Skip to content

Commit

Permalink
Add ExecutionWitness to Payload
Browse files Browse the repository at this point in the history
  • Loading branch information
Mac L committed May 13, 2024
1 parent b786e6d commit b92786a
Show file tree
Hide file tree
Showing 19 changed files with 472 additions and 57 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ validator_dir = { path = "common/validator_dir" }
warp_utils = { path = "common/warp_utils" }

[patch.crates-io]
ssz_types = { git = "https://github.com/macladson/ssz_types.git", branch = "optional" }
yamux = { git = "https://github.com/sigp/rust-yamux.git" }

[profile.maxperf]
Expand Down
20 changes: 9 additions & 11 deletions beacon_node/client/src/notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,17 +549,15 @@ async fn electra_readiness_logging<T: BeaconChainTypes>(
beacon_chain: &BeaconChain<T>,
log: &Logger,
) {
// TODO(electra): Once Electra has features, this code can be swapped back.
let electra_completed = false;
//let electra_completed = beacon_chain
// .canonical_head
// .cached_head()
// .snapshot
// .beacon_block
// .message()
// .body()
// .execution_payload()
// .map_or(false, |payload| payload.electra_placeholder().is_ok());
let electra_completed = beacon_chain
.canonical_head
.cached_head()
.snapshot
.beacon_block
.message()
.body()
.execution_payload()
.map_or(false, |payload| payload.execution_witness_root().is_ok());

let has_execution_layer = beacon_chain.execution_layer.is_some();

Expand Down
9 changes: 9 additions & 0 deletions beacon_node/execution_layer/src/block_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ pub fn calculate_execution_block_hash<E: EthSpec>(
None
};

// TODO(mac): Fix rlp calc
let rlp_execution_witness_root = None;

let rlp_blob_gas_used = payload.blob_gas_used().ok();
let rlp_excess_blob_gas = payload.excess_blob_gas().ok();

Expand All @@ -48,6 +51,7 @@ pub fn calculate_execution_block_hash<E: EthSpec>(
rlp_blob_gas_used,
rlp_excess_blob_gas,
parent_beacon_block_root,
rlp_execution_witness_root,
);

// Hash the RLP encoding of the block header.
Expand Down Expand Up @@ -137,6 +141,7 @@ mod test {
blob_gas_used: None,
excess_blob_gas: None,
parent_beacon_block_root: None,
execution_witness_root: None,
};
let expected_rlp = "f90200a0e0a94a7a3c9617401586b1a27025d2d9671332d22d540e0af72b069170380f2aa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794ba5e000000000000000000000000000000000000a0ec3c94b18b8a1cff7d60f8d258ec723312932928626b4c9355eb4ab3568ec7f7a050f738580ed699f0469702c7ccc63ed2e51bc034be9479b7bff4e68dee84accfa029b0562f7140574dd0d50dee8a271b22e1a0a7b78fca58f7c60370d8317ba2a9b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200000188016345785d8a00008301553482079e42a0000000000000000000000000000000000000000000000000000000000000000088000000000000000082036b";
let expected_hash =
Expand Down Expand Up @@ -168,6 +173,7 @@ mod test {
blob_gas_used: None,
excess_blob_gas: None,
parent_beacon_block_root: None,
execution_witness_root: None,
};
let expected_rlp = "f901fda0927ca537f06c783a3a2635b8805eef1c8c2124f7444ad4a3389898dd832f2dbea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794ba5e000000000000000000000000000000000000a0e97859b065bd8dbbb4519c7cb935024de2484c2b7f881181b4360492f0b06b82a050f738580ed699f0469702c7ccc63ed2e51bc034be9479b7bff4e68dee84accfa029b0562f7140574dd0d50dee8a271b22e1a0a7b78fca58f7c60370d8317ba2a9b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800188016345785d8a00008301553482079e42a0000000000000000000000000000000000000000000000000000000000002000088000000000000000082036b";
let expected_hash =
Expand Down Expand Up @@ -200,6 +206,7 @@ mod test {
blob_gas_used: None,
excess_blob_gas: None,
parent_beacon_block_root: None,
execution_witness_root: None,
};
let expected_hash =
Hash256::from_str("6da69709cd5a34079b6604d29cd78fc01dacd7c6268980057ad92a2bede87351")
Expand Down Expand Up @@ -230,6 +237,7 @@ mod test {
blob_gas_used: Some(0x0u64),
excess_blob_gas: Some(0x0u64),
parent_beacon_block_root: Some(Hash256::from_str("f7d327d2c04e4f12e9cdd492e53d39a1d390f8b1571e3b2a22ac6e1e170e5b1a").unwrap()),
execution_witness_root: None,
};
let expected_hash =
Hash256::from_str("a7448e600ead0a23d16f96aa46e8dea9eef8a7c5669a5f0a5ff32709afe9c408")
Expand Down Expand Up @@ -260,6 +268,7 @@ mod test {
blob_gas_used: Some(0x0u64),
excess_blob_gas: Some(0x0u64),
parent_beacon_block_root: Some(Hash256::from_str("f7d327d2c04e4f12e9cdd492e53d39a1d390f8b1571e3b2a22ac6e1e170e5b1a").unwrap()),
execution_witness_root: None,
};
let expected_hash =
Hash256::from_str("a7448e600ead0a23d16f96aa46e8dea9eef8a7c5669a5f0a5ff32709afe9c408")
Expand Down
52 changes: 31 additions & 21 deletions beacon_node/execution_layer/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use strum::IntoStaticStr;
use superstruct::superstruct;
pub use types::{
Address, BeaconBlockRef, EthSpec, ExecutionBlockHash, ExecutionPayload, ExecutionPayloadHeader,
ExecutionPayloadRef, FixedVector, ForkName, Hash256, Transactions, Uint256, VariableList,
Withdrawal, Withdrawals,
ExecutionPayloadRef, ExecutionWitness, FixedVector, ForkName, Hash256, Transactions, Uint256,
VariableList, Withdrawal, Withdrawals,
};

use types::{
Expand Down Expand Up @@ -197,6 +197,8 @@ pub struct ExecutionBlockWithTransactions<E: EthSpec> {
#[superstruct(only(Deneb, Electra))]
#[serde(with = "serde_utils::u64_hex_be")]
pub excess_blob_gas: u64,
#[superstruct(only(Electra))]
pub execution_witness: ExecutionWitness<E>,
}

impl<E: EthSpec> TryFrom<ExecutionPayload<E>> for ExecutionBlockWithTransactions<E> {
Expand Down Expand Up @@ -302,6 +304,7 @@ impl<E: EthSpec> TryFrom<ExecutionPayload<E>> for ExecutionBlockWithTransactions
.collect(),
blob_gas_used: block.blob_gas_used,
excess_blob_gas: block.excess_blob_gas,
execution_witness: block.execution_witness,
})
}
};
Expand Down Expand Up @@ -521,6 +524,7 @@ impl<E: EthSpec> GetPayloadResponse<E> {
pub struct ExecutionPayloadBodyV1<E: EthSpec> {
pub transactions: Transactions<E>,
pub withdrawals: Option<Withdrawals<E>>,
pub execution_witness: Option<ExecutionWitness<E>>,
}

impl<E: EthSpec> ExecutionPayloadBodyV1<E> {
Expand Down Expand Up @@ -609,25 +613,31 @@ impl<E: EthSpec> ExecutionPayloadBodyV1<E> {
}
ExecutionPayloadHeader::Electra(header) => {
if let Some(withdrawals) = self.withdrawals {
Ok(ExecutionPayload::Electra(ExecutionPayloadElectra {
parent_hash: header.parent_hash,
fee_recipient: header.fee_recipient,
state_root: header.state_root,
receipts_root: header.receipts_root,
logs_bloom: header.logs_bloom,
prev_randao: header.prev_randao,
block_number: header.block_number,
gas_limit: header.gas_limit,
gas_used: header.gas_used,
timestamp: header.timestamp,
extra_data: header.extra_data,
base_fee_per_gas: header.base_fee_per_gas,
block_hash: header.block_hash,
transactions: self.transactions,
withdrawals,
blob_gas_used: header.blob_gas_used,
excess_blob_gas: header.excess_blob_gas,
}))
if let Some(execution_witness) = self.execution_witness {
Ok(ExecutionPayload::Electra(ExecutionPayloadElectra {
parent_hash: header.parent_hash,
fee_recipient: header.fee_recipient,
state_root: header.state_root,
receipts_root: header.receipts_root,
logs_bloom: header.logs_bloom,
prev_randao: header.prev_randao,
block_number: header.block_number,
gas_limit: header.gas_limit,
gas_used: header.gas_used,
timestamp: header.timestamp,
extra_data: header.extra_data,
base_fee_per_gas: header.base_fee_per_gas,
block_hash: header.block_hash,
transactions: self.transactions,
withdrawals,
blob_gas_used: header.blob_gas_used,
excess_blob_gas: header.excess_blob_gas,
execution_witness,
}))
} else {
Err(format!(
"block {} is post-electra but payload body doesn't have an execution witness", header.block_hash))
}
} else {
Err(format!(
"block {} is post-capella but payload body doesn't have withdrawals",
Expand Down
Loading

0 comments on commit b92786a

Please sign in to comment.