-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add chain data pruning experimental feature #4686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 36 commits
fce33c1
be8f081
af59579
16de0e9
3e67042
0d433a3
0e545c5
4e0e627
9313b02
3e3596b
d0807ff
4c1d792
95e86a5
a63542a
580942a
328005b
c34154f
64ba456
a42a933
322b327
cd37f0f
ac79611
51c6c6d
96c2934
cbc460b
99b273f
cc4648e
8315393
5992b66
5d4da4e
118178e
91102a7
962adb6
1368c55
d41661b
2a439f1
d29a286
e2c088c
25d514d
571a022
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /* | ||
| * Copyright Hyperledger Besu Contributors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations under the License. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| */ | ||
| package org.hyperledger.besu.cli.options.unstable; | ||
|
|
||
| import org.hyperledger.besu.cli.options.CLIOptions; | ||
| import org.hyperledger.besu.ethereum.chain.ChainPrunerConfiguration; | ||
| import org.hyperledger.besu.util.number.PositiveNumber; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import picocli.CommandLine; | ||
|
|
||
| public class ChainDataPruningOptions implements CLIOptions<ChainPrunerConfiguration> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename to ChainPruningOPtions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
| private static final String CHAIN_PRUNING_ENABLED_FLAG = "--Xchain-pruning-enabled"; | ||
| private static final String CHAIN_PRUNING_BLOCKS_RETAINED_FLAG = | ||
| "--Xchain-pruning-blocks-retained"; | ||
| private static final String CHAIN_PRUNING_FREQUENCY_FLAG = "--Xchain-pruning-frequency"; | ||
| public static final long DEFAULT_CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED = 7200; | ||
| public static final int DEFAULT_CHAIN_DATA_PRUNING_FREQUENCY = 256; | ||
|
|
||
| @CommandLine.Option( | ||
| hidden = true, | ||
| names = {CHAIN_PRUNING_ENABLED_FLAG}, | ||
| description = | ||
| "Enable the chain pruner to actively prune old chain data (default: ${DEFAULT-VALUE})") | ||
| private final Boolean chainDataPruningEnabled = Boolean.FALSE; | ||
|
|
||
| @CommandLine.Option( | ||
| hidden = true, | ||
| names = {CHAIN_PRUNING_BLOCKS_RETAINED_FLAG}, | ||
| description = | ||
| "The number of recent blocks for which to keep the chain data. Must be >= " | ||
| + DEFAULT_CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED | ||
| + " (default: ${DEFAULT-VALUE})") | ||
| private final Long chainDataPruningBlocksRetained = | ||
| DEFAULT_CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED; | ||
|
|
||
| @CommandLine.Option( | ||
| hidden = true, | ||
| names = {CHAIN_PRUNING_FREQUENCY_FLAG}, | ||
| description = | ||
| "The number of blocks added to the chain between two pruning operations. Must be non-negative (default: ${DEFAULT-VALUE})") | ||
| private final PositiveNumber chainDataPruningBlocksFrequency = | ||
| PositiveNumber.fromInt(DEFAULT_CHAIN_DATA_PRUNING_FREQUENCY); | ||
|
|
||
| public static ChainDataPruningOptions create() { | ||
| return new ChainDataPruningOptions(); | ||
| } | ||
|
|
||
| public Boolean getChainDataPruningEnabled() { | ||
| return chainDataPruningEnabled; | ||
| } | ||
|
|
||
| public Long getChainDataPruningBlocksRetained() { | ||
| return chainDataPruningBlocksRetained; | ||
| } | ||
|
|
||
| @Override | ||
| public ChainPrunerConfiguration toDomainObject() { | ||
| return new ChainPrunerConfiguration( | ||
| chainDataPruningEnabled, | ||
| chainDataPruningBlocksRetained, | ||
| chainDataPruningBlocksFrequency.getValue()); | ||
| } | ||
|
|
||
| @Override | ||
| public List<String> getCLIOptions() { | ||
| return Arrays.asList( | ||
| CHAIN_PRUNING_ENABLED_FLAG, | ||
| chainDataPruningEnabled.toString(), | ||
| CHAIN_PRUNING_BLOCKS_RETAINED_FLAG, | ||
| chainDataPruningBlocksRetained.toString(), | ||
| CHAIN_PRUNING_FREQUENCY_FLAG, | ||
| chainDataPruningBlocksFrequency.toString()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,9 @@ | |
| import org.hyperledger.besu.ethereum.bonsai.CachedMerkleTrieLoader; | ||
| import org.hyperledger.besu.ethereum.chain.Blockchain; | ||
| import org.hyperledger.besu.ethereum.chain.BlockchainStorage; | ||
| import org.hyperledger.besu.ethereum.chain.ChainDataPruner; | ||
| import org.hyperledger.besu.ethereum.chain.ChainDataPrunerStorage; | ||
| import org.hyperledger.besu.ethereum.chain.ChainPrunerConfiguration; | ||
| import org.hyperledger.besu.ethereum.chain.DefaultBlockchain; | ||
| import org.hyperledger.besu.ethereum.chain.GenesisState; | ||
| import org.hyperledger.besu.ethereum.chain.MutableBlockchain; | ||
|
|
@@ -51,6 +54,7 @@ | |
| import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; | ||
| import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; | ||
| import org.hyperledger.besu.ethereum.eth.manager.MergePeerFilter; | ||
| import org.hyperledger.besu.ethereum.eth.manager.MonitoredExecutors; | ||
| import org.hyperledger.besu.ethereum.eth.manager.snap.SnapProtocolManager; | ||
| import org.hyperledger.besu.ethereum.eth.peervalidation.CheckpointBlocksPeerValidator; | ||
| import org.hyperledger.besu.ethereum.eth.peervalidation.ClassicForkPeerValidator; | ||
|
|
@@ -140,6 +144,7 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides | |
| Collections.emptyList(); | ||
| protected EvmConfiguration evmConfiguration; | ||
| protected int maxPeers; | ||
| protected ChainPrunerConfiguration chainPrunerConfiguration = ChainPrunerConfiguration.DEFAULT; | ||
|
|
||
| public BesuControllerBuilder storageProvider(final StorageProvider storageProvider) { | ||
| this.storageProvider = storageProvider; | ||
|
|
@@ -268,6 +273,12 @@ public BesuControllerBuilder maxPeers(final int maxPeers) { | |
| return this; | ||
| } | ||
|
|
||
| public BesuControllerBuilder chainPruningConfiguration( | ||
| final ChainPrunerConfiguration chainPrunerConfiguration) { | ||
| this.chainPrunerConfiguration = chainPrunerConfiguration; | ||
| return this; | ||
| } | ||
|
|
||
| public BesuController build() { | ||
| checkNotNull(genesisConfig, "Missing genesis config"); | ||
| checkNotNull(syncConfig, "Missing sync config"); | ||
|
|
@@ -315,6 +326,30 @@ public BesuController build() { | |
| blockchain, worldStateArchive, protocolSchedule, this::createConsensusContext); | ||
| validateContext(protocolContext); | ||
|
|
||
| if (chainPrunerConfiguration.getChainPruningEnabled()) { | ||
| protocolContext.getConsensusContext(MergeContext.class).setIsChainPruningEnabled(true); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are not post-merge e.g. using QBFT then the merge context will not be available. You can use the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
| final ChainDataPruner chainDataPruner = | ||
| new ChainDataPruner( | ||
| blockchainStorage, | ||
| new ChainDataPrunerStorage( | ||
| storageProvider.getStorageBySegmentIdentifier( | ||
| KeyValueSegmentIdentifier.CHAIN_PRUNER_STATE)), | ||
| chainPrunerConfiguration.getChainPruningBlocksRetained(), | ||
| chainPrunerConfiguration.getChainPruningBlocksFrequency(), | ||
| MonitoredExecutors.newBoundedThreadPool( | ||
| ChainDataPruner.class.getSimpleName(), | ||
| 1, | ||
| 1, | ||
| ChainDataPruner.MAX_PRUNING_THREAD_QUEUE_SIZE, | ||
| metricsSystem)); | ||
| blockchain.observeBlockAdded(chainDataPruner); | ||
| LOG.info( | ||
| "Chain data pruning enabled with recent blocks retained to be: " | ||
| + chainPrunerConfiguration.getChainPruningBlocksRetained() | ||
| + " and frequency to be: " | ||
| + chainPrunerConfiguration.getChainPruningBlocksFrequency()); | ||
|
jframe marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| protocolSchedule.setPublicWorldStateArchiveForPrivacyBlockProcessor( | ||
| protocolContext.getWorldStateArchive()); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,7 @@ dependencies { | |
| implementation 'org.apache.tuweni:tuweni-rlp' | ||
| implementation 'org.hyperledger.besu:bls12-381' | ||
| implementation 'org.immutables:value-annotations' | ||
| implementation 'org.awaitility:awaitility' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should only for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, that's true, updated. |
||
|
|
||
| implementation 'io.prometheus:simpleclient_guava' | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove data from description based previous naming conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated