cosmos-sdk icon indicating copy to clipboard operation
cosmos-sdk copied to clipboard

feat: Add a cli cmd to prune old states according to current settings

Open adu-crypto opened this issue 3 years ago • 7 comments

Description

Closes: #12727

  • a command to read pruning options and prune the history states

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.

I have...

  • [ ] included the correct type prefix in the PR title
  • [ ] added ! to the type prefix if API or client breaking change
  • [ ] targeted the correct branch (see PR Targeting)
  • [ ] provided a link to the relevant issue or specification
  • [ ] followed the guidelines for building modules
  • [ ] included the necessary unit and integration tests
  • [ ] added a changelog entry to CHANGELOG.md
  • [ ] included comments for documenting Go code
  • [ ] updated the relevant documentation or specification
  • [ ] reviewed "Files changed" and left comments if necessary
  • [ ] confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.

I have...

  • [ ] confirmed the correct type prefix in the PR title
  • [ ] confirmed ! in the type prefix if API or client breaking change
  • [ ] confirmed all author checklist items have been addressed
  • [ ] reviewed state machine logic
  • [ ] reviewed API design and naming
  • [ ] reviewed documentation is accurate
  • [ ] reviewed tests and test coverage
  • [ ] manually tested (if applicable)

adu-crypto avatar Jul 27 '22 09:07 adu-crypto

Could you add a changelog entry. This is now pruning SDK, do you think its worth having something for tendermint as well.

@marbar3778 changelog entry added. I can investigate the tendermint pruning part and update the pr if necessary.

adu-crypto avatar Aug 01 '22 08:08 adu-crypto

I can investigate the tendermint pruning part and update the pr if necessary.

Here is how it would be done. https://github.com/binaryholdings/cosmprund/blob/master/cmd/pruner.go#L578. But I think there is a cleaner way to do it. https://github.com/binaryholdings/cosmprund/pull/4 Here I copy the data in tendermint into a new db then replace the old db with it. The problem with these commands is they take a very long time to do because compaction is needed to reclaim the space on disk otherwise you are placing delete markers but not actually removing from disk

tac0turtle avatar Aug 01 '22 11:08 tac0turtle

@marbar3778 thanks for your advice but it seems pruning tendermint db is not an urgent need for me. maybe we can come back to complete the pruning cmd for tendermint db in the future.

adu-crypto avatar Aug 02 '22 02:08 adu-crypto

utACK. is there a reason we cant backport this to 0.46 and 0.45

I think it's alright to be ported to 0.46 and 0.45 without breaking change. actually I'm already doing this to test on a cronos testing db

adu-crypto avatar Aug 04 '22 08:08 adu-crypto

Codecov Report

Merging #12742 (d875f88) into main (d638ca3) will increase coverage by 0.00%. The diff coverage is 77.77%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #12742   +/-   ##
=======================================
  Coverage   53.15%   53.15%           
=======================================
  Files         641      641           
  Lines       54871    54877    +6     
=======================================
+ Hits        29166    29172    +6     
  Misses      23382    23382           
  Partials     2323     2323           
Impacted Files Coverage Δ
store/rootmulti/store.go 73.35% <76.47%> (+0.19%) :arrow_up:
simapp/simd/cmd/root.go 70.51% <100.00%> (+0.11%) :arrow_up:

codecov[bot] avatar Aug 04 '22 08:08 codecov[bot]

Is this ready for review again?

amaury1093 avatar Aug 10 '22 14:08 amaury1093

Is this ready for review again?

yes, it's ready for another round of review.

adu-crypto avatar Aug 11 '22 01:08 adu-crypto

  • pruning-interval: N means to delete old states from disk every Nth block.

@yihuang @alexanderbez I was thinking that the current pruning-interval allows at most 1/2 of the old states to be pruned(except prune everything). Could we change its semantics to keep old states every Nth block so we can have more aggressive pruning options, say prune 9/10 of the states and we can delete versions in range, which is more effective?

adu-crypto avatar Aug 23 '22 02:08 adu-crypto

  • pruning-interval: N means to delete old states from disk every Nth block.

@yihuang @alexanderbez I was thinking that the current pruning-interval allows at most 1/2 of the old states to be pruned(except prune everything). Could we change its semantics to keep old states every Nth block so we can have more aggressive pruning options, say prune 9/10 of the states and we can delete versions in range, which is more effective?

I think you can try to propose a new flag in a separate issue.

yihuang avatar Aug 23 '22 03:08 yihuang

@yihuang can you re-review this please?

alexanderbez avatar Aug 23 '22 14:08 alexanderbez

Shall we backport?

yihuang avatar Aug 30 '22 09:08 yihuang

test-rosetta failed, maybe not related to this PR.

yihuang avatar Aug 30 '22 09:08 yihuang

I have backported this to my forked release/v0.46.x and tested this command on a devnet cronos node, the result seems alright:

(base) adudu@CNMAC0342 cronos % bin/cronosd prune --home 'data/cronos_777-1/node0/' --app-db-backend 'goleveldb' --pruning 'custom' --pruning-keep-recent 10 --pruning-interval 10
get pruning options from command flags, strategy: 3, keep-recent: 10
the latest version: 89
pruning heights start from 1, end at 78
successfully pruned the application root multi stores

adu-crypto avatar Aug 31 '22 11:08 adu-crypto

I have backported this to my forked release/v0.46.x and tested this command on a devnet cronos node, the result seems alright:

(base) adudu@CNMAC0342 cronos % bin/cronosd prune --home 'data/cronos_777-1/node0/' --app-db-backend 'goleveldb' --pruning 'custom' --pruning-keep-recent 10 --pruning-interval 10
get pruning options from command flags, strategy: 3, keep-recent: 10
the latest version: 89
pruning heights start from 1, end at 78
successfully pruned the application root multi stores

want to backport to 45 and 46, we can merge those quickly

tac0turtle avatar Sep 01 '22 08:09 tac0turtle