mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 13:28:33 +00:00
Electra spec changes for v1.5.0-beta.0 (#6731)
* First pass * Add restrictions to RuntimeVariableList api * Use empty_uninitialized and fix warnings * Fix some todos * Merge branch 'unstable' into max-blobs-preset * Fix take impl on RuntimeFixedList * cleanup * Fix test compilations * Fix some more tests * Fix test from unstable * Merge branch 'unstable' into max-blobs-preset * Implement "Bugfix and more withdrawal tests" * Implement "Add missed exit checks to consolidation processing" * Implement "Update initial earliest_exit_epoch calculation" * Implement "Limit consolidating balance by validator.effective_balance" * Implement "Use 16-bit random value in validator filter" * Implement "Do not change creds type on consolidation" * Rename PendingPartialWithdraw index field to validator_index * Skip slots to get test to pass and add TODO * Implement "Synchronously check all transactions to have non-zero length" * Merge remote-tracking branch 'origin/unstable' into max-blobs-preset * Remove footgun function * Minor simplifications * Move from preset to config * Fix typo * Revert "Remove footgun function" This reverts commitde01f923c7. * Try fixing tests * Implement "bump minimal preset MAX_BLOB_COMMITMENTS_PER_BLOCK and KZG_COMMITMENT_INCLUSION_PROOF_DEPTH" * Thread through ChainSpec * Fix release tests * Move RuntimeFixedVector into module and rename * Add test * Implement "Remove post-altair `initialize_beacon_state_from_eth1` from specs" * Update preset YAML * Remove empty RuntimeVarList awefullness * Make max_blobs_per_block a config parameter (#6329) Squashed commit of the following: commit04b3743ec1Author: Michael Sproul <michael@sigmaprime.io> Date: Mon Jan 6 17:36:58 2025 +1100 Add test commit440e854199Author: Michael Sproul <michael@sigmaprime.io> Date: Mon Jan 6 17:24:50 2025 +1100 Move RuntimeFixedVector into module and rename commitf66e179a40Author: Michael Sproul <michael@sigmaprime.io> Date: Mon Jan 6 17:17:17 2025 +1100 Fix release tests commite4bfe71cd1Author: Michael Sproul <michael@sigmaprime.io> Date: Mon Jan 6 17:05:30 2025 +1100 Thread through ChainSpec commit063b79c16aAuthor: Michael Sproul <michael@sigmaprime.io> Date: Mon Jan 6 15:32:16 2025 +1100 Try fixing tests commit88bedf09bcAuthor: Michael Sproul <michael@sigmaprime.io> Date: Mon Jan 6 15:04:37 2025 +1100 Revert "Remove footgun function" This reverts commitde01f923c7. commit32483d385bAuthor: Michael Sproul <michael@sigmaprime.io> Date: Mon Jan 6 15:04:32 2025 +1100 Fix typo commit2e86585b47Author: Michael Sproul <michael@sigmaprime.io> Date: Mon Jan 6 15:04:15 2025 +1100 Move from preset to config commit1095d60a40Author: Michael Sproul <michael@sigmaprime.io> Date: Mon Jan 6 14:38:40 2025 +1100 Minor simplifications commitde01f923c7Author: Michael Sproul <michael@sigmaprime.io> Date: Mon Jan 6 14:06:57 2025 +1100 Remove footgun function commit0c2c8c4224Merge:21ecb58fff51a292f7Author: Michael Sproul <michael@sigmaprime.io> Date: Mon Jan 6 14:02:50 2025 +1100 Merge remote-tracking branch 'origin/unstable' into max-blobs-preset commitf51a292f77Author: Daniel Knopik <107140945+dknopik@users.noreply.github.com> Date: Fri Jan 3 20:27:21 2025 +0100 fully lint only explicitly to avoid unnecessary rebuilds (#6753) * fully lint only explicitly to avoid unnecessary rebuilds commit7e0cddef32Author: Akihito Nakano <sora.akatsuki@gmail.com> Date: Tue Dec 24 10:38:56 2024 +0900 Make sure we have fanout peers when publish (#6738) * Ensure that `fanout_peers` is always non-empty if it's `Some` commit21ecb58ff8Merge:2fcb2935e9aefb5539Author: Pawan Dhananjay <pawandhananjay@gmail.com> Date: Mon Oct 21 14:46:00 2024 -0700 Merge branch 'unstable' into max-blobs-preset commit2fcb2935ecAuthor: Pawan Dhananjay <pawandhananjay@gmail.com> Date: Fri Sep 6 18:28:31 2024 -0700 Fix test from unstable commit12c6ef118aAuthor: Pawan Dhananjay <pawandhananjay@gmail.com> Date: Wed Sep 4 16:16:36 2024 -0700 Fix some more tests commitd37733b846Author: Pawan Dhananjay <pawandhananjay@gmail.com> Date: Wed Sep 4 12:47:36 2024 -0700 Fix test compilations commit52bb581e07Author: Pawan Dhananjay <pawandhananjay@gmail.com> Date: Tue Sep 3 18:38:19 2024 -0700 cleanup commite71020e3e6Author: Pawan Dhananjay <pawandhananjay@gmail.com> Date: Tue Sep 3 17:16:10 2024 -0700 Fix take impl on RuntimeFixedList commit13f9bba647Merge:60100fc6b4e675cf5dAuthor: Pawan Dhananjay <pawandhananjay@gmail.com> Date: Tue Sep 3 16:08:59 2024 -0700 Merge branch 'unstable' into max-blobs-preset commit60100fc6beAuthor: Pawan Dhananjay <pawandhananjay@gmail.com> Date: Fri Aug 30 16:04:11 2024 -0700 Fix some todos commita9cb329a22Author: Pawan Dhananjay <pawandhananjay@gmail.com> Date: Fri Aug 30 15:54:00 2024 -0700 Use empty_uninitialized and fix warnings commit4dc6e6515eAuthor: Pawan Dhananjay <pawandhananjay@gmail.com> Date: Fri Aug 30 15:53:18 2024 -0700 Add restrictions to RuntimeVariableList api commit25feedfde3Author: Pawan Dhananjay <pawandhananjay@gmail.com> Date: Thu Aug 29 16:11:19 2024 -0700 First pass * Fix tests * Implement max_blobs_per_block_electra * Fix config issues * Simplify BlobSidecarListFromRoot * Disable PeerDAS tests * Merge remote-tracking branch 'origin/unstable' into max-blobs-preset * Bump quota to account for new target (6) * Remove clone * Fix issue from review * Try to remove ugliness * Merge branch 'unstable' into max-blobs-preset * Merge remote-tracking branch 'origin/unstable' into electra-alpha10 * Merge commit '04b3743ec1e0b650269dd8e58b540c02430d1c0d' into electra-alpha10 * Merge remote-tracking branch 'pawan/max-blobs-preset' into electra-alpha10 * Update tests to v1.5.0-beta.0 * Resolve merge conflicts * Linting * fmt * Fix test and add TODO * Gracefully handle slashed proposers in fork choice tests * Merge remote-tracking branch 'origin/unstable' into electra-alpha10 * Keep latest changes from max_blobs_per_block PR in codec.rs * Revert a few more regressions and add a comment * Disable more DAS tests * Improve validator monitor test a little * Make test more robust * Fix sync test that didn't understand blobs * Fill out cropped comment
This commit is contained in:
@@ -46,6 +46,7 @@ mod tests;
|
||||
|
||||
pub const CACHED_EPOCHS: usize = 3;
|
||||
const MAX_RANDOM_BYTE: u64 = (1 << 8) - 1;
|
||||
const MAX_RANDOM_VALUE: u64 = (1 << 16) - 1;
|
||||
|
||||
pub type Validators<E> = List<Validator, <E as EthSpec>::ValidatorRegistryLimit>;
|
||||
pub type Balances<E> = List<u64, <E as EthSpec>::ValidatorRegistryLimit>;
|
||||
@@ -916,6 +917,11 @@ impl<E: EthSpec> BeaconState<E> {
|
||||
}
|
||||
|
||||
let max_effective_balance = spec.max_effective_balance_for_fork(self.fork_name_unchecked());
|
||||
let max_random_value = if self.fork_name_unchecked().electra_enabled() {
|
||||
MAX_RANDOM_VALUE
|
||||
} else {
|
||||
MAX_RANDOM_BYTE
|
||||
};
|
||||
|
||||
let mut i = 0;
|
||||
loop {
|
||||
@@ -929,10 +935,10 @@ impl<E: EthSpec> BeaconState<E> {
|
||||
let candidate_index = *indices
|
||||
.get(shuffled_index)
|
||||
.ok_or(Error::ShuffleIndexOutOfBounds(shuffled_index))?;
|
||||
let random_byte = Self::shuffling_random_byte(i, seed)?;
|
||||
let random_value = self.shuffling_random_value(i, seed)?;
|
||||
let effective_balance = self.get_effective_balance(candidate_index)?;
|
||||
if effective_balance.safe_mul(MAX_RANDOM_BYTE)?
|
||||
>= max_effective_balance.safe_mul(u64::from(random_byte))?
|
||||
if effective_balance.safe_mul(max_random_value)?
|
||||
>= max_effective_balance.safe_mul(random_value)?
|
||||
{
|
||||
return Ok(candidate_index);
|
||||
}
|
||||
@@ -940,6 +946,19 @@ impl<E: EthSpec> BeaconState<E> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Fork-aware abstraction for the shuffling.
|
||||
///
|
||||
/// In Electra and later, the random value is a 16-bit integer stored in a `u64`.
|
||||
///
|
||||
/// Prior to Electra, the random value is an 8-bit integer stored in a `u64`.
|
||||
fn shuffling_random_value(&self, i: usize, seed: &[u8]) -> Result<u64, Error> {
|
||||
if self.fork_name_unchecked().electra_enabled() {
|
||||
Self::shuffling_random_u16_electra(i, seed).map(u64::from)
|
||||
} else {
|
||||
Self::shuffling_random_byte(i, seed).map(u64::from)
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a random byte from the given `seed`.
|
||||
///
|
||||
/// Used by the proposer & sync committee selection functions.
|
||||
@@ -953,6 +972,21 @@ impl<E: EthSpec> BeaconState<E> {
|
||||
.ok_or(Error::ShuffleIndexOutOfBounds(index))
|
||||
}
|
||||
|
||||
/// Get two random bytes from the given `seed`.
|
||||
///
|
||||
/// This is used in place of `shuffling_random_byte` from Electra onwards.
|
||||
fn shuffling_random_u16_electra(i: usize, seed: &[u8]) -> Result<u16, Error> {
|
||||
let mut preimage = seed.to_vec();
|
||||
preimage.append(&mut int_to_bytes8(i.safe_div(16)? as u64));
|
||||
let offset = i.safe_rem(16)?.safe_mul(2)?;
|
||||
hash(&preimage)
|
||||
.get(offset..offset.safe_add(2)?)
|
||||
.ok_or(Error::ShuffleIndexOutOfBounds(offset))?
|
||||
.try_into()
|
||||
.map(u16::from_le_bytes)
|
||||
.map_err(|_| Error::ShuffleIndexOutOfBounds(offset))
|
||||
}
|
||||
|
||||
/// Convenience accessor for the `execution_payload_header` as an `ExecutionPayloadHeaderRef`.
|
||||
pub fn latest_execution_payload_header(&self) -> Result<ExecutionPayloadHeaderRef<E>, Error> {
|
||||
match self {
|
||||
@@ -1120,6 +1154,11 @@ impl<E: EthSpec> BeaconState<E> {
|
||||
|
||||
let seed = self.get_seed(epoch, Domain::SyncCommittee, spec)?;
|
||||
let max_effective_balance = spec.max_effective_balance_for_fork(self.fork_name_unchecked());
|
||||
let max_random_value = if self.fork_name_unchecked().electra_enabled() {
|
||||
MAX_RANDOM_VALUE
|
||||
} else {
|
||||
MAX_RANDOM_BYTE
|
||||
};
|
||||
|
||||
let mut i = 0;
|
||||
let mut sync_committee_indices = Vec::with_capacity(E::SyncCommitteeSize::to_usize());
|
||||
@@ -1134,10 +1173,10 @@ impl<E: EthSpec> BeaconState<E> {
|
||||
let candidate_index = *active_validator_indices
|
||||
.get(shuffled_index)
|
||||
.ok_or(Error::ShuffleIndexOutOfBounds(shuffled_index))?;
|
||||
let random_byte = Self::shuffling_random_byte(i, seed.as_slice())?;
|
||||
let random_value = self.shuffling_random_value(i, seed.as_slice())?;
|
||||
let effective_balance = self.get_validator(candidate_index)?.effective_balance;
|
||||
if effective_balance.safe_mul(MAX_RANDOM_BYTE)?
|
||||
>= max_effective_balance.safe_mul(u64::from(random_byte))?
|
||||
if effective_balance.safe_mul(max_random_value)?
|
||||
>= max_effective_balance.safe_mul(random_value)?
|
||||
{
|
||||
sync_committee_indices.push(candidate_index);
|
||||
}
|
||||
@@ -2205,7 +2244,7 @@ impl<E: EthSpec> BeaconState<E> {
|
||||
for withdrawal in self
|
||||
.pending_partial_withdrawals()?
|
||||
.iter()
|
||||
.filter(|withdrawal| withdrawal.index as usize == validator_index)
|
||||
.filter(|withdrawal| withdrawal.validator_index as usize == validator_index)
|
||||
{
|
||||
pending_balance.safe_add_assign(withdrawal.amount)?;
|
||||
}
|
||||
|
||||
@@ -191,6 +191,7 @@ pub struct ChainSpec {
|
||||
pub max_pending_partials_per_withdrawals_sweep: u64,
|
||||
pub min_per_epoch_churn_limit_electra: u64,
|
||||
pub max_per_epoch_activation_exit_churn_limit: u64,
|
||||
pub max_blobs_per_block_electra: u64,
|
||||
|
||||
/*
|
||||
* Fulu hard fork params
|
||||
@@ -623,9 +624,12 @@ impl ChainSpec {
|
||||
}
|
||||
|
||||
/// Return the value of `MAX_BLOBS_PER_BLOCK` appropriate for `fork`.
|
||||
pub fn max_blobs_per_block_by_fork(&self, _fork_name: ForkName) -> u64 {
|
||||
// TODO(electra): add Electra blobs per block change here
|
||||
self.max_blobs_per_block
|
||||
pub fn max_blobs_per_block_by_fork(&self, fork_name: ForkName) -> u64 {
|
||||
if fork_name.electra_enabled() {
|
||||
self.max_blobs_per_block_electra
|
||||
} else {
|
||||
self.max_blobs_per_block
|
||||
}
|
||||
}
|
||||
|
||||
pub fn data_columns_per_subnet(&self) -> usize {
|
||||
@@ -826,6 +830,7 @@ impl ChainSpec {
|
||||
u64::checked_pow(2, 8)?.checked_mul(u64::checked_pow(10, 9)?)
|
||||
})
|
||||
.expect("calculation does not overflow"),
|
||||
max_blobs_per_block_electra: default_max_blobs_per_block_electra(),
|
||||
|
||||
/*
|
||||
* Fulu hard fork params
|
||||
@@ -940,7 +945,7 @@ impl ChainSpec {
|
||||
// Electra
|
||||
electra_fork_version: [0x05, 0x00, 0x00, 0x01],
|
||||
electra_fork_epoch: None,
|
||||
max_pending_partials_per_withdrawals_sweep: u64::checked_pow(2, 0)
|
||||
max_pending_partials_per_withdrawals_sweep: u64::checked_pow(2, 1)
|
||||
.expect("pow does not overflow"),
|
||||
min_per_epoch_churn_limit_electra: option_wrapper(|| {
|
||||
u64::checked_pow(2, 6)?.checked_mul(u64::checked_pow(10, 9)?)
|
||||
@@ -1156,6 +1161,7 @@ impl ChainSpec {
|
||||
u64::checked_pow(2, 8)?.checked_mul(u64::checked_pow(10, 9)?)
|
||||
})
|
||||
.expect("calculation does not overflow"),
|
||||
max_blobs_per_block_electra: default_max_blobs_per_block_electra(),
|
||||
|
||||
/*
|
||||
* Fulu hard fork params
|
||||
@@ -1412,6 +1418,9 @@ pub struct Config {
|
||||
#[serde(default = "default_max_per_epoch_activation_exit_churn_limit")]
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
max_per_epoch_activation_exit_churn_limit: u64,
|
||||
#[serde(default = "default_max_blobs_per_block_electra")]
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
max_blobs_per_block_electra: u64,
|
||||
|
||||
#[serde(default = "default_custody_requirement")]
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
@@ -1554,6 +1563,10 @@ const fn default_max_per_epoch_activation_exit_churn_limit() -> u64 {
|
||||
256_000_000_000
|
||||
}
|
||||
|
||||
const fn default_max_blobs_per_block_electra() -> u64 {
|
||||
9
|
||||
}
|
||||
|
||||
const fn default_attestation_propagation_slot_range() -> u64 {
|
||||
32
|
||||
}
|
||||
@@ -1773,6 +1786,7 @@ impl Config {
|
||||
min_per_epoch_churn_limit_electra: spec.min_per_epoch_churn_limit_electra,
|
||||
max_per_epoch_activation_exit_churn_limit: spec
|
||||
.max_per_epoch_activation_exit_churn_limit,
|
||||
max_blobs_per_block_electra: spec.max_blobs_per_block_electra,
|
||||
|
||||
custody_requirement: spec.custody_requirement,
|
||||
data_column_sidecar_subnet_count: spec.data_column_sidecar_subnet_count,
|
||||
@@ -1850,6 +1864,7 @@ impl Config {
|
||||
|
||||
min_per_epoch_churn_limit_electra,
|
||||
max_per_epoch_activation_exit_churn_limit,
|
||||
max_blobs_per_block_electra,
|
||||
custody_requirement,
|
||||
data_column_sidecar_subnet_count,
|
||||
number_of_columns,
|
||||
@@ -1919,6 +1934,7 @@ impl Config {
|
||||
|
||||
min_per_epoch_churn_limit_electra,
|
||||
max_per_epoch_activation_exit_churn_limit,
|
||||
max_blobs_per_block_electra,
|
||||
|
||||
// We need to re-derive any values that might have changed in the config.
|
||||
max_blocks_by_root_request: max_blocks_by_root_request_common(max_request_blocks),
|
||||
|
||||
@@ -3,10 +3,10 @@ use crate::*;
|
||||
use safe_arith::SafeArith;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ssz_types::typenum::{
|
||||
bit::B0, UInt, U0, U1, U1024, U1048576, U1073741824, U1099511627776, U128, U131072, U134217728,
|
||||
U16, U16777216, U2, U2048, U256, U262144, U32, U4, U4096, U512, U625, U64, U65536, U8, U8192,
|
||||
bit::B0, UInt, U0, U1, U10, U1024, U1048576, U1073741824, U1099511627776, U128, U131072,
|
||||
U134217728, U16, U16777216, U17, U2, U2048, U256, U262144, U32, U4, U4096, U512, U625, U64,
|
||||
U65536, U8, U8192,
|
||||
};
|
||||
use ssz_types::typenum::{U17, U9};
|
||||
use std::fmt::{self, Debug};
|
||||
use std::str::FromStr;
|
||||
|
||||
@@ -431,7 +431,7 @@ impl EthSpec for MainnetEthSpec {
|
||||
type PendingDepositsLimit = U134217728;
|
||||
type PendingPartialWithdrawalsLimit = U134217728;
|
||||
type PendingConsolidationsLimit = U262144;
|
||||
type MaxConsolidationRequestsPerPayload = U1;
|
||||
type MaxConsolidationRequestsPerPayload = U2;
|
||||
type MaxDepositRequestsPerPayload = U8192;
|
||||
type MaxAttesterSlashingsElectra = U1;
|
||||
type MaxAttestationsElectra = U8;
|
||||
@@ -466,8 +466,8 @@ impl EthSpec for MinimalEthSpec {
|
||||
type MaxWithdrawalsPerPayload = U4;
|
||||
type FieldElementsPerBlob = U4096;
|
||||
type BytesPerBlob = U131072;
|
||||
type MaxBlobCommitmentsPerBlock = U16;
|
||||
type KzgCommitmentInclusionProofDepth = U9;
|
||||
type MaxBlobCommitmentsPerBlock = U32;
|
||||
type KzgCommitmentInclusionProofDepth = U10;
|
||||
type PendingPartialWithdrawalsLimit = U64;
|
||||
type PendingConsolidationsLimit = U64;
|
||||
type MaxDepositRequestsPerPayload = U4;
|
||||
@@ -558,7 +558,7 @@ impl EthSpec for GnosisEthSpec {
|
||||
type PendingDepositsLimit = U134217728;
|
||||
type PendingPartialWithdrawalsLimit = U134217728;
|
||||
type PendingConsolidationsLimit = U262144;
|
||||
type MaxConsolidationRequestsPerPayload = U1;
|
||||
type MaxConsolidationRequestsPerPayload = U2;
|
||||
type MaxDepositRequestsPerPayload = U8192;
|
||||
type MaxAttesterSlashingsElectra = U1;
|
||||
type MaxAttestationsElectra = U8;
|
||||
|
||||
@@ -21,7 +21,7 @@ use tree_hash_derive::TreeHash;
|
||||
)]
|
||||
pub struct PendingPartialWithdrawal {
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub index: u64,
|
||||
pub validator_index: u64,
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub amount: u64,
|
||||
pub withdrawable_epoch: Epoch,
|
||||
|
||||
@@ -234,7 +234,7 @@ pub struct ElectraPreset {
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub max_pending_partials_per_withdrawals_sweep: u64,
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub pending_balance_deposits_limit: u64,
|
||||
pub pending_deposits_limit: u64,
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub pending_partial_withdrawals_limit: u64,
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
@@ -260,7 +260,7 @@ impl ElectraPreset {
|
||||
whistleblower_reward_quotient_electra: spec.whistleblower_reward_quotient_electra,
|
||||
max_pending_partials_per_withdrawals_sweep: spec
|
||||
.max_pending_partials_per_withdrawals_sweep,
|
||||
pending_balance_deposits_limit: E::pending_deposits_limit() as u64,
|
||||
pending_deposits_limit: E::pending_deposits_limit() as u64,
|
||||
pending_partial_withdrawals_limit: E::pending_partial_withdrawals_limit() as u64,
|
||||
pending_consolidations_limit: E::pending_consolidations_limit() as u64,
|
||||
max_consolidation_requests_per_payload: E::max_consolidation_requests_per_payload()
|
||||
|
||||
Reference in New Issue
Block a user