Skip to content

Commit

Permalink
Fix block v3 reward encodings (#5049)
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit cfb0994
Author: Michael Sproul <michael@sigmaprime.io>
Date:   Tue Jan 9 15:59:25 2024 +1100

    Fix block v3 reward encodings
  • Loading branch information
paulhauner committed Jan 9, 2024
1 parent 73238ff commit dfc817e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,17 @@ impl<E: EthSpec> BeaconBlockResponseWrapper<E> {
}
}

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(_))
}
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/http_api/src/produce_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn build_response_v3<T: BeaconChainTypes>(
.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 {
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/http_api/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn add_execution_payload_value_header<T: Reply>(
/// Add the `Eth-Consensus-Block-Value` header to a response.
pub fn add_consensus_block_value_header<T: Reply>(
reply: T,
consensus_payload_value: u64,
consensus_payload_value: Uint256,
) -> Response {
reply::with_header(
reply,
Expand Down
7 changes: 4 additions & 3 deletions common/eth2/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: EthSpec> FullBlockContents<T> {
Expand Down Expand Up @@ -1707,7 +1708,7 @@ impl TryFrom<&HeaderMap> for ProduceBlockV3Metadata {
})?;
let consensus_block_value =
parse_required_header(headers, CONSENSUS_BLOCK_VALUE_HEADER, |s| {
s.parse::<u64>()
s.parse::<Uint256>()
.map_err(|e| format!("invalid {CONSENSUS_BLOCK_VALUE_HEADER}: {e:?}"))
})?;

Expand Down

0 comments on commit dfc817e

Please sign in to comment.