Skip to content

Commit 5d14571

Browse files
jenpaffampcode-com
andauthored
fix(engine): deserialize PayloadAttributes.slot_number as hex string (#3619)
The execution-apis spec defines slotNumber as uint64 (hex-encoded string), but PayloadAttributes was missing the serde quantity attribute. This caused engine_forkchoiceUpdatedV4 to fail with: 'invalid type: string "0x0", expected u64' See: ethereum/execution-apis#731 Amp-Thread-ID: https://ampcode.com/threads/T-019c0b50-5b65-759b-b375-7a23102f5675 Co-authored-by: Amp <amp@ampcode.com>
1 parent 2ff2a80 commit 5d14571

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

crates/rpc-types-engine/src/payload.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,8 +2462,17 @@ pub struct PayloadAttributes {
24622462
/// See also <https://github.com/ethereum/execution-apis/blob/main/src/engine/cancun.md#payloadattributesv3>
24632463
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
24642464
pub parent_beacon_block_root: Option<B256>,
2465-
/// Slot of the current block enabled with Amsterdam fork
2466-
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
2465+
/// Slot of the current block enabled with Amsterdam fork.
2466+
///
2467+
/// See <https://github.com/ethereum/execution-apis/pull/731>
2468+
#[cfg_attr(
2469+
feature = "serde",
2470+
serde(
2471+
default,
2472+
skip_serializing_if = "Option::is_none",
2473+
with = "alloy_serde::quantity::opt"
2474+
)
2475+
)]
24672476
pub slot_number: Option<u64>,
24682477
}
24692478

@@ -3562,4 +3571,21 @@ mod tests {
35623571
assert_eq!(attrs.timestamp, 0x1234);
35633572
assert!(attrs.slot_number.is_none());
35643573
}
3574+
3575+
#[test]
3576+
#[cfg(feature = "serde")]
3577+
fn serde_payload_attributes_with_hex_slot_number() {
3578+
let json = r#"{
3579+
"timestamp": "0x2",
3580+
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000",
3581+
"suggestedFeeRecipient": "0x0000000000000000000000000000000000000000",
3582+
"withdrawals": [],
3583+
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
3584+
"slotNumber": "0x0"
3585+
}"#;
3586+
3587+
let attrs: PayloadAttributes = serde_json::from_str(json).unwrap();
3588+
assert_eq!(attrs.timestamp, 0x2);
3589+
assert_eq!(attrs.slot_number, Some(0));
3590+
}
35653591
}

0 commit comments

Comments
 (0)