Skip to content

Commit

Permalink
Fix block v3 reward encodings (#5049)
Browse files Browse the repository at this point in the history
* Fix block v3 reward encodings

* Use crates.io version
  • Loading branch information
michaelsproul authored Jan 9, 2024
1 parent 4a65d28 commit 7e948ee
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 7e948ee

Please sign in to comment.