Add chain data pruning experimental feature#4686
Conversation
04f5c3b to
fff4909
Compare
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
1fd4fa6 to
0d433a3
Compare
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
Signed-off-by: Zhenyang Shi <wcgcyx@gmail.com>
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
Signed-off-by: Zhenyang Shi <wcgcyx@gmail.com>
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
| // TODO: post-merge cleanup, this should be unnecessary after merge | ||
| if (!mergeCoordinator.latestValidAncestorDescendsFromTerminal(newHead.get())) { | ||
| if (!mergeCoordinator.latestValidAncestorDescendsFromTerminal(newHead.get()) | ||
| && !ChainDataPruner.isPruningEnabled()) { |
There was a problem hiding this comment.
Would be nicer to drive this based on the chain data pruning enabled flag rather than setting and using a static global field
There was a problem hiding this comment.
Yea, I tried that a bit but it seems like that would involve bringing besu command into the protocol context. I consider it to be a temporary solution until #4703 is merged. Then, we could just do a cleanup to get rid of this global field completely.
There was a problem hiding this comment.
We shouldn't need to bring the entire Besu command into the protocol context. At most, the chain pruning config values would need to be passed through. A compromise could be to make the ChainPruner a singleton instead.
There was a problem hiding this comment.
Actually, It seems cleaner to add a flag in merge context instead, following what @gfukushima did in #4735
There was a problem hiding this comment.
updated to have a temporary flag in protocol context instead. Global variable gets removed.
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
Signed-off-by: Zhenyang Shi <wcgcyx@gmail.com>
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
Signed-off-by: Zhenyang Shi <wcgcyx@gmail.com>
| .isChainDataPruningEnabled(unstableChainDataPruningOptions.getChainDataPruningEnabled()) | ||
| .chainDataPruningBlocksRetained( | ||
| unstableChainDataPruningOptions.getChainDataPruningBlocksRetained()) | ||
| .chainDataPruningFrequency( | ||
| unstableChainDataPruningOptions.getChainDataPruningBlocksFrequency()); |
There was a problem hiding this comment.
Can domain object be created instead so that 3 values don't need to passed through
| this.blocksToRetain = blocksToRetain; | ||
| this.pruningFrequency = pruningFrequency; | ||
| this.pruningExecutor = | ||
| new ThreadPoolExecutor( |
There was a problem hiding this comment.
Can this instead use the MonitoredExecutors.newFixedThreadPool so we have monitoring
There was a problem hiding this comment.
Updated to use monitored executors.
| this.blocksToRetain = blocksToRetain; | ||
| this.pruningFrequency = pruningFrequency; | ||
| this.pruningExecutor = | ||
| new ThreadPoolExecutor( |
There was a problem hiding this comment.
Rather the executor was passed in so that this isn't created in the constructor
| if (blockNumber < pruningMark) { | ||
| // Ignore and warn if block number < pruning mark, this normally indicates the | ||
| // blocksToRetain | ||
| // is too small. |
There was a problem hiding this comment.
nit: comment could be moved to previous line // is too small.
There was a problem hiding this comment.
Updated, I've removed unnecessary comments. This comment goes into the logging to show the user that the blocks to retain are too small (probably misconfiguration).
|
|
||
| // TODO: cleanup - isChainPruningEnabled will not be required after | ||
| // https://github.com/hyperledger/besu/pull/4703 is merged. | ||
| public void setIsChainPruningEnabled(final boolean isChainPruningEnabled) { |
There was a problem hiding this comment.
Don't think this is a good place for the chain pruning enabled flag, it is very high level. Maybe part of the Merge context would be ok, as we only need this check for the Merge RPCs.
There was a problem hiding this comment.
Updated. Ended up placing a flag in merge context since it involves very little change.
Co-authored-by: Simon Dudley <simon.l.dudley@hotmail.com> Signed-off-by: Zhenyang Shi <wcgcyx@gmail.com>
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
| + " which normally indicates the blocksToRetain is too small"); | ||
| return; | ||
| } | ||
| final KeyValueStorageTransaction tx1 = prunerStorage.startTransaction(); |
There was a problem hiding this comment.
nit: do we need tx1 and tx2, any reason the same variable can't be reused?
There was a problem hiding this comment.
If we do need two, then I think a more descriptive name would help readability
There was a problem hiding this comment.
I was trying to use one variable actually but tx must be final in the lambda expression so couldn't be reused. Is there a way to get around that?
There was a problem hiding this comment.
Gotcha, you could probably work around it with a class instead of lambda but it's not worth it for this. Renaming would be an improvement IMO but I wouldn't block the PR on it :)
88d6743 to
2a439f1
Compare
siladu
left a comment
There was a problem hiding this comment.
Approved! Just the tx1, tx2 renaming suggestion but not a blocker for me
Signed-off-by: Zhenyang Shi <wcgcyx@gmail.com>
| - Increase the speed of modexp gas execution and execution. [#4780](https://github.com/hyperledger/besu/pull/4780) | ||
| - Added experimental CLI options `--Xeth-capability-max` and `--Xeth-capability-min` to specify a range of capabilities to be supported by the Eth protocol. [#4752](https://github.com/hyperledger/besu/pull/4752) | ||
| - Set the default curve in the EVMTool, like is done in production operations [#4790](https://github.com/hyperledger/besu/pull/4790) | ||
| - Add chain data pruning feature with three experimental CLI options: `--Xchain-data-pruning-enabled`, `--Xchain-data-pruning-blocks-retained` and `--Xchain-data-pruning-frequency` [#4686](https://github.com/hyperledger/besu/pull/4686) |
There was a problem hiding this comment.
nit: remove data from description based previous naming conversation
|
|
||
| import picocli.CommandLine; | ||
|
|
||
| public class ChainDataPruningOptions implements CLIOptions<ChainPrunerConfiguration> { |
There was a problem hiding this comment.
rename to ChainPruningOPtions
| validateContext(protocolContext); | ||
|
|
||
| if (chainPrunerConfiguration.getChainPruningEnabled()) { | ||
| protocolContext.getConsensusContext(MergeContext.class).setIsChainPruningEnabled(true); |
There was a problem hiding this comment.
If we are not post-merge e.g. using QBFT then the merge context will not be available. You can use the ProtocolContext.safeConsensusContext to handle this case.
| implementation 'org.apache.tuweni:tuweni-rlp' | ||
| implementation 'org.hyperledger.besu:bls12-381' | ||
| implementation 'org.immutables:value-annotations' | ||
| implementation 'org.awaitility:awaitility' |
There was a problem hiding this comment.
This should only for testImplementation not implementation it's only needed for tests
There was a problem hiding this comment.
yep, that's true, updated.
| final KeyValueStorageTransaction pruningTransaction = prunerStorage.startTransaction(); | ||
| long currentPruningMark = storedPruningMark; | ||
| final long newPruningMark = blockNumber - blocksToRetain; | ||
| if (event.isNewCanonicalHead() |
There was a problem hiding this comment.
I think this check for pruning frequency could be done before submitting it to the executor so that less work is done in case nothing needs to happen.
There was a problem hiding this comment.
I need to think about this one.
| this.chainPruningBlocksRetained = chainPruningBlocksRetained; | ||
| this.chainPruningBlocksFrequency = chainPruningBlocksFrequency; | ||
| } | ||
|
|
There was a problem hiding this comment.
nit: chainPruning prefix could removed from the getters and fields are this is all on the ChainPrunerConfiguration class
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
* Add chain pruner * Increase minimum blocks to retain * Skip ancestor check in pruning mode * Separate class for pruning storage * Move pruning to separate thread * Limit total pruning threads Signed-off-by: wcgcyx <wcgcyx@gmail.com> Signed-off-by: Zhenyang Shi <wcgcyx@gmail.com> Co-authored-by: Simon Dudley <simon.l.dudley@hotmail.com> Co-authored-by: Jason Frame <jason.frame@consensys.net> Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
* Add chain pruner * Increase minimum blocks to retain * Skip ancestor check in pruning mode * Separate class for pruning storage * Move pruning to separate thread * Limit total pruning threads Signed-off-by: wcgcyx <wcgcyx@gmail.com> Signed-off-by: Zhenyang Shi <wcgcyx@gmail.com> Co-authored-by: Simon Dudley <simon.l.dudley@hotmail.com> Co-authored-by: Jason Frame <jason.frame@consensys.net> Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
* Add chain pruner * Increase minimum blocks to retain * Skip ancestor check in pruning mode * Separate class for pruning storage * Move pruning to separate thread * Limit total pruning threads Signed-off-by: wcgcyx <wcgcyx@gmail.com> Signed-off-by: Zhenyang Shi <wcgcyx@gmail.com> Co-authored-by: Simon Dudley <simon.l.dudley@hotmail.com> Co-authored-by: Jason Frame <jason.frame@consensys.net> Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
* Add chain pruner * Increase minimum blocks to retain * Skip ancestor check in pruning mode * Separate class for pruning storage * Move pruning to separate thread * Limit total pruning threads Signed-off-by: wcgcyx <wcgcyx@gmail.com> Signed-off-by: Zhenyang Shi <wcgcyx@gmail.com> Co-authored-by: Simon Dudley <simon.l.dudley@hotmail.com> Co-authored-by: Jason Frame <jason.frame@consensys.net>
PR description
This PR introduces a new feature that allows besu to prune old chain data. Three experimental CLI options are introduced as well:
--Xchain-pruning-enabledto turn on/off pruning,--Xchain-pruning-blocks-retainedto specify the number of recent blocks to retain and--Xchain-pruning-frequencyto specify how often to perform chain data pruning.Fixed Issue(s)
Linked to #4476
Documentation
doc-change-requiredlabel to this PR ifupdates are required.
Changelog