feat: Integrate Sealedblock to BeaconConsensusEngineEvent (#2764)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
chirag-bgh
2023-05-22 15:14:50 +05:30
committed by GitHub
parent 43aeadb9ba
commit 7849b4c38e
3 changed files with 13 additions and 16 deletions

View File

@ -81,11 +81,11 @@ impl NodeState {
BeaconConsensusEngineEvent::ForkchoiceUpdated(state) => { BeaconConsensusEngineEvent::ForkchoiceUpdated(state) => {
info!(target: "reth::cli", ?state, "Forkchoice updated"); info!(target: "reth::cli", ?state, "Forkchoice updated");
} }
BeaconConsensusEngineEvent::CanonicalBlockAdded(number, hash) => { BeaconConsensusEngineEvent::CanonicalBlockAdded(block) => {
info!(target: "reth::cli", number, ?hash, "Block added to canonical chain"); info!(target: "reth::cli", number=block.number, hash=?block.hash, "Block added to canonical chain");
} }
BeaconConsensusEngineEvent::ForkBlockAdded(number, hash) => { BeaconConsensusEngineEvent::ForkBlockAdded(block) => {
info!(target: "reth::cli", number, ?hash, "Block added to fork chain"); info!(target: "reth::cli", number=block.number, hash=?block.hash, "Block added to fork chain");
} }
} }
} }

View File

@ -1,5 +1,6 @@
use reth_interfaces::consensus::ForkchoiceState; use reth_interfaces::consensus::ForkchoiceState;
use reth_primitives::{BlockHash, BlockNumber}; use reth_primitives::SealedBlock;
use std::sync::Arc;
/// Events emitted by [crate::BeaconConsensusEngine]. /// Events emitted by [crate::BeaconConsensusEngine].
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -7,7 +8,7 @@ pub enum BeaconConsensusEngineEvent {
/// The fork choice state was updated. /// The fork choice state was updated.
ForkchoiceUpdated(ForkchoiceState), ForkchoiceUpdated(ForkchoiceState),
/// A block was added to the canonical chain. /// A block was added to the canonical chain.
CanonicalBlockAdded(BlockNumber, BlockHash), CanonicalBlockAdded(Arc<SealedBlock>),
/// A block was added to the fork chain. /// A block was added to the fork chain.
ForkBlockAdded(BlockNumber, BlockHash), ForkBlockAdded(Arc<SealedBlock>),
} }

View File

@ -29,6 +29,7 @@ use reth_tasks::TaskSpawner;
use schnellru::{ByLength, LruMap}; use schnellru::{ByLength, LruMap};
use std::{ use std::{
pin::Pin, pin::Pin,
sync::Arc,
task::{Context, Poll}, task::{Context, Poll},
}; };
use tokio::sync::{ use tokio::sync::{
@ -708,22 +709,17 @@ where
debug_assert!(self.sync.is_pipeline_idle(), "pipeline must be idle"); debug_assert!(self.sync.is_pipeline_idle(), "pipeline must be idle");
let block_hash = block.hash; let block_hash = block.hash;
let block_number = block.number; let status = self.blockchain.insert_block_without_senders(block.clone())?;
let status = self.blockchain.insert_block_without_senders(block)?;
let mut latest_valid_hash = None; let mut latest_valid_hash = None;
let block = Arc::new(block);
let status = match status { let status = match status {
BlockStatus::Valid => { BlockStatus::Valid => {
latest_valid_hash = Some(block_hash); latest_valid_hash = Some(block_hash);
self.listeners.notify(BeaconConsensusEngineEvent::CanonicalBlockAdded( self.listeners.notify(BeaconConsensusEngineEvent::CanonicalBlockAdded(block));
block_number,
block_hash,
));
PayloadStatusEnum::Valid PayloadStatusEnum::Valid
} }
BlockStatus::Accepted => { BlockStatus::Accepted => {
self.listeners self.listeners.notify(BeaconConsensusEngineEvent::ForkBlockAdded(block));
.notify(BeaconConsensusEngineEvent::ForkBlockAdded(block_number, block_hash));
PayloadStatusEnum::Accepted PayloadStatusEnum::Accepted
} }
BlockStatus::Disconnected => PayloadStatusEnum::Syncing, BlockStatus::Disconnected => PayloadStatusEnum::Syncing,