From 7849b4c38ef229abbeb1e8521dc71e8a9ef64fc7 Mon Sep 17 00:00:00 2001 From: chirag-bgh <76247491+chirag-bgh@users.noreply.github.com> Date: Mon, 22 May 2023 15:14:50 +0530 Subject: [PATCH] feat: Integrate Sealedblock to BeaconConsensusEngineEvent (#2764) Co-authored-by: Matthias Seitz --- bin/reth/src/node/events.rs | 8 ++++---- crates/consensus/beacon/src/engine/event.rs | 7 ++++--- crates/consensus/beacon/src/engine/mod.rs | 14 +++++--------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/bin/reth/src/node/events.rs b/bin/reth/src/node/events.rs index 543531312a..5008eb8ddc 100644 --- a/bin/reth/src/node/events.rs +++ b/bin/reth/src/node/events.rs @@ -81,11 +81,11 @@ impl NodeState { BeaconConsensusEngineEvent::ForkchoiceUpdated(state) => { info!(target: "reth::cli", ?state, "Forkchoice updated"); } - BeaconConsensusEngineEvent::CanonicalBlockAdded(number, hash) => { - info!(target: "reth::cli", number, ?hash, "Block added to canonical chain"); + BeaconConsensusEngineEvent::CanonicalBlockAdded(block) => { + info!(target: "reth::cli", number=block.number, hash=?block.hash, "Block added to canonical chain"); } - BeaconConsensusEngineEvent::ForkBlockAdded(number, hash) => { - info!(target: "reth::cli", number, ?hash, "Block added to fork chain"); + BeaconConsensusEngineEvent::ForkBlockAdded(block) => { + info!(target: "reth::cli", number=block.number, hash=?block.hash, "Block added to fork chain"); } } } diff --git a/crates/consensus/beacon/src/engine/event.rs b/crates/consensus/beacon/src/engine/event.rs index 9959d102b0..bdec564eb9 100644 --- a/crates/consensus/beacon/src/engine/event.rs +++ b/crates/consensus/beacon/src/engine/event.rs @@ -1,5 +1,6 @@ use reth_interfaces::consensus::ForkchoiceState; -use reth_primitives::{BlockHash, BlockNumber}; +use reth_primitives::SealedBlock; +use std::sync::Arc; /// Events emitted by [crate::BeaconConsensusEngine]. #[derive(Clone, Debug)] @@ -7,7 +8,7 @@ pub enum BeaconConsensusEngineEvent { /// The fork choice state was updated. ForkchoiceUpdated(ForkchoiceState), /// A block was added to the canonical chain. - CanonicalBlockAdded(BlockNumber, BlockHash), + CanonicalBlockAdded(Arc), /// A block was added to the fork chain. - ForkBlockAdded(BlockNumber, BlockHash), + ForkBlockAdded(Arc), } diff --git a/crates/consensus/beacon/src/engine/mod.rs b/crates/consensus/beacon/src/engine/mod.rs index 0457dc4973..38717fa3dc 100644 --- a/crates/consensus/beacon/src/engine/mod.rs +++ b/crates/consensus/beacon/src/engine/mod.rs @@ -29,6 +29,7 @@ use reth_tasks::TaskSpawner; use schnellru::{ByLength, LruMap}; use std::{ pin::Pin, + sync::Arc, task::{Context, Poll}, }; use tokio::sync::{ @@ -708,22 +709,17 @@ where debug_assert!(self.sync.is_pipeline_idle(), "pipeline must be idle"); let block_hash = block.hash; - let block_number = block.number; - let status = self.blockchain.insert_block_without_senders(block)?; + let status = self.blockchain.insert_block_without_senders(block.clone())?; let mut latest_valid_hash = None; + let block = Arc::new(block); let status = match status { BlockStatus::Valid => { latest_valid_hash = Some(block_hash); - self.listeners.notify(BeaconConsensusEngineEvent::CanonicalBlockAdded( - block_number, - block_hash, - )); - + self.listeners.notify(BeaconConsensusEngineEvent::CanonicalBlockAdded(block)); PayloadStatusEnum::Valid } BlockStatus::Accepted => { - self.listeners - .notify(BeaconConsensusEngineEvent::ForkBlockAdded(block_number, block_hash)); + self.listeners.notify(BeaconConsensusEngineEvent::ForkBlockAdded(block)); PayloadStatusEnum::Accepted } BlockStatus::Disconnected => PayloadStatusEnum::Syncing,