Feature gate withdrawals (#3684)

* start feature gating

* feature gate withdrawals
This commit is contained in:
realbigsean
2022-11-04 16:50:26 -04:00
committed by GitHub
parent 1aec17b09c
commit fc0b06a039
24 changed files with 144 additions and 12 deletions

View File

@@ -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;

View File

@@ -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,

View File

@@ -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.

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,