Skip to content

Commit f99ca4d

Browse files
authored
fix(core): Made engine_forkchoiceUpdatedV3 second parameter optional (#2575)
**Motivation** This PR makes it so that when parsing engine_forkchoiceUpdatedV3 the second parameter isn't required. This came to light while testing odometer #2507, which sent the updates without the second parameter. This change makes it more conforming with the spec. **Description** Made it so that the second optional parameter in engine_forkchoiceUpdatedV3 ( Payload attributes) isn't required to be sent in the post request. Note: this was already working if the second parameter was sent as a null or had problems.
1 parent 214e353 commit f99ca4d

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

crates/networking/rpc/engine/fork_choice.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,20 +174,24 @@ fn parse(
174174
let params = params
175175
.as_ref()
176176
.ok_or(RpcErr::BadParams("No params provided".to_owned()))?;
177-
if params.len() != 2 {
178-
return Err(RpcErr::BadParams("Expected 2 params".to_owned()));
177+
178+
if params.len() != 2 && params.len() != 1 {
179+
return Err(RpcErr::BadParams("Expected 2 or 1 params".to_owned()));
179180
}
180181

181182
let forkchoice_state: ForkChoiceState = serde_json::from_value(params[0].clone())?;
182-
// if there is an error when parsing, set to None
183-
let payload_attributes: Option<PayloadAttributesV3> =
184-
match serde_json::from_value::<Option<PayloadAttributesV3>>(params[1].clone()) {
185-
Ok(attributes) => attributes,
186-
Err(error) => {
187-
info!("Could not parse params {}", error);
188-
None
189-
}
190-
};
183+
let mut payload_attributes: Option<PayloadAttributesV3> = None;
184+
if params.len() == 2 {
185+
// if there is an error when parsing (or the parameter is missing), set to None
186+
payload_attributes =
187+
match serde_json::from_value::<Option<PayloadAttributesV3>>(params[1].clone()) {
188+
Ok(attributes) => attributes,
189+
Err(error) => {
190+
info!("Could not parse params {}", error);
191+
None
192+
}
193+
};
194+
}
191195
if let Some(attr) = &payload_attributes {
192196
if !is_v3 && attr.parent_beacon_block_root.is_some() {
193197
return Err(RpcErr::InvalidPayloadAttributes(

0 commit comments

Comments
 (0)