Skip to content

Commit a6ce95d

Browse files
committed
Add invalidation of payloads
1 parent ec487c6 commit a6ce95d

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

beacon_node/beacon_chain/src/execution_payload.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ use crate::{
1414
use execution_layer::ExecutePayloadResponseStatus;
1515
use fork_choice::PayloadVerificationStatus;
1616
use proto_array::{Block as ProtoBlock, ExecutionStatus};
17-
use slog::debug;
17+
use slog::{crit, debug, warn};
1818
use slot_clock::SlotClock;
1919
use state_processing::per_block_processing::{
2020
compute_timestamp_at_slot, is_execution_enabled, is_merge_complete,
2121
partially_verify_execution_payload,
2222
};
23+
use tree_hash::TreeHash;
2324
use types::*;
2425

2526
/// Verify that `execution_payload` contained by `block` is considered valid by an execution
@@ -57,10 +58,33 @@ pub fn execute_payload<T: BeaconChainTypes>(
5758
.block_on(|execution_layer| execution_layer.execute_payload(execution_payload));
5859

5960
match execute_payload_response {
60-
Ok((status, _latest_valid_hash)) => match status {
61-
ExecutePayloadResponseStatus::Valid => Ok(PayloadVerificationStatus::Verified),
62-
// TODO(merge): invalidate any invalid ancestors of this block in fork choice.
63-
ExecutePayloadResponseStatus::Invalid => {
61+
Ok(status) => match status {
62+
ExecutePayloadResponseStatus::Valid { .. } => Ok(PayloadVerificationStatus::Verified),
63+
ExecutePayloadResponseStatus::Invalid { latest_valid_hash } => {
64+
// TODO(paul): pass this value to avoid double hashing?
65+
let invalid_root = block.tree_hash_root();
66+
match chain
67+
.fork_choice
68+
.write()
69+
.on_invalid_execution_payload(invalid_root, latest_valid_hash)
70+
{
71+
Ok(()) => warn!(
72+
chain.log,
73+
"Invalid execution payload in block";
74+
"latest_valid_hash" => ?latest_valid_hash,
75+
"root" => ?invalid_root,
76+
),
77+
Err(e) => {
78+
crit!(
79+
chain.log,
80+
"Failed to process invalid payload";
81+
"latest_valid_hash" => ?latest_valid_hash,
82+
"root" => ?invalid_root,
83+
);
84+
85+
return Err(BeaconChainError::from(e).into());
86+
}
87+
}
6488
Err(ExecutionPayloadError::RejectedByExecutionEngine.into())
6589
}
6690
ExecutePayloadResponseStatus::Syncing => Ok(PayloadVerificationStatus::NotVerified),

consensus/proto_array/src/proto_array_fork_choice.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ impl ProtoArrayForkChoice {
153153
})
154154
}
155155

156+
pub fn process_execution_payload_invalidation(
157+
&mut self,
158+
invalid_root: Hash256,
159+
latest_valid_ancestor_root: Hash256,
160+
) -> Result<(), String> {
161+
self.proto_array
162+
.propagate_execution_payload_invalidation(invalid_root, latest_valid_ancestor_root)
163+
.map_err(|e| format!("Failed to process invalid payload: {:?}", e))
164+
}
165+
156166
pub fn process_attestation(
157167
&mut self,
158168
validator_index: usize,

0 commit comments

Comments
 (0)