@@ -5,20 +5,21 @@ use std::sync::Arc;
5
5
use alloy_consensus:: { BlockHeader , Header } ;
6
6
use alloy_rpc_types_engine:: { ExecutionPayloadSidecar , PayloadError } ;
7
7
use reth_node_builder:: {
8
- EngineApiMessageVersion , EngineObjectValidationError , EngineTypes , EngineValidator ,
9
- InvalidPayloadAttributesError , PayloadAttributes , PayloadOrAttributes , PayloadTypes ,
10
- PayloadValidator ,
8
+ validate_parent_beacon_block_root_presence, EngineApiMessageVersion ,
9
+ EngineObjectValidationError , EngineTypes , EngineValidator , InvalidPayloadAttributesError ,
10
+ MessageValidationKind , PayloadAttributes , PayloadOrAttributes , PayloadTypes , PayloadValidator ,
11
+ VersionSpecificValidationError ,
11
12
} ;
12
13
use reth_payload_builder:: EthBuiltPayload ;
13
- use reth_payload_primitives:: validate_version_specific_fields;
14
- use reth_primitives:: { Block , SealedBlock } ;
14
+ use reth_primitives:: { Block , EthereumHardforks , SealedBlock } ;
15
15
use reth_taiko_chainspec:: TaikoChainSpec ;
16
16
use reth_taiko_engine_primitives:: {
17
17
ExecutionPayloadEnvelopeV3 , ExecutionPayloadEnvelopeV4 , ExecutionPayloadV1 ,
18
18
TaikoExecutionPayloadEnvelopeV2 , TaikoPayloadBuilderAttributes ,
19
19
} ;
20
20
use reth_taiko_engine_types:: { TaikoExecutionPayload , TaikoPayloadAttributes } ;
21
21
use reth_taiko_payload_validator:: TaikoExecutionPayloadValidator ;
22
+ use reth_tracing:: tracing:: debug;
22
23
23
24
/// The types used in the default mainnet ethereum beacon consensus engine.
24
25
#[ derive( Debug , Default , Clone , serde:: Deserialize , serde:: Serialize ) ]
@@ -97,15 +98,25 @@ where
97
98
version : EngineApiMessageVersion ,
98
99
payload_or_attrs : PayloadOrAttributes < ' _ , TaikoPayloadAttributes > ,
99
100
) -> Result < ( ) , EngineObjectValidationError > {
100
- validate_version_specific_fields ( self . chain_spec ( ) , version, payload_or_attrs)
101
+ debug ! ( target: "taiko::engine" , version=?version, payload_or_attrs=?payload_or_attrs) ;
102
+ let res = validate_version_specific_fields ( self . chain_spec ( ) , version, payload_or_attrs) ;
103
+ debug ! ( target: "taiko::engine" , version=?version, ?res) ;
104
+ res
101
105
}
102
106
103
107
fn ensure_well_formed_attributes (
104
108
& self ,
105
109
version : EngineApiMessageVersion ,
106
110
attributes : & TaikoPayloadAttributes ,
107
111
) -> Result < ( ) , EngineObjectValidationError > {
108
- validate_version_specific_fields ( self . chain_spec ( ) , version, attributes. into ( ) )
112
+ debug ! ( target: "taiko::engine" , version=?version, attributes=?attributes) ;
113
+ let res = reth_payload_primitives:: validate_version_specific_fields (
114
+ self . chain_spec ( ) ,
115
+ version,
116
+ attributes. into ( ) ,
117
+ ) ;
118
+ debug ! ( target: "taiko::engine" , version=?version, ?res) ;
119
+ res
109
120
}
110
121
111
122
fn validate_payload_attributes_against_header (
@@ -119,3 +130,55 @@ where
119
130
Ok ( ( ) )
120
131
}
121
132
}
133
+
134
+ fn validate_withdrawals_presence < T : EthereumHardforks > (
135
+ chain_spec : & T ,
136
+ version : EngineApiMessageVersion ,
137
+ message_validation_kind : MessageValidationKind ,
138
+ timestamp : u64 ,
139
+ has_withdrawals : bool ,
140
+ ) -> Result < ( ) , EngineObjectValidationError > {
141
+ let is_shanghai_active = chain_spec. is_shanghai_active_at_timestamp ( timestamp) ;
142
+
143
+ match version {
144
+ EngineApiMessageVersion :: V1 => {
145
+ if has_withdrawals {
146
+ return Err ( message_validation_kind
147
+ . to_error ( VersionSpecificValidationError :: WithdrawalsNotSupportedInV1 ) )
148
+ }
149
+ }
150
+ EngineApiMessageVersion :: V2 | EngineApiMessageVersion :: V3 | EngineApiMessageVersion :: V4 => {
151
+ if !is_shanghai_active && has_withdrawals {
152
+ return Err ( message_validation_kind
153
+ . to_error ( VersionSpecificValidationError :: HasWithdrawalsPreShanghai ) )
154
+ }
155
+ }
156
+ } ;
157
+
158
+ Ok ( ( ) )
159
+ }
160
+
161
+ fn validate_version_specific_fields < Type , T > (
162
+ chain_spec : & T ,
163
+ version : EngineApiMessageVersion ,
164
+ payload_or_attrs : PayloadOrAttributes < ' _ , Type > ,
165
+ ) -> Result < ( ) , EngineObjectValidationError >
166
+ where
167
+ Type : PayloadAttributes ,
168
+ T : EthereumHardforks ,
169
+ {
170
+ validate_withdrawals_presence (
171
+ chain_spec,
172
+ version,
173
+ payload_or_attrs. message_validation_kind ( ) ,
174
+ payload_or_attrs. timestamp ( ) ,
175
+ payload_or_attrs. withdrawals ( ) . is_some ( ) ,
176
+ ) ?;
177
+ validate_parent_beacon_block_root_presence (
178
+ chain_spec,
179
+ version,
180
+ payload_or_attrs. message_validation_kind ( ) ,
181
+ payload_or_attrs. timestamp ( ) ,
182
+ payload_or_attrs. parent_beacon_block_root ( ) . is_some ( ) ,
183
+ )
184
+ }
0 commit comments