diff --git a/crates/consensus/beacon/src/engine/mod.rs b/crates/consensus/beacon/src/engine/mod.rs index e8b27dc57..f3aa249fa 100644 --- a/crates/consensus/beacon/src/engine/mod.rs +++ b/crates/consensus/beacon/src/engine/mod.rs @@ -506,7 +506,7 @@ where } else { let previous_action = self .blockchain_tree_action - .replace(BlockchainTreeAction::FcuMakeCanonical { state, attrs, tx }); + .replace(BlockchainTreeAction::MakeForkchoiceHeadCanonical { state, attrs, tx }); debug_assert!(previous_action.is_none(), "Pre-existing action found"); } } @@ -1624,7 +1624,7 @@ where action: BlockchainTreeAction, ) -> RethResult { match action { - BlockchainTreeAction::FcuMakeCanonical { state, attrs, tx } => { + BlockchainTreeAction::MakeForkchoiceHeadCanonical { state, attrs, tx } => { let start = Instant::now(); let result = self.blockchain.make_canonical(state.head_block_hash); let elapsed = self.record_make_canonical_latency(start, &result); @@ -1697,30 +1697,15 @@ where // if we're currently syncing and the inserted block is the targeted // FCU head block, we can try to make it canonical. if block_hash == target.head_block_hash { - if let Err((_hash, error)) = - self.try_make_sync_target_canonical(block_num_hash) - { - if error.is_fatal() { - let response = Err(BeaconOnNewPayloadError::Internal( - Box::new(error.clone()), - )); - let _ = tx.send(response); - return Err(RethError::Canonical(error)) - } - - // If we could not make the sync target block canonical, - // we should return the error as an invalid payload status. - let status = Ok(PayloadStatus::new( - PayloadStatusEnum::Invalid { - validation_error: error.to_string(), - }, - // TODO: return a proper latest valid hash - // See: - self.forkchoice_state_tracker.last_valid_head(), - )); - let _ = tx.send(status); - return Ok(EngineEventOutcome::Processed) - } + let previous_action = self.blockchain_tree_action.replace( + BlockchainTreeAction::MakeNewPayloadCanonical { + payload_num_hash: block_num_hash, + status, + tx, + }, + ); + debug_assert!(previous_action.is_none(), "Pre-existing action found"); + return Ok(EngineEventOutcome::Processed) } } // block was successfully inserted, so we can cancel the full block @@ -1728,6 +1713,31 @@ where self.sync.cancel_full_block_request(block_hash); } + trace!(target: "consensus::engine", ?status, "Returning payload status"); + let _ = tx.send(Ok(status)); + } + BlockchainTreeAction::MakeNewPayloadCanonical { payload_num_hash, status, tx } => { + let status = match self.try_make_sync_target_canonical(payload_num_hash) { + Ok(()) => status, + Err((_hash, error)) => { + if error.is_fatal() { + let response = + Err(BeaconOnNewPayloadError::Internal(Box::new(error.clone()))); + let _ = tx.send(response); + return Err(RethError::Canonical(error)) + } + + // If we could not make the sync target block canonical, + // we should return the error as an invalid payload status. + PayloadStatus::new( + PayloadStatusEnum::Invalid { validation_error: error.to_string() }, + // TODO: return a proper latest valid hash + // See: + self.forkchoice_state_tracker.last_valid_head(), + ) + } + }; + trace!(target: "consensus::engine", ?status, "Returning payload status"); let _ = tx.send(Ok(status)); } @@ -1859,7 +1869,7 @@ where } enum BlockchainTreeAction { - FcuMakeCanonical { + MakeForkchoiceHeadCanonical { state: ForkchoiceState, attrs: Option, tx: oneshot::Sender>, @@ -1868,6 +1878,11 @@ enum BlockchainTreeAction { block: SealedBlock, tx: oneshot::Sender>, }, + MakeNewPayloadCanonical { + payload_num_hash: BlockNumHash, + status: PayloadStatus, + tx: oneshot::Sender>, + }, } /// Represents outcomes of processing an engine event