feat: CanonStateNotification for commit and reorg (#2156)

This commit is contained in:
rakita
2023-04-10 13:11:15 +02:00
committed by GitHub
parent cbbd834575
commit 087d0a6317
40 changed files with 801 additions and 617 deletions

View File

@@ -3,10 +3,11 @@
use crate::dirs::{JwtSecretPath, PlatformPath};
use clap::Args;
use jsonrpsee::server::ServerHandle;
use reth_interfaces::events::ChainEventSubscriptions;
use reth_network_api::{NetworkInfo, Peers};
use reth_primitives::ChainSpec;
use reth_provider::{BlockProvider, EvmEnvProvider, HeaderProvider, StateProviderFactory};
use reth_provider::{
BlockProvider, CanonStateSubscriptions, EvmEnvProvider, HeaderProvider, StateProviderFactory,
};
use reth_rpc::{JwtError, JwtSecret};
use reth_rpc_builder::{
constants, error::RpcError, IpcServerBuilder, RethRpcModule, RpcModuleSelection,
@@ -134,7 +135,7 @@ impl RpcServerArgs {
Pool: TransactionPool + Clone + 'static,
Network: NetworkInfo + Peers + Clone + 'static,
Tasks: TaskSpawner + Clone + 'static,
Events: ChainEventSubscriptions + Clone + 'static,
Events: CanonStateSubscriptions + Clone + 'static,
{
reth_rpc_builder::launch(
client,

View File

@@ -30,7 +30,6 @@ use reth_executor::blockchain_tree::{
};
use reth_interfaces::{
consensus::{Consensus, ForkchoiceState},
events::NewBlockNotificationSink,
p2p::{
bodies::{client::BodiesClient, downloader::BodyDownloader},
headers::{client::StatusUpdater, downloader::HeaderDownloader},
@@ -231,11 +230,11 @@ impl Command {
let tree_config = BlockchainTreeConfig::default();
// The size of the broadcast is twice the maximum reorg depth, because at maximum reorg
// depth at least N blocks must be sent at once.
let new_block_notification_sender =
NewBlockNotificationSink::new(tree_config.max_reorg_depth() as usize * 2);
let (canon_state_notification_sender, _receiver) =
tokio::sync::broadcast::channel(tree_config.max_reorg_depth() as usize * 2);
let blockchain_tree = ShareableBlockchainTree::new(BlockchainTree::new(
tree_externals,
new_block_notification_sender.clone(),
canon_state_notification_sender.clone(),
tree_config,
)?);
@@ -246,7 +245,7 @@ impl Command {
shareable_db.clone(),
transaction_pool.clone(),
consensus_engine_tx.clone(),
new_block_notification_sender.clone(),
canon_state_notification_sender,
)
.build();