fix: handle tree event on new payload (#14475)

This commit is contained in:
Matthias Seitz
2025-02-13 18:52:27 +01:00
committed by GitHub
parent 431df62a4a
commit 95b14f851b

View File

@ -950,11 +950,14 @@ where
}; };
let mut outcome = TreeOutcome::new(status); let mut outcome = TreeOutcome::new(status);
// if the block is valid and it is the current sync target head, make it canonical
if outcome.outcome.is_valid() && self.is_sync_target_head(block_hash) { if outcome.outcome.is_valid() && self.is_sync_target_head(block_hash) {
// if the block is valid and it is the sync target head, make it canonical // but only if it isn't already the canonical head
outcome = outcome.with_event(TreeEvent::TreeAction(TreeAction::MakeCanonical { if self.state.tree_state.canonical_block_hash() != block_hash {
sync_target_head: block_hash, outcome = outcome.with_event(TreeEvent::TreeAction(TreeAction::MakeCanonical {
})); sync_target_head: block_hash,
}));
}
} }
Ok(outcome) Ok(outcome)
@ -1436,7 +1439,12 @@ where
} }
} }
BeaconEngineMessage::NewPayload { payload, tx } => { BeaconEngineMessage::NewPayload { payload, tx } => {
let output = self.on_new_payload(payload); let mut output = self.on_new_payload(payload);
let maybe_event =
output.as_mut().ok().and_then(|out| out.event.take());
// emit response
if let Err(err) = if let Err(err) =
tx.send(output.map(|o| o.outcome).map_err(|e| { tx.send(output.map(|o| o.outcome).map_err(|e| {
BeaconOnNewPayloadError::Internal(Box::new(e)) BeaconOnNewPayloadError::Internal(Box::new(e))
@ -1448,6 +1456,9 @@ where
.failed_new_payload_response_deliveries .failed_new_payload_response_deliveries
.increment(1); .increment(1);
} }
// handle the event if any
self.on_maybe_tree_event(maybe_event)?;
} }
BeaconEngineMessage::TransitionConfigurationExchanged => { BeaconEngineMessage::TransitionConfigurationExchanged => {
// triggering this hook will record that we received a request from // triggering this hook will record that we received a request from
@ -1592,6 +1603,8 @@ where
} }
/// Handles a tree event. /// Handles a tree event.
///
/// Returns an error if a [`TreeAction::MakeCanonical`] results in a fatal error.
fn on_tree_event(&mut self, event: TreeEvent) -> ProviderResult<()> { fn on_tree_event(&mut self, event: TreeEvent) -> ProviderResult<()> {
match event { match event {
TreeEvent::TreeAction(action) => match action { TreeEvent::TreeAction(action) => match action {