feat(config): missing stage configs (#3215)

This commit is contained in:
Alexey Shekhirin
2023-06-19 09:51:12 +01:00
committed by GitHub
parent 37e8f7b140
commit f44010b888
6 changed files with 123 additions and 12 deletions

View File

@ -77,6 +77,10 @@ use crate::{
use reth_interfaces::p2p::headers::client::HeadersClient;
use reth_payload_builder::PayloadBuilderService;
use reth_provider::providers::BlockchainProvider;
use reth_stages::stages::{
AccountHashingStage, IndexAccountHistoryStage, IndexStorageHistoryStage, MerkleStage,
StorageHashingStage, TransactionLookupStage,
};
pub mod cl_events;
pub mod events;
@ -628,7 +632,7 @@ impl Command {
H: HeaderDownloader + 'static,
B: BodyDownloader + 'static,
{
let stage_conf = &config.stages;
let stage_config = &config.stages;
let mut builder = Pipeline::builder();
@ -670,17 +674,33 @@ impl Command {
)
.set(
TotalDifficultyStage::new(consensus)
.with_commit_threshold(stage_conf.total_difficulty.commit_threshold),
.with_commit_threshold(stage_config.total_difficulty.commit_threshold),
)
.set(SenderRecoveryStage {
commit_threshold: stage_conf.sender_recovery.commit_threshold,
commit_threshold: stage_config.sender_recovery.commit_threshold,
})
.set(ExecutionStage::new(
factory,
ExecutionStageThresholds {
max_blocks: stage_conf.execution.max_blocks,
max_changes: stage_conf.execution.max_changes,
max_blocks: stage_config.execution.max_blocks,
max_changes: stage_config.execution.max_changes,
},
))
.set(AccountHashingStage::new(
stage_config.account_hashing.clean_threshold,
stage_config.account_hashing.commit_threshold,
))
.set(StorageHashingStage::new(
stage_config.storage_hashing.clean_threshold,
stage_config.storage_hashing.commit_threshold,
))
.set(MerkleStage::new_execution(stage_config.merkle.clean_threshold))
.set(TransactionLookupStage::new(stage_config.transaction_lookup.commit_threshold))
.set(IndexAccountHistoryStage::new(
stage_config.index_account_history.commit_threshold,
))
.set(IndexStorageHistoryStage::new(
stage_config.index_storage_history.commit_threshold,
)),
)
.build(db, self.chain.clone());

View File

@ -51,14 +51,26 @@ impl Config {
pub struct StageConfig {
/// Header stage configuration.
pub headers: HeadersConfig,
/// Total difficulty stage configuration
/// Total Difficulty stage configuration
pub total_difficulty: TotalDifficultyConfig,
/// Body stage configuration.
pub bodies: BodiesConfig,
/// Sender recovery stage configuration.
/// Sender Recovery stage configuration.
pub sender_recovery: SenderRecoveryConfig,
/// Execution stage configuration.
pub execution: ExecutionConfig,
/// Account Hashing stage configuration.
pub account_hashing: HashingConfig,
/// Storage Hashing stage configuration.
pub storage_hashing: HashingConfig,
/// Merkle stage configuration.
pub merkle: MerkleConfig,
/// Transaction Lookup stage configuration.
pub transaction_lookup: TransactionLookupConfig,
/// Index Account History stage configuration.
pub index_account_history: IndexHistoryConfig,
/// Index Storage History stage configuration.
pub index_storage_history: IndexHistoryConfig,
}
/// Header stage configuration.
@ -204,6 +216,66 @@ impl Default for ExecutionConfig {
}
}
/// Hashing stage configuration.
#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Serialize)]
#[serde(default)]
pub struct HashingConfig {
/// The threshold (in number of blocks) for switching between
/// incremental hashing and full hashing.
pub clean_threshold: u64,
/// The maximum number of entities to process before committing progress to the database.
pub commit_threshold: u64,
}
impl Default for HashingConfig {
fn default() -> Self {
Self { clean_threshold: 500_000, commit_threshold: 100_000 }
}
}
/// Merkle stage configuration.
#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Serialize)]
#[serde(default)]
pub struct MerkleConfig {
/// The threshold (in number of blocks) for switching from incremental trie building of changes
/// to whole rebuild.
pub clean_threshold: u64,
}
impl Default for MerkleConfig {
fn default() -> Self {
Self { clean_threshold: 50_000 }
}
}
/// Transaction Lookup stage configuration.
#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Serialize)]
#[serde(default)]
pub struct TransactionLookupConfig {
/// The maximum number of transactions to process before committing progress to the database.
pub commit_threshold: u64,
}
impl Default for TransactionLookupConfig {
fn default() -> Self {
Self { commit_threshold: 5_000_000 }
}
}
/// History History stage configuration.
#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Serialize)]
#[serde(default)]
pub struct IndexHistoryConfig {
/// The maximum number of blocks to process before committing progress to the database.
pub commit_threshold: u64,
}
impl Default for IndexHistoryConfig {
fn default() -> Self {
Self { commit_threshold: 100_000 }
}
}
#[cfg(test)]
mod tests {
use super::Config;

View File

@ -29,7 +29,7 @@ use tracing::*;
/// This is preparation before generating intermediate hashes and calculating Merkle tree root.
#[derive(Clone, Debug)]
pub struct AccountHashingStage {
/// The threshold (in number of state transitions) for switching between incremental
/// The threshold (in number of blocks) for switching between incremental
/// hashing and full storage hashing.
pub clean_threshold: u64,
/// The maximum number of accounts to process before committing.

View File

@ -14,6 +14,13 @@ pub struct IndexAccountHistoryStage {
pub commit_threshold: u64,
}
impl IndexAccountHistoryStage {
/// Create new instance of [IndexAccountHistoryStage].
pub fn new(commit_threshold: u64) -> Self {
Self { commit_threshold }
}
}
impl Default for IndexAccountHistoryStage {
fn default() -> Self {
Self { commit_threshold: 100_000 }

View File

@ -14,6 +14,13 @@ pub struct IndexStorageHistoryStage {
pub commit_threshold: u64,
}
impl IndexStorageHistoryStage {
/// Create new instance of [IndexStorageHistoryStage].
pub fn new(commit_threshold: u64) -> Self {
Self { commit_threshold }
}
}
impl Default for IndexStorageHistoryStage {
fn default() -> Self {
Self { commit_threshold: 100_000 }

View File

@ -44,8 +44,8 @@ use tracing::*;
pub enum MerkleStage {
/// The execution portion of the merkle stage.
Execution {
/// The threshold for switching from incremental trie building
/// of changes to whole rebuild. Num of transitions.
/// The threshold (in number of blocks) for switching from incremental trie building
/// of changes to whole rebuild.
clean_threshold: u64,
},
/// The unwind portion of the merkle stage.
@ -58,16 +58,21 @@ pub enum MerkleStage {
}
impl MerkleStage {
/// Stage default for the Execution variant.
/// Stage default for the [MerkleStage::Execution].
pub fn default_execution() -> Self {
Self::Execution { clean_threshold: 50_000 }
}
/// Stage default for the Unwind variant.
/// Stage default for the [MerkleStage::Unwind].
pub fn default_unwind() -> Self {
Self::Unwind
}
/// Create new instance of [MerkleStage::Execution].
pub fn new_execution(clean_threshold: u64) -> Self {
Self::Execution { clean_threshold }
}
/// Check that the computed state root matches the root in the expected header.
fn validate_state_root(
&self,