From 9b281c176c42fde3efdff67eaae23695f55eadae Mon Sep 17 00:00:00 2001 From: Joseph Livesey Date: Wed, 18 Sep 2024 11:35:51 -0400 Subject: [PATCH 1/2] feat(beacon): support try from block for deneb beacon block --- src/lib.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 4b9bd69..6cf4ca7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -682,6 +682,46 @@ pub mod beacon { Ok(beacon_block_body) } } + + impl TryFrom + for types::BeaconBlockBodyDeneb + { + type Error = ProtosError; + + fn try_from( + body: crate::beacon::r#type::v1::block::Body, + ) -> Result { + match body { + crate::beacon::r#type::v1::block::Body::Deneb(deneb) => { + Ok(deneb.try_into()?) + } + _ => panic!("Invalid body type"), + } + } + } + + impl TryFrom for types::BeaconBlock { + type Error = ProtosError; + + fn try_from( + Block { + slot, + proposer_index, + parent_root, + state_root, + body, + .. + }: Block, + ) -> Result { + Ok(Self::Deneb(types::BeaconBlockDeneb { + slot: slot.into(), + proposer_index, + parent_root: H256::from_slice(parent_root.as_slice()), + state_root: H256::from_slice(state_root.as_slice()), + body: body.ok_or(ProtosError::BlockConversionError)?.try_into()?, + })) + } + } } } } From f721fdcd6886ff0a94aecc8628fa16f6a201867b Mon Sep 17 00:00:00 2001 From: Joseph Livesey Date: Wed, 18 Sep 2024 14:36:50 -0400 Subject: [PATCH 2/2] fix: fix timestamp in beacon block lighthouse conversion --- src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6cf4ca7..e8c3924 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -361,8 +361,9 @@ pub mod beacon { gas_limit, gas_used, timestamp: timestamp - .map(|ts| ts.seconds as u64 * 1_000_000_000 + ts.nanos as u64) - .unwrap_or_default(), + .as_ref() + .ok_or(ProtosError::BlockConversionError)? + .seconds as u64, extra_data: extra_data.into(), base_fee_per_gas: U256::from_big_endian(base_fee_per_gas.as_slice()), block_hash: ExecutionBlockHash(H256::from_slice(block_hash.as_slice())),