From dfc817ec4fc888749fe22239b36eda96b4471c3d Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Tue, 9 Jan 2024 17:56:56 +1100 Subject: [PATCH] Fix block v3 reward encodings (#5049) Squashed commit of the following: commit cfb09946a705846994d8ba4876c7b88a0a2131b7 Author: Michael Sproul Date: Tue Jan 9 15:59:25 2024 +1100 Fix block v3 reward encodings --- Cargo.toml | 4 +++- beacon_node/beacon_chain/src/beacon_chain.rs | 6 +++++- beacon_node/http_api/src/produce_block.rs | 2 +- beacon_node/http_api/src/version.rs | 2 +- common/eth2/src/types.rs | 7 ++++--- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6847d650eee..c40b544b448 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -110,7 +110,9 @@ env_logger = "0.9" error-chain = "0.12" ethereum-types = "0.14" ethereum_hashing = "1.0.0-beta.2" -ethereum_serde_utils = "0.5" +# ethereum_serde_utils = "0.5" +# FIXME(sproul): restore crates.io version +ethereum_serde_utils = { git = "https://github.com/sigp/ethereum_serde_utils", branch = "decimal-u256" } ethereum_ssz = "0.5" ethereum_ssz_derive = "0.5" ethers-core = "1" diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 715ba715246..bf418054799 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -511,13 +511,17 @@ impl BeaconBlockResponseWrapper { } } - pub fn consensus_block_value(&self) -> u64 { + pub fn consensus_block_value_gwei(&self) -> u64 { match self { BeaconBlockResponseWrapper::Full(resp) => resp.consensus_block_value, BeaconBlockResponseWrapper::Blinded(resp) => resp.consensus_block_value, } } + pub fn consensus_block_value_wei(&self) -> Uint256 { + Uint256::from(self.consensus_block_value_gwei()) * 1_000_000_000 + } + pub fn is_blinded(&self) -> bool { matches!(self, BeaconBlockResponseWrapper::Blinded(_)) } diff --git a/beacon_node/http_api/src/produce_block.rs b/beacon_node/http_api/src/produce_block.rs index 3ab66614e4e..eb6863ceef7 100644 --- a/beacon_node/http_api/src/produce_block.rs +++ b/beacon_node/http_api/src/produce_block.rs @@ -80,7 +80,7 @@ pub fn build_response_v3( .fork_name(&chain.spec) .map_err(inconsistent_fork_rejection)?; let execution_payload_value = block_response.execution_payload_value(); - let consensus_block_value = block_response.consensus_block_value(); + let consensus_block_value = block_response.consensus_block_value_wei(); let execution_payload_blinded = block_response.is_blinded(); let metadata = ProduceBlockV3Metadata { diff --git a/beacon_node/http_api/src/version.rs b/beacon_node/http_api/src/version.rs index 343defb809f..7cd5e6700a0 100644 --- a/beacon_node/http_api/src/version.rs +++ b/beacon_node/http_api/src/version.rs @@ -93,7 +93,7 @@ pub fn add_execution_payload_value_header( /// Add the `Eth-Consensus-Block-Value` header to a response. pub fn add_consensus_block_value_header( reply: T, - consensus_payload_value: u64, + consensus_payload_value: Uint256, ) -> Response { reply::with_header( reply, diff --git a/common/eth2/src/types.rs b/common/eth2/src/types.rs index 46c0dff8b40..98074615b8d 100644 --- a/common/eth2/src/types.rs +++ b/common/eth2/src/types.rs @@ -1554,9 +1554,10 @@ pub struct ProduceBlockV3Metadata { )] pub consensus_version: ForkName, pub execution_payload_blinded: bool, + #[serde(with = "serde_utils::u256_dec")] pub execution_payload_value: Uint256, - #[serde(with = "serde_utils::quoted_u64")] - pub consensus_block_value: u64, + #[serde(with = "serde_utils::u256_dec")] + pub consensus_block_value: Uint256, } impl FullBlockContents { @@ -1707,7 +1708,7 @@ impl TryFrom<&HeaderMap> for ProduceBlockV3Metadata { })?; let consensus_block_value = parse_required_header(headers, CONSENSUS_BLOCK_VALUE_HEADER, |s| { - s.parse::() + s.parse::() .map_err(|e| format!("invalid {CONSENSUS_BLOCK_VALUE_HEADER}: {e:?}")) })?;