@@ -14,12 +14,13 @@ use crate::{
1414use execution_layer:: ExecutePayloadResponseStatus ;
1515use fork_choice:: PayloadVerificationStatus ;
1616use proto_array:: { Block as ProtoBlock , ExecutionStatus } ;
17- use slog:: debug;
17+ use slog:: { crit , debug, warn } ;
1818use slot_clock:: SlotClock ;
1919use 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 ;
2324use 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 ) ,
0 commit comments