Skip to content

Commit

Permalink
chore(rpc): reusable eth api EthCall (#8683)
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane authored Jun 11, 2024
1 parent bc24e8e commit f89077b
Show file tree
Hide file tree
Showing 114 changed files with 3,023 additions and 2,649 deletions.
36 changes: 18 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
[workspace.package]
version = "0.2.0-beta.9"
edition = "2021"
rust-version = "1.76"
license = "MIT OR Apache-2.0"
homepage = "https://paradigmxyz.github.io/reth"
repository = "https://github.com/paradigmxyz/reth"
exclude = [".github/"]

[workspace]
members = [
"bin/reth/",
Expand Down Expand Up @@ -39,7 +48,7 @@ members = [
"crates/net/network-api/",
"crates/net/network/",
"crates/net/p2p/",
"crates/net/types/",
"crates/net/peers/",
"crates/node-core/",
"crates/node/api/",
"crates/node/builder/",
Expand Down Expand Up @@ -194,15 +203,6 @@ redundant_pub_crate = "allow"
significant_drop_in_scrutinee = "allow"
significant_drop_tightening = "allow"

[workspace.package]
version = "0.2.0-beta.9"
edition = "2021"
rust-version = "1.76"
license = "MIT OR Apache-2.0"
homepage = "https://paradigmxyz.github.io/reth"
repository = "https://github.com/paradigmxyz/reth"
exclude = [".github/"]

# Speed up tests.
[profile.dev.package]
proptest.opt-level = 3
Expand Down Expand Up @@ -282,7 +282,7 @@ reth-net-common = { path = "crates/net/common" }
reth-net-nat = { path = "crates/net/nat" }
reth-network = { path = "crates/net/network" }
reth-network-api = { path = "crates/net/network-api" }
reth-network-types = { path = "crates/net/types" }
reth-network-peers = { path = "crates/net/peers" }
reth-network-p2p = { path = "crates/net/p2p" }
reth-nippy-jar = { path = "crates/storage/nippy-jar" }
reth-node-api = { path = "crates/node/api" }
Expand Down
71 changes: 67 additions & 4 deletions bin/reth/src/commands/common.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
//! Contains common `reth` arguments
use clap::Parser;
use reth_beacon_consensus::EthBeaconConsensus;
use reth_config::{config::EtlConfig, Config};
use reth_db::{init_db, open_db_read_only, DatabaseEnv};
use reth_db_common::init::init_genesis;
use reth_downloaders::{bodies::noop::NoopBodiesDownloader, headers::noop::NoopHeaderDownloader};
use reth_evm::noop::NoopBlockExecutorProvider;
use reth_node_core::{
args::{
utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
DatabaseArgs, DatadirArgs,
},
dirs::{ChainPath, DataDirPath},
};
use reth_primitives::ChainSpec;
use reth_provider::{providers::StaticFileProvider, ProviderFactory};
use reth_primitives::{stage::PipelineTarget, ChainSpec};
use reth_provider::{
providers::StaticFileProvider, HeaderSyncMode, ProviderFactory, StaticFileProviderFactory,
};
use reth_stages::{sets::DefaultStages, Pipeline};
use reth_static_file::StaticFileProducer;
use std::{path::PathBuf, sync::Arc};
use tracing::{debug, info};
use tracing::{debug, info, warn};

/// Struct to hold config and datadir paths
#[derive(Debug, Parser)]
Expand Down Expand Up @@ -77,14 +84,70 @@ impl EnvironmentArgs {
),
};

let provider_factory = ProviderFactory::new(db, self.chain.clone(), sfp);
let provider_factory = self.create_provider_factory(&config, db, sfp)?;
if access.is_read_write() {
debug!(target: "reth::cli", chain=%self.chain.chain, genesis=?self.chain.genesis_hash(), "Initializing genesis");
init_genesis(provider_factory.clone())?;
}

Ok(Environment { config, provider_factory, data_dir })
}

/// Returns a [`ProviderFactory`] after executing consistency checks.
///
/// If it's a read-write environment and an issue is found, it will attempt to heal (including a
/// pipeline unwind). Otherwise, it will print out an warning, advising the user to restart the
/// node to heal.
fn create_provider_factory(
&self,
config: &Config,
db: Arc<DatabaseEnv>,
static_file_provider: StaticFileProvider,
) -> eyre::Result<ProviderFactory<Arc<DatabaseEnv>>> {
let has_receipt_pruning = config.prune.as_ref().map_or(false, |a| a.has_receipts_pruning());
let factory = ProviderFactory::new(db, self.chain.clone(), static_file_provider);

info!(target: "reth::cli", "Verifying storage consistency.");

// Check for consistency between database and static files.
if let Some(unwind_target) = factory
.static_file_provider()
.check_consistency(&factory.provider()?, has_receipt_pruning)?
{
if factory.db_ref().is_read_only() {
warn!(target: "reth::cli", ?unwind_target, "Inconsistent storage. Restart node to heal.");
return Ok(factory)
}

let prune_modes = config.prune.clone().map(|prune| prune.segments).unwrap_or_default();

// Highly unlikely to happen, and given its destructive nature, it's better to panic
// instead.
assert_ne!(unwind_target, PipelineTarget::Unwind(0), "A static file <> database inconsistency was found that would trigger an unwind to block 0");

info!(target: "reth::cli", unwind_target = %unwind_target, "Executing an unwind after a failed storage consistency check.");

// Builds and executes an unwind-only pipeline
let mut pipeline = Pipeline::builder()
.add_stages(DefaultStages::new(
factory.clone(),
HeaderSyncMode::Continuous,
Arc::new(EthBeaconConsensus::new(self.chain.clone())),
NoopHeaderDownloader::default(),
NoopBodiesDownloader::default(),
NoopBlockExecutorProvider::default(),
config.stages.clone(),
prune_modes.clone(),
))
.build(factory.clone(), StaticFileProducer::new(factory.clone(), prune_modes));

// Move all applicable data from database to static files.
pipeline.move_to_static_files()?;
pipeline.unwind(unwind_target.unwind_target().expect("should exist"), None)?;
}

Ok(factory)
}
}

/// Environment built from [`EnvironmentArgs`].
Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/auto-seal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ reth-evm.workspace = true
reth-engine-primitives.workspace = true
reth-consensus.workspace = true
reth-rpc-types.workspace = true
reth-network-types.workspace = true
reth-network-peers.workspace = true
reth-tokio-util.workspace = true

# async
Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/auto-seal/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use reth_network_p2p::{
headers::client::{HeadersClient, HeadersFut, HeadersRequest},
priority::Priority,
};
use reth_network_types::{PeerId, WithPeerId};
use reth_network_peers::{PeerId, WithPeerId};
use reth_primitives::{BlockBody, BlockHashOrNumber, Header, HeadersDirection, B256};
use std::fmt::Debug;
use tracing::{trace, warn};
Expand Down
12 changes: 6 additions & 6 deletions crates/evm/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use reth_storage_errors::provider::ProviderResult;
use revm::primitives::{BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, SpecId};

/// A provider type that knows chain specific information required to configure a
/// [CfgEnvWithHandlerCfg].
/// [`CfgEnvWithHandlerCfg`].
///
/// This type is mainly used to provide required data to configure the EVM environment that is
/// usually stored on disk.
#[auto_impl::auto_impl(&, Arc)]
pub trait EvmEnvProvider: Send + Sync {
/// Fills the [CfgEnvWithHandlerCfg] and [BlockEnv] fields with values specific to the given
/// Fills the [`CfgEnvWithHandlerCfg`] and [BlockEnv] fields with values specific to the given
/// [BlockHashOrNumber].
fn fill_env_at<EvmConfig>(
&self,
Expand All @@ -24,7 +24,7 @@ pub trait EvmEnvProvider: Send + Sync {
where
EvmConfig: ConfigureEvmEnv;

/// Fills the default [CfgEnvWithHandlerCfg] and [BlockEnv] fields with values specific to the
/// Fills the default [`CfgEnvWithHandlerCfg`] and [BlockEnv] fields with values specific to the
/// given [Header].
fn env_with_header<EvmConfig>(
&self,
Expand All @@ -40,7 +40,7 @@ pub trait EvmEnvProvider: Send + Sync {
Ok((cfg, block_env))
}

/// Fills the [CfgEnvWithHandlerCfg] and [BlockEnv] fields with values specific to the given
/// Fills the [`CfgEnvWithHandlerCfg`] and [BlockEnv] fields with values specific to the given
/// [Header].
fn fill_env_with_header<EvmConfig>(
&self,
Expand All @@ -66,7 +66,7 @@ pub trait EvmEnvProvider: Send + Sync {
header: &Header,
) -> ProviderResult<()>;

/// Fills the [CfgEnvWithHandlerCfg] fields with values specific to the given
/// Fills the [`CfgEnvWithHandlerCfg`] fields with values specific to the given
/// [BlockHashOrNumber].
fn fill_cfg_env_at<EvmConfig>(
&self,
Expand All @@ -77,7 +77,7 @@ pub trait EvmEnvProvider: Send + Sync {
where
EvmConfig: ConfigureEvmEnv;

/// Fills the [CfgEnvWithHandlerCfg] fields with values specific to the given [Header].
/// Fills the [`CfgEnvWithHandlerCfg`] fields with values specific to the given [Header].
fn fill_cfg_env_with_header<EvmConfig>(
&self,
cfg: &mut CfgEnvWithHandlerCfg,
Expand Down
1 change: 0 additions & 1 deletion crates/net/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ workspace = true
alloy-primitives.workspace = true

# async
pin-project.workspace = true
tokio = { workspace = true, features = ["full"] }
Loading

0 comments on commit f89077b

Please sign in to comment.