feat: BlockchainTree (#1212)

Co-authored-by: Dragan Rakita <draganrakita@192.168.1.4>
This commit is contained in:
rakita
2023-03-14 19:17:14 +01:00
committed by GitHub
parent 06db495d96
commit 237fd5ce6e
54 changed files with 3409 additions and 367 deletions

View File

@ -7,7 +7,7 @@ use reth_net_nat::NatResolver;
use reth_network::NetworkConfigBuilder;
use reth_primitives::{ChainSpec, NodeRecord};
use reth_staged_sync::Config;
use std::path::PathBuf;
use std::{path::PathBuf, sync::Arc};
/// Parameters for configuring the network more granularity via CLI
#[derive(Debug, Args)]
@ -50,7 +50,11 @@ pub struct NetworkArgs {
impl NetworkArgs {
/// Build a [`NetworkConfigBuilder`] from a [`Config`] and a [`ChainSpec`], in addition to the
/// values in this option struct.
pub fn network_config(&self, config: &Config, chain_spec: ChainSpec) -> NetworkConfigBuilder {
pub fn network_config(
&self,
config: &Config,
chain_spec: Arc<ChainSpec>,
) -> NetworkConfigBuilder {
let peers_file = (!self.no_persist_peers).then_some(&self.peers_file);
let network_config_builder = config
.network_config(self.nat, peers_file.map(|f| f.as_ref().to_path_buf()))

View File

@ -63,7 +63,7 @@ pub struct ImportCommand {
default_value = "mainnet",
value_parser = genesis_value_parser
)]
chain: ChainSpec,
chain: Arc<ChainSpec>,
/// The path to a block file for import.
///
@ -140,7 +140,7 @@ impl ImportCommand {
.build(file_client.clone(), consensus.clone(), db)
.into_task();
let factory = reth_executor::Factory::new(Arc::new(self.chain.clone()));
let factory = reth_executor::Factory::new(self.chain.clone());
let mut pipeline = Pipeline::builder()
.with_sync_state_updater(file_client)

View File

@ -36,7 +36,7 @@ pub struct InitCommand {
default_value = "mainnet",
value_parser = genesis_value_parser
)]
chain: ChainSpec,
chain: Arc<ChainSpec>,
}
impl InitCommand {

View File

@ -207,8 +207,8 @@ impl<'a, DB: Database> DbTool<'a, DB> {
let chain = random_block_range(0..len, Default::default(), 0..64);
self.db.update(|tx| {
chain.iter().try_for_each(|block| {
insert_canonical_block(tx, block, true)?;
chain.into_iter().try_for_each(|block| {
insert_canonical_block(tx, block, None, true)?;
Ok::<_, eyre::Error>(())
})
})??;

View File

@ -90,7 +90,7 @@ pub struct Command {
default_value = "mainnet",
value_parser = genesis_value_parser
)]
chain: ChainSpec,
chain: Arc<ChainSpec>,
/// Enable Prometheus metrics.
///
@ -443,7 +443,7 @@ impl Command {
builder = builder.with_max_block(max_block)
}
let factory = reth_executor::Factory::new(Arc::new(self.chain.clone()));
let factory = reth_executor::Factory::new(self.chain.clone());
let pipeline = builder
.with_sync_state_updater(updater.clone())
.add_stages(

View File

@ -39,7 +39,7 @@ pub struct Command {
default_value = "mainnet",
value_parser = chain_spec_value_parser
)]
chain: ChainSpec,
chain: Arc<ChainSpec>,
/// Disable the discovery service.
#[command(flatten)]

View File

@ -54,7 +54,7 @@ pub struct Command {
default_value = "mainnet",
value_parser = chain_spec_value_parser
)]
chain: ChainSpec,
chain: Arc<ChainSpec>,
/// Enable Prometheus metrics.
///
@ -171,7 +171,7 @@ impl Command {
stage.execute(&mut tx, input).await?;
}
StageEnum::Execution => {
let factory = reth_executor::Factory::new(Arc::new(self.chain.clone()));
let factory = reth_executor::Factory::new(self.chain.clone());
let mut stage = ExecutionStage::new(factory, 10_000);
stage.commit_threshold = num_blocks;
if !self.skip_unwind {

View File

@ -140,13 +140,13 @@ pub async fn run_test(path: PathBuf) -> eyre::Result<TestOutcome> {
// insert genesis
let header: SealedHeader = suite.genesis_block_header.into();
let genesis_block = SealedBlock { header, body: vec![], ommers: vec![], withdrawals: None };
reth_provider::insert_canonical_block(&tx, &genesis_block, has_block_reward)?;
reth_provider::insert_canonical_block(&tx, genesis_block, None, has_block_reward)?;
let mut last_block = None;
suite.blocks.iter().try_for_each(|block| -> eyre::Result<()> {
let decoded = SealedBlock::decode(&mut block.rlp.as_ref())?;
reth_provider::insert_canonical_block(&tx, &decoded, has_block_reward)?;
last_block = Some(decoded.number);
reth_provider::insert_canonical_block(&tx, decoded, None, has_block_reward)?;
Ok(())
})?;