Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into alexey/pruner-part-tr…
Browse files Browse the repository at this point in the history
…ait-impls
  • Loading branch information
shekhirin committed Oct 11, 2023
2 parents 0552157 + 65cc314 commit d7fa9a5
Show file tree
Hide file tree
Showing 50 changed files with 815 additions and 186 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
!Cross.toml
!deny.toml
!Makefile
!/.git # include for vergen constants

# include for vergen constants
!/.git

# include dist directory, where the reth binary is located after compilation
!/dist
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ reth-rpc-types-compat = { path = "./crates/rpc/rpc-types-compat" }
reth-discv4 = { path = "./crates/net/discv4" }
reth-eth-wire = { path = "./crates/net/eth-wire" }
reth-ecies = { path = "./crates/net/ecies" }
reth-tracing = {path = "./crates/tracing"}

# revm
revm = "3.5.0"
Expand Down
4 changes: 2 additions & 2 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ reth-rpc-builder = { path = "../../crates/rpc/rpc-builder" }
reth-rpc = { path = "../../crates/rpc/rpc" }
reth-rpc-types = { path = "../../crates/rpc/rpc-types" }
reth-rpc-types-compat = { path = "../../crates/rpc/rpc-types-compat" }
reth-rpc-api = { path = "../../crates/rpc/rpc-api" }
reth-rpc-api = { path = "../../crates/rpc/rpc-api", features = ["client"] }
reth-network = { path = "../../crates/net/network", features = ["serde"] }
reth-network-api.workspace = true
reth-downloaders = { path = "../../crates/net/downloaders", features = ["test-utils"] }
reth-tracing = { path = "../../crates/tracing" }
reth-tracing.workspace = true
reth-tasks.workspace = true
reth-net-nat = { path = "../../crates/net/nat" }
reth-payload-builder.workspace = true
Expand Down
20 changes: 14 additions & 6 deletions bin/reth/src/args/rpc_server_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::{
args::GasPriceOracleArgs,
cli::{
components::{RethNodeComponents, RethRpcComponents},
components::{RethNodeComponents, RethRpcComponents, RethRpcServerHandles},
config::RethRpcConfig,
ext::RethNodeCommandConfig,
},
Expand Down Expand Up @@ -184,7 +184,7 @@ impl RpcServerArgs {
engine_api: Engine,
jwt_secret: JwtSecret,
conf: &mut Conf,
) -> eyre::Result<(RpcServerHandle, AuthServerHandle)>
) -> eyre::Result<RethRpcServerHandles>
where
Reth: RethNodeComponents,
Engine: EngineApiServer,
Expand All @@ -202,12 +202,13 @@ impl RpcServerArgs {
.with_events(components.events())
.with_executor(components.task_executor())
.build_with_auth_server(module_config, engine_api);
let node_modules = RethRpcComponents { registry: &mut registry, modules: &mut modules };

let rpc_components = RethRpcComponents { registry: &mut registry, modules: &mut modules };
// apply configured customization
conf.extend_rpc_modules(self, components, node_modules)?;
conf.extend_rpc_modules(self, components, rpc_components)?;

let server_config = self.rpc_server_config();
let launch_rpc = modules.start_server(server_config).map_ok(|handle| {
let launch_rpc = modules.clone().start_server(server_config).map_ok(|handle| {
if let Some(url) = handle.ipc_endpoint() {
info!(target: "reth::cli", url=%url, "RPC IPC server started");
}
Expand All @@ -227,7 +228,14 @@ impl RpcServerArgs {
});

// launch servers concurrently
Ok(futures::future::try_join(launch_rpc, launch_auth).await?)
let (rpc, auth) = futures::future::try_join(launch_rpc, launch_auth).await?;
let handles = RethRpcServerHandles { rpc, auth };

// call hook
let rpc_components = RethRpcComponents { registry: &mut registry, modules: &mut modules };
conf.on_rpc_server_started(self, components, rpc_components, handles.clone())?;

Ok(handles)
}

/// Convenience function for starting a rpc server with configs which extracted from cli args.
Expand Down
26 changes: 25 additions & 1 deletion bin/reth/src/cli/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use reth_provider::{
AccountReader, BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider, ChangeSetReader,
EvmEnvProvider, StateProviderFactory,
};
use reth_rpc_builder::{RethModuleRegistry, TransportRpcModules};
use reth_rpc_builder::{
auth::AuthServerHandle, RethModuleRegistry, RpcServerHandle, TransportRpcModules,
};
use reth_tasks::TaskSpawner;
use reth_transaction_pool::TransactionPool;
use std::sync::Arc;
Expand Down Expand Up @@ -143,3 +145,25 @@ where
self.events.clone()
}
}

/// Contains the handles to the spawned RPC servers.
///
/// This can be used to access the endpoints of the servers.
///
/// # Example
///
/// ```rust
/// use reth::cli::components::RethRpcServerHandles;
/// use reth::rpc::api::EthApiClient;
/// # async fn t(handles: RethRpcServerHandles) {
/// let client = handles.rpc.http_client().expect("http server not started");
/// let block_number = client.block_number().await.unwrap();
/// # }
/// ```
#[derive(Debug, Clone)]
pub struct RethRpcServerHandles {
/// The regular RPC server handle.
pub rpc: RpcServerHandle,
/// The handle to the auth server (engine API)
pub auth: AuthServerHandle,
}
39 changes: 39 additions & 0 deletions bin/reth/src/cli/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
use reth_tasks::TaskSpawner;
use std::{fmt, marker::PhantomData};

use crate::cli::components::RethRpcServerHandles;

/// A trait that allows for extending parts of the CLI with additional functionality.
///
/// This is intended as a way to allow to _extend_ the node command. For example, to register
Expand Down Expand Up @@ -46,6 +48,25 @@ pub trait RethNodeCommandConfig: fmt::Debug {
Ok(())
}

/// Event hook called once the rpc servers has been started.
fn on_rpc_server_started<Conf, Reth>(
&mut self,
config: &Conf,
components: &Reth,
rpc_components: RethRpcComponents<'_, Reth>,
handles: RethRpcServerHandles,
) -> eyre::Result<()>
where
Conf: RethRpcConfig,
Reth: RethNodeComponents,
{
let _ = config;
let _ = components;
let _ = rpc_components;
let _ = handles;
Ok(())
}

/// Allows for registering additional RPC modules for the transports.
///
/// This is expected to call the merge functions of [reth_rpc_builder::TransportRpcModules], for
Expand Down Expand Up @@ -190,6 +211,24 @@ impl<T: RethNodeCommandConfig> RethNodeCommandConfig for NoArgs<T> {
}
}

fn on_rpc_server_started<Conf, Reth>(
&mut self,
config: &Conf,
components: &Reth,
rpc_components: RethRpcComponents<'_, Reth>,
handles: RethRpcServerHandles,
) -> eyre::Result<()>
where
Conf: RethRpcConfig,
Reth: RethNodeComponents,
{
if let Some(conf) = self.inner_mut() {
conf.on_rpc_server_started(config, components, rpc_components, handles)
} else {
Ok(())
}
}

fn extend_rpc_modules<Conf, Reth>(
&mut self,
config: &Conf,
Expand Down
3 changes: 1 addition & 2 deletions bin/reth/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
Factory::new(self.chain.clone()),
Arc::clone(&self.chain),
);
let _tree_config = BlockchainTreeConfig::default();
let tree = BlockchainTree::new(
tree_externals,
BlockchainTreeConfig::default(),
Expand Down Expand Up @@ -533,7 +532,7 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
self.adjust_instance_ports();

// Start RPC servers
let (_rpc_server, _auth_server) =
let _rpc_server_handles =
self.rpc.start_servers(&components, engine_api, jwt_secret, &mut self.ext).await?;

// Run consensus engine to completion
Expand Down
2 changes: 1 addition & 1 deletion book/installation/build-for-arm-devices.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Building for ARM devices

Reth can be build for and run on ARM devices, but there are a few things to take into considerations before.
Reth can be built for and run on ARM devices, but there are a few things to take into considerations before.

## CPU Architecture

Expand Down
2 changes: 1 addition & 1 deletion book/run/private-testnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ b454497fbec8 el-1-reth-lighthouse engine-rpc: 8551/tcp -
Great! You now have a private network with 2 full Ethereum nodes on your local machine over Docker - one that is a Reth/Lighthouse pair and another that is Reth/Teku. Check out the [Kurtosis docs](https://docs.kurtosis.com/cli) to learn about the various ways you can interact with and inspect your network.

## Using Kurtosis on Kubernetes
Kurtosis packages are portable and reproducible, meaning they will work the same way over Docker or Kubernetes, locally or on remote infrsatructure. For use cases that require a larger scale, Kurtosis can be deployed on Kubernetes by following these docs [here](https://docs.kurtosis.com/k8s/).
Kurtosis packages are portable and reproducible, meaning they will work the same way over Docker or Kubernetes, locally or on remote infrastructure. For use cases that require a larger scale, Kurtosis can be deployed on Kubernetes by following these docs [here](https://docs.kurtosis.com/k8s/).

## Running the network with additional services
The [`ethereum-package`](https://github.com/kurtosis-tech/ethereum-package) comes with many optional flags and arguments you can enable for your private network. Some include:
Expand Down
15 changes: 6 additions & 9 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ use tracing::{debug, error, info, instrument, trace, warn};
/// and commit it to db. If we don't have the block, pipeline syncing should start to fetch the
/// blocks from p2p. Do reorg in tables if canonical chain if needed.
#[derive(Debug)]
pub struct BlockchainTree<DB: Database, C: Consensus, EF: ExecutorFactory> {
pub struct BlockchainTree<DB: Database, EF: ExecutorFactory> {
/// The tracked chains and their current data.
chains: HashMap<BlockChainId, AppendableChain>,
/// Unconnected block buffer.
Expand All @@ -84,7 +84,7 @@ pub struct BlockchainTree<DB: Database, C: Consensus, EF: ExecutorFactory> {
/// Indices to block and their connection to the canonical chain.
block_indices: BlockIndices,
/// External components (the database, consensus engine etc.)
externals: TreeExternals<DB, C, EF>,
externals: TreeExternals<DB, EF>,
/// Tree configuration
config: BlockchainTreeConfig,
/// Broadcast channel for canon state changes notifications.
Expand All @@ -96,10 +96,10 @@ pub struct BlockchainTree<DB: Database, C: Consensus, EF: ExecutorFactory> {
prune_modes: Option<PruneModes>,
}

impl<DB: Database, C: Consensus, EF: ExecutorFactory> BlockchainTree<DB, C, EF> {
impl<DB: Database, EF: ExecutorFactory> BlockchainTree<DB, EF> {
/// Create a new blockchain tree.
pub fn new(
externals: TreeExternals<DB, C, EF>,
externals: TreeExternals<DB, EF>,
config: BlockchainTreeConfig,
prune_modes: Option<PruneModes>,
) -> RethResult<Self> {
Expand Down Expand Up @@ -1196,7 +1196,7 @@ mod tests {

fn setup_externals(
exec_res: Vec<BundleStateWithReceipts>,
) -> TreeExternals<Arc<DatabaseEnv>, Arc<TestConsensus>, TestExecutorFactory> {
) -> TreeExternals<Arc<DatabaseEnv>, TestExecutorFactory> {
let db = create_test_rw_db();
let consensus = Arc::new(TestConsensus::default());
let chain_spec = Arc::new(
Expand Down Expand Up @@ -1281,10 +1281,7 @@ mod tests {
self
}

fn assert<DB: Database, C: Consensus, EF: ExecutorFactory>(
self,
tree: &BlockchainTree<DB, C, EF>,
) {
fn assert<DB: Database, EF: ExecutorFactory>(self, tree: &BlockchainTree<DB, EF>) {
if let Some(chain_num) = self.chain_num {
assert_eq!(tree.chains.len(), chain_num);
}
Expand Down
Loading

0 comments on commit d7fa9a5

Please sign in to comment.