mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(engine): make new payload canonical action (#8042)
This commit is contained in:
@ -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<EngineT>,
|
||||
) -> RethResult<EngineEventOutcome> {
|
||||
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: <https://github.com/paradigmxyz/reth/issues/7146>
|
||||
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: <https://github.com/paradigmxyz/reth/issues/7146>
|
||||
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<EngineT: EngineTypes> {
|
||||
FcuMakeCanonical {
|
||||
MakeForkchoiceHeadCanonical {
|
||||
state: ForkchoiceState,
|
||||
attrs: Option<EngineT::PayloadAttributes>,
|
||||
tx: oneshot::Sender<RethResult<OnForkChoiceUpdated>>,
|
||||
@ -1868,6 +1878,11 @@ enum BlockchainTreeAction<EngineT: EngineTypes> {
|
||||
block: SealedBlock,
|
||||
tx: oneshot::Sender<Result<PayloadStatus, BeaconOnNewPayloadError>>,
|
||||
},
|
||||
MakeNewPayloadCanonical {
|
||||
payload_num_hash: BlockNumHash,
|
||||
status: PayloadStatus,
|
||||
tx: oneshot::Sender<Result<PayloadStatus, BeaconOnNewPayloadError>>,
|
||||
},
|
||||
}
|
||||
|
||||
/// Represents outcomes of processing an engine event
|
||||
|
||||
Reference in New Issue
Block a user