File tree Expand file tree Collapse file tree 7 files changed +32
-0
lines changed Expand file tree Collapse file tree 7 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ reth-trie-common.workspace = true
2626alloy-primitives.workspace = true
2727alloy-consensus.workspace = true
2828alloy-rpc-types-engine.workspace = true
29+ alloy-eips.workspace = true
2930
3031# async
3132tokio = { workspace = true , features = [" sync" ] }
@@ -46,6 +47,7 @@ std = [
4647 " alloy-primitives/std" ,
4748 " alloy-consensus/std" ,
4849 " alloy-rpc-types-engine/std" ,
50+ " alloy-eips/std" ,
4951 " futures/std" ,
5052 " serde/std" ,
5153 " thiserror/std" ,
Original file line number Diff line number Diff line change 33use crate :: ForkchoiceStatus ;
44use alloc:: boxed:: Box ;
55use alloy_consensus:: BlockHeader ;
6+ use alloy_eips:: BlockNumHash ;
67use alloy_primitives:: B256 ;
78use alloy_rpc_types_engine:: ForkchoiceState ;
89use core:: {
@@ -20,6 +21,8 @@ pub enum BeaconConsensusEngineEvent<N: NodePrimitives = EthPrimitives> {
2021 ForkchoiceUpdated ( ForkchoiceState , ForkchoiceStatus ) ,
2122 /// A block was added to the fork chain.
2223 ForkBlockAdded ( ExecutedBlockWithTrieUpdates < N > , Duration ) ,
24+ /// A new block was received from the consensus engine
25+ BlockReceived ( BlockNumHash ) ,
2326 /// A block was added to the canonical chain, and the elapsed time validating the block
2427 CanonicalBlockAdded ( ExecutedBlockWithTrieUpdates < N > , Duration ) ,
2528 /// A canonical chain was committed, and the elapsed time committing the data
6972 Self :: LiveSyncProgress ( progress) => {
7073 write ! ( f, "LiveSyncProgress({progress:?})" )
7174 }
75+ Self :: BlockReceived ( num_hash) => {
76+ write ! ( f, "BlockReceived({num_hash:?})" )
77+ }
7278 }
7379 }
7480}
Original file line number Diff line number Diff line change @@ -571,6 +571,10 @@ where
571571 }
572572 } ;
573573
574+ let num_hash = block. num_hash ( ) ;
575+ let engine_event = BeaconConsensusEngineEvent :: BlockReceived ( num_hash) ;
576+ self . emit_event ( EngineApiEvent :: BeaconConsensus ( engine_event) ) ;
577+
574578 let block_hash = block. hash ( ) ;
575579 let mut lowest_buffered_ancestor = self . lowest_buffered_ancestor_or ( block_hash) ;
576580 if lowest_buffered_ancestor == block_hash {
Original file line number Diff line number Diff line change @@ -349,6 +349,18 @@ impl TestHarness {
349349 }
350350 }
351351
352+ async fn check_block_received ( & mut self , hash : B256 ) {
353+ let event = self . from_tree_rx . recv ( ) . await . unwrap ( ) ;
354+ match event {
355+ EngineApiEvent :: BeaconConsensus ( BeaconConsensusEngineEvent :: BlockReceived (
356+ num_hash,
357+ ) ) => {
358+ assert_eq ! ( num_hash. hash, hash) ;
359+ }
360+ _ => panic ! ( "Unexpected event: {event:#?}" ) ,
361+ }
362+ }
363+
352364 fn persist_blocks ( & self , blocks : Vec < RecoveredBlock < reth_ethereum_primitives:: Block > > ) {
353365 let mut block_data: Vec < ( B256 , Block ) > = Vec :: with_capacity ( blocks. len ( ) ) ;
354366 let mut headers_data: Vec < ( B256 , Header ) > = Vec :: with_capacity ( blocks. len ( ) ) ;
@@ -1137,6 +1149,9 @@ async fn test_engine_tree_buffered_blocks_are_eventually_connected() {
11371149 assert ! ( test_harness. tree. state. buffer. block( & buffered_block_hash) . is_none( ) ) ;
11381150
11391151 // both blocks are added to the canon chain in order
1152+ // note that the buffered block is received first, but added last
1153+ test_harness. check_block_received ( buffered_block_hash) . await ;
1154+ test_harness. check_block_received ( non_buffered_block_hash) . await ;
11401155 test_harness. check_canon_block_added ( non_buffered_block_hash) . await ;
11411156 test_harness. check_canon_block_added ( buffered_block_hash) . await ;
11421157}
Original file line number Diff line number Diff line change @@ -280,6 +280,9 @@ impl NodeState {
280280 BeaconConsensusEngineEvent :: InvalidBlock ( block) => {
281281 warn ! ( number=block. number( ) , hash=?block. hash( ) , "Encountered invalid block" ) ;
282282 }
283+ BeaconConsensusEngineEvent :: BlockReceived ( num_hash) => {
284+ info ! ( number=num_hash. number, hash=?num_hash. hash, "Received block from consensus engine" ) ;
285+ }
283286 }
284287 }
285288
Original file line number Diff line number Diff line change @@ -123,6 +123,7 @@ pub async fn maintain_pending_state<P>(
123123 }
124124 // ignore
125125 BeaconConsensusEngineEvent :: CanonicalChainCommitted ( _, _) |
126+ BeaconConsensusEngineEvent :: BlockReceived ( _) |
126127 BeaconConsensusEngineEvent :: LiveSyncProgress ( _) => ( ) ,
127128 }
128129 }
You can’t perform that action at this time.
0 commit comments