From fc0b06a0399935c735f5316e8abda45ba29926f2 Mon Sep 17 00:00:00 2001 From: realbigsean Date: Fri, 4 Nov 2022 16:50:26 -0400 Subject: [PATCH] Feature gate withdrawals (#3684) * start feature gating * feature gate withdrawals --- beacon_node/Cargo.toml | 2 + beacon_node/beacon_chain/Cargo.toml | 2 + beacon_node/beacon_chain/src/beacon_chain.rs | 1 + beacon_node/execution_layer/Cargo.toml | 3 + beacon_node/execution_layer/src/engine_api.rs | 15 ++--- .../src/engine_api/json_structures.rs | 13 ++++ beacon_node/execution_layer/src/lib.rs | 4 ++ .../test_utils/execution_block_generator.rs | 1 + .../src/test_utils/mock_execution_layer.rs | 1 + beacon_node/store/Cargo.toml | 4 ++ beacon_node/store/src/partial_beacon_state.rs | 65 +++++++++++++++++++ consensus/state_processing/Cargo.toml | 2 + consensus/state_processing/src/common/mod.rs | 1 + .../src/common/withdraw_balance.rs | 1 + .../src/per_epoch_processing/capella.rs | 6 ++ .../capella/full_withdrawals.rs | 2 + .../capella/partial_withdrawals.rs | 2 + .../state_processing/src/upgrade/capella.rs | 3 + .../state_processing/src/upgrade/eip4844.rs | 13 +++- consensus/types/Cargo.toml | 1 + consensus/types/src/beacon_state.rs | 3 + consensus/types/src/execution_payload.rs | 1 + .../types/src/execution_payload_header.rs | 6 ++ lighthouse/Cargo.toml | 4 ++ 24 files changed, 144 insertions(+), 12 deletions(-) diff --git a/beacon_node/Cargo.toml b/beacon_node/Cargo.toml index b85aae2f4f..093f09949c 100644 --- a/beacon_node/Cargo.toml +++ b/beacon_node/Cargo.toml @@ -13,6 +13,8 @@ node_test_rig = { path = "../testing/node_test_rig" } [features] write_ssz_files = ["beacon_chain/write_ssz_files"] # Writes debugging .ssz files to /tmp during block processing. +withdrawals = ["beacon_chain/withdrawals", "types/withdrawals", "store/withdrawals", "execution_layer/withdrawals"] +withdrawals-processing = ["beacon_chain/withdrawals-processing", "store/withdrawals-processing", "execution_layer/withdrawals-processing"] [dependencies] eth2_config = { path = "../common/eth2_config" } diff --git a/beacon_node/beacon_chain/Cargo.toml b/beacon_node/beacon_chain/Cargo.toml index 5b85833048..39ff16c6b7 100644 --- a/beacon_node/beacon_chain/Cargo.toml +++ b/beacon_node/beacon_chain/Cargo.toml @@ -10,6 +10,8 @@ default = ["participation_metrics"] write_ssz_files = [] # Writes debugging .ssz files to /tmp during block processing. participation_metrics = [] # Exposes validator participation metrics to Prometheus. fork_from_env = [] # Initialise the harness chain spec from the FORK_NAME env variable +withdrawals = ["state_processing/withdrawals", "types/withdrawals", "store/withdrawals", "execution_layer/withdrawals"] +withdrawals-processing = ["state_processing/withdrawals-processing", "store/withdrawals-processing", "execution_layer/withdrawals-processing"] [dev-dependencies] maplit = "1.0.2" diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index d9be36686c..a7d0fe5c6c 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -4117,6 +4117,7 @@ impl BeaconChain { .get_suggested_fee_recipient(proposer as u64) .await, //FIXME(sean) + #[cfg(feature = "withdrawals")] withdrawals: vec![], }), }; diff --git a/beacon_node/execution_layer/Cargo.toml b/beacon_node/execution_layer/Cargo.toml index 5d6339996b..68a4f6a414 100644 --- a/beacon_node/execution_layer/Cargo.toml +++ b/beacon_node/execution_layer/Cargo.toml @@ -4,6 +4,9 @@ version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +withdrawals = ["state_processing/withdrawals", "types/withdrawals"] +withdrawals-processing = ["state_processing/withdrawals-processing"] [dependencies] types = { path = "../../consensus/types"} diff --git a/beacon_node/execution_layer/src/engine_api.rs b/beacon_node/execution_layer/src/engine_api.rs index f04a723789..ed940d4a88 100644 --- a/beacon_node/execution_layer/src/engine_api.rs +++ b/beacon_node/execution_layer/src/engine_api.rs @@ -155,6 +155,7 @@ pub struct ExecutionBlockWithTransactions { #[serde(rename = "hash")] pub block_hash: ExecutionBlockHash, pub transactions: Vec, + #[cfg(feature = "withdrawals")] #[superstruct(only(Capella, Eip4844))] pub withdrawals: Vec, } @@ -204,6 +205,7 @@ impl From> for ExecutionBlockWithTransactions .map(|tx| Transaction::decode(&Rlp::new(tx))) .collect::, _>>() .unwrap_or_else(|_| Vec::new()), + #[cfg(feature = "withdrawals")] withdrawals: block.withdrawals.into(), }) } @@ -229,6 +231,7 @@ impl From> for ExecutionBlockWithTransactions .map(|tx| Transaction::decode(&Rlp::new(tx))) .collect::, _>>() .unwrap_or_else(|_| Vec::new()), + #[cfg(feature = "withdrawals")] withdrawals: block.withdrawals.into(), }) } @@ -236,17 +239,6 @@ impl From> for ExecutionBlockWithTransactions } } -/* -impl From> for ExecutionPayload { - fn from(block: ExecutionBlockWithTransactions) -> Self { - map_execution_block_with_transactions!(block, |inner, cons| { - let block = inner.into(); - cons(block) - }) - } -} - */ - #[superstruct( variants(V1, V2), variant_attributes(derive(Clone, Debug, PartialEq),), @@ -261,6 +253,7 @@ pub struct PayloadAttributes { pub prev_randao: Hash256, #[superstruct(getter(copy))] pub suggested_fee_recipient: Address, + #[cfg(feature = "withdrawals")] #[superstruct(only(V2))] pub withdrawals: Vec, } diff --git a/beacon_node/execution_layer/src/engine_api/json_structures.rs b/beacon_node/execution_layer/src/engine_api/json_structures.rs index e32122ba31..6d1d70e78d 100644 --- a/beacon_node/execution_layer/src/engine_api/json_structures.rs +++ b/beacon_node/execution_layer/src/engine_api/json_structures.rs @@ -99,6 +99,7 @@ pub struct JsonExecutionPayloadHeader { pub excess_blobs: u64, pub block_hash: ExecutionBlockHash, pub transactions_root: Hash256, + #[cfg(feature = "withdrawals")] #[superstruct(only(V2, V3))] pub withdrawals_root: Hash256, } @@ -137,6 +138,7 @@ impl From> for ExecutionPayloadHeader< base_fee_per_gas: v2.base_fee_per_gas, block_hash: v2.block_hash, transactions_root: v2.transactions_root, + #[cfg(feature = "withdrawals")] withdrawals_root: v2.withdrawals_root, }), JsonExecutionPayloadHeader::V3(v3) => Self::Eip4844(ExecutionPayloadHeaderEip4844 { @@ -155,6 +157,7 @@ impl From> for ExecutionPayloadHeader< excess_blobs: v3.excess_blobs, block_hash: v3.block_hash, transactions_root: v3.transactions_root, + #[cfg(feature = "withdrawals")] withdrawals_root: v3.withdrawals_root, }), } @@ -195,6 +198,7 @@ impl From> for JsonExecutionPayloadHeader< base_fee_per_gas: capella.base_fee_per_gas, block_hash: capella.block_hash, transactions_root: capella.transactions_root, + #[cfg(feature = "withdrawals")] withdrawals_root: capella.withdrawals_root, }), ExecutionPayloadHeader::Eip4844(eip4844) => Self::V3(JsonExecutionPayloadHeaderV3 { @@ -213,6 +217,7 @@ impl From> for JsonExecutionPayloadHeader< excess_blobs: eip4844.excess_blobs, block_hash: eip4844.block_hash, transactions_root: eip4844.transactions_root, + #[cfg(feature = "withdrawals")] withdrawals_root: eip4844.withdrawals_root, }), } @@ -258,6 +263,7 @@ pub struct JsonExecutionPayload { #[serde(with = "ssz_types::serde_utils::list_of_hex_var_list")] pub transactions: VariableList, T::MaxTransactionsPerPayload>, + #[cfg(feature = "withdrawals")] #[superstruct(only(V2, V3))] pub withdrawals: VariableList, } @@ -296,6 +302,7 @@ impl From> for ExecutionPayload { base_fee_per_gas: v2.base_fee_per_gas, block_hash: v2.block_hash, transactions: v2.transactions, + #[cfg(feature = "withdrawals")] withdrawals: v2.withdrawals, }), JsonExecutionPayload::V3(v3) => Self::Eip4844(ExecutionPayloadEip4844 { @@ -314,6 +321,7 @@ impl From> for ExecutionPayload { excess_blobs: v3.excess_blobs, block_hash: v3.block_hash, transactions: v3.transactions, + #[cfg(feature = "withdrawals")] withdrawals: v3.withdrawals, }), } @@ -354,6 +362,7 @@ impl From> for JsonExecutionPayload { base_fee_per_gas: capella.base_fee_per_gas, block_hash: capella.block_hash, transactions: capella.transactions, + #[cfg(feature = "withdrawals")] withdrawals: capella.withdrawals, }), ExecutionPayload::Eip4844(eip4844) => Self::V3(JsonExecutionPayloadV3 { @@ -372,6 +381,7 @@ impl From> for JsonExecutionPayload { excess_blobs: eip4844.excess_blobs, block_hash: eip4844.block_hash, transactions: eip4844.transactions, + #[cfg(feature = "withdrawals")] withdrawals: eip4844.withdrawals, }), } @@ -425,6 +435,7 @@ pub struct JsonPayloadAttributes { pub timestamp: u64, pub prev_randao: Hash256, pub suggested_fee_recipient: Address, + #[cfg(feature = "withdrawals")] #[superstruct(only(V2))] pub withdrawals: Vec, } @@ -441,6 +452,7 @@ impl From for JsonPayloadAttributes { timestamp: pa.timestamp, prev_randao: pa.prev_randao, suggested_fee_recipient: pa.suggested_fee_recipient, + #[cfg(feature = "withdrawals")] withdrawals: pa.withdrawals.into_iter().map(Into::into).collect(), }), } @@ -459,6 +471,7 @@ impl From for PayloadAttributes { timestamp: jpa.timestamp, prev_randao: jpa.prev_randao, suggested_fee_recipient: jpa.suggested_fee_recipient, + #[cfg(feature = "withdrawals")] withdrawals: jpa.withdrawals.into_iter().map(Into::into).collect(), }), } diff --git a/beacon_node/execution_layer/src/lib.rs b/beacon_node/execution_layer/src/lib.rs index 21ee0457d2..04bdb4a20d 100644 --- a/beacon_node/execution_layer/src/lib.rs +++ b/beacon_node/execution_layer/src/lib.rs @@ -1499,6 +1499,7 @@ impl ExecutionLayer { }) } ExecutionBlockWithTransactions::Capella(capella_block) => { + #[cfg(feature = "withdrawals")] let withdrawals = VariableList::new(capella_block.withdrawals.clone()) .map_err(ApiError::DeserializeWithdrawals)?; @@ -1517,10 +1518,12 @@ impl ExecutionLayer { base_fee_per_gas: capella_block.base_fee_per_gas, block_hash: capella_block.block_hash, transactions, + #[cfg(feature = "withdrawals")] withdrawals, }) } ExecutionBlockWithTransactions::Eip4844(eip4844_block) => { + #[cfg(feature = "withdrawals")] let withdrawals = VariableList::new(eip4844_block.withdrawals.clone()) .map_err(ApiError::DeserializeWithdrawals)?; @@ -1540,6 +1543,7 @@ impl ExecutionLayer { excess_blobs: eip4844_block.excess_blobs, block_hash: eip4844_block.block_hash, transactions, + #[cfg(feature = "withdrawals")] withdrawals, }) } diff --git a/beacon_node/execution_layer/src/test_utils/execution_block_generator.rs b/beacon_node/execution_layer/src/test_utils/execution_block_generator.rs index c492bcd5a5..37eb8ba8f4 100644 --- a/beacon_node/execution_layer/src/test_utils/execution_block_generator.rs +++ b/beacon_node/execution_layer/src/test_utils/execution_block_generator.rs @@ -403,6 +403,7 @@ impl ExecutionBlockGenerator { base_fee_per_gas: Uint256::one(), block_hash: ExecutionBlockHash::zero(), transactions: vec![].into(), + #[cfg(feature = "withdrawals")] withdrawals: pa .withdrawals .iter() diff --git a/beacon_node/execution_layer/src/test_utils/mock_execution_layer.rs b/beacon_node/execution_layer/src/test_utils/mock_execution_layer.rs index d0bc2785c3..62336279b0 100644 --- a/beacon_node/execution_layer/src/test_utils/mock_execution_layer.rs +++ b/beacon_node/execution_layer/src/test_utils/mock_execution_layer.rs @@ -113,6 +113,7 @@ impl MockExecutionLayer { prev_randao, suggested_fee_recipient: Address::repeat_byte(42), // FIXME: think about adding withdrawals here.. + #[cfg(feature = "withdrawals")] withdrawals: vec![], }) } diff --git a/beacon_node/store/Cargo.toml b/beacon_node/store/Cargo.toml index 09d960535e..b3e8e1fc6b 100644 --- a/beacon_node/store/Cargo.toml +++ b/beacon_node/store/Cargo.toml @@ -26,3 +26,7 @@ lru = "0.7.1" sloggers = { version = "2.1.1", features = ["json"] } directory = { path = "../../common/directory" } strum = { version = "0.24.0", features = ["derive"] } + +[features] +withdrawals = ["state_processing/withdrawals", "types/withdrawals"] +withdrawals-processing = ["state_processing/withdrawals-processing"] \ No newline at end of file diff --git a/beacon_node/store/src/partial_beacon_state.rs b/beacon_node/store/src/partial_beacon_state.rs index 74e63c58ea..5cff00529e 100644 --- a/beacon_node/store/src/partial_beacon_state.rs +++ b/beacon_node/store/src/partial_beacon_state.rs @@ -105,10 +105,13 @@ where pub latest_execution_payload_header: ExecutionPayloadHeaderEip4844, // Withdrawals + #[cfg(feature = "withdrawals")] #[superstruct(only(Capella, Eip4844))] pub withdrawal_queue: VariableList, + #[cfg(feature = "withdrawals")] #[superstruct(only(Capella, Eip4844))] pub next_withdrawal_index: u64, + #[cfg(feature = "withdrawals")] #[superstruct(only(Capella, Eip4844))] pub next_partial_withdrawal_validator_index: u64, } @@ -199,6 +202,7 @@ impl PartialBeaconState { latest_execution_payload_header ] ), + #[cfg(feature = "withdrawals")] BeaconState::Capella(s) => impl_from_state_forgetful!( s, outer, @@ -216,6 +220,22 @@ impl PartialBeaconState { next_partial_withdrawal_validator_index ] ), + #[cfg(not(feature = "withdrawals"))] + BeaconState::Capella(s) => impl_from_state_forgetful!( + s, + outer, + Capella, + PartialBeaconStateCapella, + [ + previous_epoch_participation, + current_epoch_participation, + current_sync_committee, + next_sync_committee, + inactivity_scores, + latest_execution_payload_header + ] + ), + #[cfg(feature = "withdrawals")] BeaconState::Eip4844(s) => impl_from_state_forgetful!( s, outer, @@ -233,6 +253,21 @@ impl PartialBeaconState { next_partial_withdrawal_validator_index ] ), + #[cfg(not(feature = "withdrawals"))] + BeaconState::Eip4844(s) => impl_from_state_forgetful!( + s, + outer, + Eip4844, + PartialBeaconStateEip4844, + [ + previous_epoch_participation, + current_epoch_participation, + current_sync_committee, + next_sync_committee, + inactivity_scores, + latest_execution_payload_header + ] + ), } } @@ -420,6 +455,7 @@ impl TryInto> for PartialBeaconState { latest_execution_payload_header ] ), + #[cfg(feature = "withdrawals")] PartialBeaconState::Capella(inner) => impl_try_into_beacon_state!( inner, Capella, @@ -436,6 +472,21 @@ impl TryInto> for PartialBeaconState { next_partial_withdrawal_validator_index ] ), + #[cfg(not(feature = "withdrawals"))] + PartialBeaconState::Capella(inner) => impl_try_into_beacon_state!( + inner, + Capella, + BeaconStateCapella, + [ + previous_epoch_participation, + current_epoch_participation, + current_sync_committee, + next_sync_committee, + inactivity_scores, + latest_execution_payload_header + ] + ), + #[cfg(feature = "withdrawals")] PartialBeaconState::Eip4844(inner) => impl_try_into_beacon_state!( inner, Eip4844, @@ -452,6 +503,20 @@ impl TryInto> for PartialBeaconState { next_partial_withdrawal_validator_index ] ), + #[cfg(not(feature = "withdrawals"))] + PartialBeaconState::Eip4844(inner) => impl_try_into_beacon_state!( + inner, + Eip4844, + BeaconStateEip4844, + [ + previous_epoch_participation, + current_epoch_participation, + current_sync_committee, + next_sync_committee, + inactivity_scores, + latest_execution_payload_header + ] + ), }; Ok(state) } diff --git a/consensus/state_processing/Cargo.toml b/consensus/state_processing/Cargo.toml index ccb41830be..39a0be3d9f 100644 --- a/consensus/state_processing/Cargo.toml +++ b/consensus/state_processing/Cargo.toml @@ -43,3 +43,5 @@ arbitrary-fuzz = [ "eth2_ssz_types/arbitrary", "tree_hash/arbitrary", ] +withdrawals = ["types/withdrawals"] +withdrawals-processing = [] diff --git a/consensus/state_processing/src/common/mod.rs b/consensus/state_processing/src/common/mod.rs index 531891ee95..34091127c0 100644 --- a/consensus/state_processing/src/common/mod.rs +++ b/consensus/state_processing/src/common/mod.rs @@ -15,6 +15,7 @@ pub use get_attesting_indices::{get_attesting_indices, get_attesting_indices_fro pub use get_indexed_attestation::get_indexed_attestation; pub use initiate_validator_exit::initiate_validator_exit; pub use slash_validator::slash_validator; +#[cfg(feature = "withdrawals")] pub use withdraw_balance::withdraw_balance; use safe_arith::SafeArith; diff --git a/consensus/state_processing/src/common/withdraw_balance.rs b/consensus/state_processing/src/common/withdraw_balance.rs index 29b09cc0f9..65343f3112 100644 --- a/consensus/state_processing/src/common/withdraw_balance.rs +++ b/consensus/state_processing/src/common/withdraw_balance.rs @@ -2,6 +2,7 @@ use crate::common::decrease_balance; use safe_arith::SafeArith; use types::{BeaconStateError as Error, *}; +#[cfg(feature = "withdrawals")] pub fn withdraw_balance( state: &mut BeaconState, validator_index: usize, diff --git a/consensus/state_processing/src/per_epoch_processing/capella.rs b/consensus/state_processing/src/per_epoch_processing/capella.rs index d1bf71071d..ed5665d77a 100644 --- a/consensus/state_processing/src/per_epoch_processing/capella.rs +++ b/consensus/state_processing/src/per_epoch_processing/capella.rs @@ -5,11 +5,15 @@ use crate::per_epoch_processing::{ historical_roots_update::process_historical_roots_update, resets::{process_eth1_data_reset, process_randao_mixes_reset, process_slashings_reset}, }; +#[cfg(all(feature = "withdrawals", feature = "withdrawals-processing"))] pub use full_withdrawals::process_full_withdrawals; +#[cfg(all(feature = "withdrawals", feature = "withdrawals-processing"))] pub use partial_withdrawals::process_partial_withdrawals; use types::{BeaconState, ChainSpec, EthSpec, RelativeEpoch}; +#[cfg(all(feature = "withdrawals", feature = "withdrawals-processing"))] pub mod full_withdrawals; +#[cfg(all(feature = "withdrawals", feature = "withdrawals-processing"))] pub mod partial_withdrawals; pub fn process_epoch( @@ -66,8 +70,10 @@ pub fn process_epoch( altair::process_sync_committee_updates(state, spec)?; // Withdrawals + #[cfg(all(feature = "withdrawals", feature = "withdrawals-processing"))] process_full_withdrawals(state, spec)?; + #[cfg(all(feature = "withdrawals", feature = "withdrawals-processing"))] process_partial_withdrawals(state, spec)?; // Rotate the epoch caches to suit the epoch transition. diff --git a/consensus/state_processing/src/per_epoch_processing/capella/full_withdrawals.rs b/consensus/state_processing/src/per_epoch_processing/capella/full_withdrawals.rs index 62e4b91110..619301f16a 100644 --- a/consensus/state_processing/src/per_epoch_processing/capella/full_withdrawals.rs +++ b/consensus/state_processing/src/per_epoch_processing/capella/full_withdrawals.rs @@ -1,7 +1,9 @@ +#[cfg(all(feature = "withdrawals", feature = "withdrawals-processing"))] use crate::common::withdraw_balance; use crate::EpochProcessingError; use types::{beacon_state::BeaconState, eth_spec::EthSpec, ChainSpec}; +#[cfg(all(feature = "withdrawals", feature = "withdrawals-processing"))] pub fn process_full_withdrawals( state: &mut BeaconState, spec: &ChainSpec, diff --git a/consensus/state_processing/src/per_epoch_processing/capella/partial_withdrawals.rs b/consensus/state_processing/src/per_epoch_processing/capella/partial_withdrawals.rs index 75576ef6e7..d1ae4fee5a 100644 --- a/consensus/state_processing/src/per_epoch_processing/capella/partial_withdrawals.rs +++ b/consensus/state_processing/src/per_epoch_processing/capella/partial_withdrawals.rs @@ -1,8 +1,10 @@ +#[cfg(all(feature = "withdrawals", feature = "withdrawals-processing"))] use crate::common::withdraw_balance; use crate::EpochProcessingError; use safe_arith::SafeArith; use types::{beacon_state::BeaconState, eth_spec::EthSpec, ChainSpec}; +#[cfg(all(feature = "withdrawals", feature = "withdrawals-processing"))] pub fn process_partial_withdrawals( state: &mut BeaconState, spec: &ChainSpec, diff --git a/consensus/state_processing/src/upgrade/capella.rs b/consensus/state_processing/src/upgrade/capella.rs index b2abd3be20..e64c839806 100644 --- a/consensus/state_processing/src/upgrade/capella.rs +++ b/consensus/state_processing/src/upgrade/capella.rs @@ -57,8 +57,11 @@ pub fn upgrade_to_capella( // Execution latest_execution_payload_header: pre.latest_execution_payload_header.upgrade_to_capella(), // Withdrawals + #[cfg(feature = "withdrawals")] withdrawal_queue: VariableList::empty(), + #[cfg(feature = "withdrawals")] next_withdrawal_index: 0, + #[cfg(feature = "withdrawals")] next_partial_withdrawal_validator_index: 0, // Caches total_active_balance: pre.total_active_balance, diff --git a/consensus/state_processing/src/upgrade/eip4844.rs b/consensus/state_processing/src/upgrade/eip4844.rs index 666d5b0c68..d677fd6666 100644 --- a/consensus/state_processing/src/upgrade/eip4844.rs +++ b/consensus/state_processing/src/upgrade/eip4844.rs @@ -9,6 +9,14 @@ pub fn upgrade_to_eip4844( let epoch = pre_state.current_epoch(); let pre = pre_state.as_capella_mut()?; + // FIXME(sean) This is a hack to let us participate in testnets where capella doesn't exist. + // if we are disabling withdrawals, assume we should fork off of bellatrix. + let previous_fork_version = if cfg!(feature ="withdrawals") { + pre.fork.current_version + } else { + spec.bellatrix_fork_epoch + }; + // Where possible, use something like `mem::take` to move fields from behind the &mut // reference. For other fields that don't have a good default value, use `clone`. // @@ -20,7 +28,7 @@ pub fn upgrade_to_eip4844( genesis_validators_root: pre.genesis_validators_root, slot: pre.slot, fork: Fork { - previous_version: pre.fork.current_version, + previous_version: previous_fork_version, current_version: spec.eip4844_fork_version, epoch, }, @@ -56,8 +64,11 @@ pub fn upgrade_to_eip4844( // Execution latest_execution_payload_header: pre.latest_execution_payload_header.upgrade_to_eip4844(), // Withdrawals + #[cfg(feature = "withdrawals")] withdrawal_queue: mem::take(&mut pre.withdrawal_queue), + #[cfg(feature = "withdrawals")] next_withdrawal_index: pre.next_withdrawal_index, + #[cfg(feature = "withdrawals")] next_partial_withdrawal_validator_index: pre.next_partial_withdrawal_validator_index, // Caches total_active_balance: pre.total_active_balance, diff --git a/consensus/types/Cargo.toml b/consensus/types/Cargo.toml index d04d9d650f..c787a7a87a 100644 --- a/consensus/types/Cargo.toml +++ b/consensus/types/Cargo.toml @@ -71,3 +71,4 @@ arbitrary-fuzz = [ "swap_or_not_shuffle/arbitrary", "tree_hash/arbitrary", ] +withdrawals = [] diff --git a/consensus/types/src/beacon_state.rs b/consensus/types/src/beacon_state.rs index 3e7cbba924..ec5aa9c4f3 100644 --- a/consensus/types/src/beacon_state.rs +++ b/consensus/types/src/beacon_state.rs @@ -295,10 +295,13 @@ where pub latest_execution_payload_header: ExecutionPayloadHeaderEip4844, // Withdrawals + #[cfg(feature = "withdrawals")] #[superstruct(only(Capella, Eip4844))] pub withdrawal_queue: VariableList, + #[cfg(feature = "withdrawals")] #[superstruct(only(Capella, Eip4844))] pub next_withdrawal_index: u64, + #[cfg(feature = "withdrawals")] #[superstruct(only(Capella, Eip4844))] pub next_partial_withdrawal_validator_index: u64, diff --git a/consensus/types/src/execution_payload.rs b/consensus/types/src/execution_payload.rs index 6110b7f4fd..022f378e39 100644 --- a/consensus/types/src/execution_payload.rs +++ b/consensus/types/src/execution_payload.rs @@ -80,6 +80,7 @@ pub struct ExecutionPayload { pub block_hash: ExecutionBlockHash, #[serde(with = "ssz_types::serde_utils::list_of_hex_var_list")] pub transactions: Transactions, + #[cfg(feature = "withdrawals")] #[superstruct(only(Capella, Eip4844))] pub withdrawals: VariableList, } diff --git a/consensus/types/src/execution_payload_header.rs b/consensus/types/src/execution_payload_header.rs index 342a2d97e7..7546ca2e5f 100644 --- a/consensus/types/src/execution_payload_header.rs +++ b/consensus/types/src/execution_payload_header.rs @@ -74,6 +74,7 @@ pub struct ExecutionPayloadHeader { pub block_hash: ExecutionBlockHash, #[superstruct(getter(copy))] pub transactions_root: Hash256, + #[cfg(feature = "withdrawals")] #[superstruct(only(Capella, Eip4844))] #[superstruct(getter(copy))] pub withdrawals_root: Hash256, @@ -104,6 +105,7 @@ impl<'a, T: EthSpec> ExecutionPayloadHeaderRef<'a, T> { impl ExecutionPayloadHeaderMerge { pub fn upgrade_to_capella(&self) -> ExecutionPayloadHeaderCapella { + #[cfg(feature = "withdrawals")] // TODO: if this is correct we should calculate and hardcode this.. let empty_withdrawals_root = VariableList::::empty().tree_hash_root(); @@ -122,6 +124,7 @@ impl ExecutionPayloadHeaderMerge { base_fee_per_gas: self.base_fee_per_gas, block_hash: self.block_hash, transactions_root: self.transactions_root, + #[cfg(feature = "withdrawals")] // FIXME: the spec doesn't seem to define what to do here.. withdrawals_root: empty_withdrawals_root, } @@ -147,6 +150,7 @@ impl ExecutionPayloadHeaderCapella { excess_blobs: 0, block_hash: self.block_hash, transactions_root: self.transactions_root, + #[cfg(feature = "withdrawals")] withdrawals_root: self.withdrawals_root, } } @@ -189,6 +193,7 @@ impl From> for ExecutionPayloadHeaderCape base_fee_per_gas: payload.base_fee_per_gas, block_hash: payload.block_hash, transactions_root: payload.transactions.tree_hash_root(), + #[cfg(feature = "withdrawals")] withdrawals_root: payload.withdrawals.tree_hash_root(), } } @@ -211,6 +216,7 @@ impl From> for ExecutionPayloadHeaderEip4 excess_blobs: payload.excess_blobs, block_hash: payload.block_hash, transactions_root: payload.transactions.tree_hash_root(), + #[cfg(feature = "withdrawals")] withdrawals_root: payload.withdrawals.tree_hash_root(), } } diff --git a/lighthouse/Cargo.toml b/lighthouse/Cargo.toml index 864869a149..7864b7e82b 100644 --- a/lighthouse/Cargo.toml +++ b/lighthouse/Cargo.toml @@ -24,6 +24,10 @@ gnosis = [] slasher-mdbx = ["slasher/mdbx"] # Support slasher LMDB backend. slasher-lmdb = ["slasher/lmdb"] +# Support for inclusion of withdrawals fields in all capella consensus types in all APIs. +withdrawals = ["types/withdrawals", "beacon_node/withdrawals"] +# Support for withdrawals consensus processing logic. +withdrawals-processing = ["beacon_node/withdrawals-processing"] [dependencies] beacon_node = { "path" = "../beacon_node" }