Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

db: Add delayed blocks pruning #12497

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6cfc4e9
client/db: Prune state/blocks with delay
lexnv Oct 14, 2022
69cb590
tests: Delay prune blocks on finalization
lexnv Oct 14, 2022
d18d071
tests: Delay prune blocks with fork
lexnv Oct 14, 2022
a5fb1cc
client/cli: Add delayed pruning mode and make it default
lexnv Oct 14, 2022
4f2f54e
client/db: Announce proper leaves for delayed pruning
lexnv Oct 14, 2022
490c0c9
tests: Verify `displaced_leaves_after_finalizing` with delayed pruning
lexnv Oct 14, 2022
17a1bb9
client/db: Rename delayed_pruning to delay_canonicalization
lexnv Oct 18, 2022
835abe9
client/cli: Fix rustdoc
lexnv Oct 18, 2022
80a78dc
client/db: Handle canonization gap
lexnv Oct 28, 2022
52b0430
Revert "client/cli: Fix rustdoc"
lexnv Oct 28, 2022
2fb4030
Revert "client/cli: Add delayed pruning mode and make it default"
lexnv Oct 28, 2022
ec24de5
client/cli: Add `delayed_canonicalization` flag
lexnv Nov 3, 2022
5bfc4fa
client/service: Fix tests
lexnv Nov 3, 2022
fdee4cc
client/db: Move `delayed` param on the database settings
lexnv Nov 3, 2022
026181b
client/db: Add debug log for pruning and fix canon gap
lexnv Nov 3, 2022
f34dad5
client/db: Apply cargo fmt
lexnv Nov 3, 2022
2c28ac1
client/cli: Improve documentation
lexnv Nov 3, 2022
9f68abd
client/db: Simplify canonicalization on startup
lexnv Nov 3, 2022
c4ae9ec
Merge remote-tracking branch 'origin/master' into lexnv/delayed_pruning
lexnv Nov 3, 2022
5f1c535
client/db: Adjust testing for origin/master
lexnv Nov 3, 2022
118e943
client/db: Remove cloning for block numbers
lexnv Nov 3, 2022
8fabc52
client/db: Use `delayed_canonicalization` naming
lexnv Nov 7, 2022
15cb39d
client/db: Obtain last canonicalized and finalized from meta
lexnv Nov 7, 2022
2014094
client/state-db: Remove private `LAST_CANONICAL` constant
lexnv Nov 7, 2022
fac193f
Merge remote-tracking branch 'origin/master' into lexnv/delayed_pruning
lexnv Nov 7, 2022
6c9baa0
Merge remote-tracking branch 'origin/master' into lexnv/delayed_pruning
lexnv Nov 8, 2022
5603f52
client/db: Adjust testing to origin/master
lexnv Nov 8, 2022
4b6a06e
Merge remote-tracking branch 'origin/master' into lexnv/delayed_pruning
lexnv Nov 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/node/cli/benches/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
trie_cache_maximum_size: Some(64 * 1024 * 1024),
state_pruning: Some(PruningMode::ArchiveAll),
blocks_pruning: BlocksPruning::KeepAll,
delayed_canonicalization: Some(32),
chain_spec: spec,
wasm_method: WasmExecutionMethod::Compiled {
instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
Expand Down
1 change: 1 addition & 0 deletions bin/node/cli/benches/transaction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
trie_cache_maximum_size: Some(64 * 1024 * 1024),
state_pruning: Some(PruningMode::ArchiveAll),
blocks_pruning: BlocksPruning::KeepAll,
delayed_canonicalization: Some(32),
chain_spec: spec,
wasm_method: WasmExecutionMethod::Interpreted,
// NOTE: we enforce the use of the native runtime to make the errors more debuggable
Expand Down
1 change: 1 addition & 0 deletions bin/node/testing/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ impl BenchDb {
state_pruning: Some(PruningMode::ArchiveAll),
source: database_type.into_settings(dir.into()),
blocks_pruning: sc_client_db::BlocksPruning::KeepAll,
delayed_canonicalization: None,
};
let task_executor = TaskExecutor::new();

Expand Down
1 change: 1 addition & 0 deletions client/cli/src/commands/chain_info_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl ChainInfoCmd {
state_pruning: config.state_pruning.clone(),
source: config.database.clone(),
blocks_pruning: config.blocks_pruning,
delayed_canonicalization: config.delayed_canonicalization,
};
let backend = sc_service::new_db_backend::<B>(db_config)?;
let info: ChainInfo<B> = backend.blockchain().info().into();
Expand Down
16 changes: 16 additions & 0 deletions client/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ pub(crate) const NODE_NAME_MAX_LENGTH: usize = 64;
/// Default sub directory to store network config.
pub(crate) const DEFAULT_NETWORK_CONFIG_PATH: &str = "network";

/// The blocks that were supposed to get pruned at the finalization N
/// will get pruned at N + 32.
pub(crate) const DELAYED_CANONICALIZATION: u32 = 32;

/// The recommended open file descriptor limit to be configured for the process.
const RECOMMENDED_OPEN_FILE_DESCRIPTOR_LIMIT: u64 = 10_000;

Expand Down Expand Up @@ -248,6 +252,17 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
.unwrap_or_else(|| Ok(Default::default()))
}

/// Get the delayed canonicalization mode.
///
/// By default this is retrieved from `delayed_canonicalization` if it is available.
/// Otherwise the mode is active.
fn delayed_canonicalization(&self) -> Result<Option<u32>> {
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
Ok(self
.pruning_params()
.map(|x| x.delayed_canonicalization())
.unwrap_or(Some(DELAYED_CANONICALIZATION)))
}

/// Get the block pruning mode.
///
/// By default this is retrieved from `block_pruning` if it is available. Otherwise its
Expand Down Expand Up @@ -530,6 +545,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
trie_cache_maximum_size: self.trie_cache_maximum_size()?,
state_pruning: self.state_pruning()?,
blocks_pruning: self.blocks_pruning()?,
delayed_canonicalization: self.delayed_canonicalization()?,
wasm_method: self.wasm_method()?,
wasm_runtime_overrides: self.wasm_runtime_overrides(),
execution_strategies: self.execution_strategies(is_dev, is_validator)?,
Expand Down
19 changes: 18 additions & 1 deletion client/cli/src/params/pruning_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::error;
use crate::{config::DELAYED_CANONICALIZATION, error};
use clap::Args;
use sc_service::{BlocksPruning, PruningMode};

Expand All @@ -40,6 +40,14 @@ pub struct PruningParams {
/// NOTE: only finalized blocks are subject for removal!
#[arg(alias = "keep-blocks", long, value_name = "COUNT")]
pub blocks_pruning: Option<String>,
/// Specify the delayed canonicalization of blocks.
///
/// The blocks that were supposed to get pruned at the finalization N
/// will get pruned after a number of finalizations.
///
/// This option is enabled by default.
#[clap(alias = "delayed-pruning", long)]
pub delayed_canonicalization: Option<bool>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: You could consider making this just bool, use ArgAction::SetFalse and rename to something like --disable-delayed-pruning. We get rid of the Option and since it is enabled by default, using --delayed-pruning true is of limited purpose anyway.

}

impl PruningParams {
Expand Down Expand Up @@ -76,4 +84,13 @@ impl PruningParams {
None => Ok(BlocksPruning::KeepFinalized),
}
}

/// Get the block delayed canonicalization value from the parameters.
pub fn delayed_canonicalization(&self) -> Option<u32> {
if self.delayed_canonicalization.unwrap_or(true) {
Some(DELAYED_CANONICALIZATION)
} else {
None
}
}
}
1 change: 1 addition & 0 deletions client/db/benches/state_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ fn create_backend(config: BenchmarkConfig, temp_dir: &TempDir) -> Backend<Block>
state_pruning: Some(PruningMode::ArchiveAll),
source: DatabaseSource::ParityDb { path },
blocks_pruning: BlocksPruning::KeepAll,
delayed_canonicalization: None,
};

Backend::new(settings, 100).expect("Creates backend")
Expand Down
Loading