mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 00:42:42 +00:00
Feature gate withdrawals (#3684)
* start feature gating * feature gate withdrawals
This commit is contained in:
@@ -43,3 +43,5 @@ arbitrary-fuzz = [
|
||||
"eth2_ssz_types/arbitrary",
|
||||
"tree_hash/arbitrary",
|
||||
]
|
||||
withdrawals = ["types/withdrawals"]
|
||||
withdrawals-processing = []
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<T: EthSpec>(
|
||||
state: &mut BeaconState<T>,
|
||||
validator_index: usize,
|
||||
|
||||
@@ -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<T: EthSpec>(
|
||||
@@ -66,8 +70,10 @@ pub fn process_epoch<T: EthSpec>(
|
||||
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.
|
||||
|
||||
@@ -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<T: EthSpec>(
|
||||
state: &mut BeaconState<T>,
|
||||
spec: &ChainSpec,
|
||||
|
||||
@@ -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<T: EthSpec>(
|
||||
state: &mut BeaconState<T>,
|
||||
spec: &ChainSpec,
|
||||
|
||||
@@ -57,8 +57,11 @@ pub fn upgrade_to_capella<E: EthSpec>(
|
||||
// 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,
|
||||
|
||||
@@ -9,6 +9,14 @@ pub fn upgrade_to_eip4844<E: EthSpec>(
|
||||
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<E: EthSpec>(
|
||||
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<E: EthSpec>(
|
||||
// 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,
|
||||
|
||||
@@ -71,3 +71,4 @@ arbitrary-fuzz = [
|
||||
"swap_or_not_shuffle/arbitrary",
|
||||
"tree_hash/arbitrary",
|
||||
]
|
||||
withdrawals = []
|
||||
|
||||
@@ -295,10 +295,13 @@ where
|
||||
pub latest_execution_payload_header: ExecutionPayloadHeaderEip4844<T>,
|
||||
|
||||
// Withdrawals
|
||||
#[cfg(feature = "withdrawals")]
|
||||
#[superstruct(only(Capella, Eip4844))]
|
||||
pub withdrawal_queue: VariableList<Withdrawal, T::WithdrawalQueueLimit>,
|
||||
#[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,
|
||||
|
||||
|
||||
@@ -80,6 +80,7 @@ pub struct ExecutionPayload<T: EthSpec> {
|
||||
pub block_hash: ExecutionBlockHash,
|
||||
#[serde(with = "ssz_types::serde_utils::list_of_hex_var_list")]
|
||||
pub transactions: Transactions<T>,
|
||||
#[cfg(feature = "withdrawals")]
|
||||
#[superstruct(only(Capella, Eip4844))]
|
||||
pub withdrawals: VariableList<Withdrawal, T::MaxWithdrawalsPerPayload>,
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ pub struct ExecutionPayloadHeader<T: EthSpec> {
|
||||
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<T: EthSpec> ExecutionPayloadHeaderMerge<T> {
|
||||
pub fn upgrade_to_capella(&self) -> ExecutionPayloadHeaderCapella<T> {
|
||||
#[cfg(feature = "withdrawals")]
|
||||
// TODO: if this is correct we should calculate and hardcode this..
|
||||
let empty_withdrawals_root =
|
||||
VariableList::<Withdrawal, T::MaxWithdrawalsPerPayload>::empty().tree_hash_root();
|
||||
@@ -122,6 +124,7 @@ impl<T: EthSpec> ExecutionPayloadHeaderMerge<T> {
|
||||
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<T: EthSpec> ExecutionPayloadHeaderCapella<T> {
|
||||
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<T: EthSpec> From<ExecutionPayloadCapella<T>> 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<T: EthSpec> From<ExecutionPayloadEip4844<T>> 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(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user