Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Electra spec changes for v1.5.0-beta.0 #6731

Merged
merged 64 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
25feedf
First pass
pawanjay176 Aug 29, 2024
4dc6e65
Add restrictions to RuntimeVariableList api
pawanjay176 Aug 30, 2024
a9cb329
Use empty_uninitialized and fix warnings
pawanjay176 Aug 30, 2024
60100fc
Fix some todos
pawanjay176 Aug 30, 2024
13f9bba
Merge branch 'unstable' into max-blobs-preset
pawanjay176 Sep 3, 2024
e71020e
Fix take impl on RuntimeFixedList
pawanjay176 Sep 4, 2024
52bb581
cleanup
pawanjay176 Sep 4, 2024
d37733b
Fix test compilations
pawanjay176 Sep 4, 2024
12c6ef1
Fix some more tests
pawanjay176 Sep 4, 2024
2fcb293
Fix test from unstable
pawanjay176 Sep 7, 2024
21ecb58
Merge branch 'unstable' into max-blobs-preset
pawanjay176 Oct 21, 2024
9d5a3af
Implement "Bugfix and more withdrawal tests"
michaelsproul Dec 19, 2024
f892849
Implement "Add missed exit checks to consolidation processing"
michaelsproul Dec 19, 2024
f27216f
Implement "Update initial earliest_exit_epoch calculation"
michaelsproul Dec 19, 2024
c31f1cc
Implement "Limit consolidating balance by validator.effective_balance"
michaelsproul Dec 20, 2024
282eefb
Implement "Use 16-bit random value in validator filter"
michaelsproul Dec 20, 2024
52e602d
Implement "Do not change creds type on consolidation"
michaelsproul Dec 20, 2024
293db28
Rename PendingPartialWithdraw index field to validator_index
eserilev Jan 2, 2025
9b8a25f
Skip slots to get test to pass and add TODO
eserilev Jan 2, 2025
23d331b
Implement "Synchronously check all transactions to have non-zero length"
eserilev Jan 2, 2025
0c2c8c4
Merge remote-tracking branch 'origin/unstable' into max-blobs-preset
michaelsproul Jan 6, 2025
de01f92
Remove footgun function
michaelsproul Jan 6, 2025
1095d60
Minor simplifications
michaelsproul Jan 6, 2025
2e86585
Move from preset to config
michaelsproul Jan 6, 2025
32483d3
Fix typo
michaelsproul Jan 6, 2025
88bedf0
Revert "Remove footgun function"
michaelsproul Jan 6, 2025
063b79c
Try fixing tests
michaelsproul Jan 6, 2025
251bca7
Implement "bump minimal preset MAX_BLOB_COMMITMENTS_PER_BLOCK and KZG…
eserilev Jan 6, 2025
e4bfe71
Thread through ChainSpec
michaelsproul Jan 6, 2025
f66e179
Fix release tests
michaelsproul Jan 6, 2025
440e854
Move RuntimeFixedVector into module and rename
michaelsproul Jan 6, 2025
04b3743
Add test
michaelsproul Jan 6, 2025
3d3bc6d
Implement "Remove post-altair `initialize_beacon_state_from_eth1` fro…
eserilev Jan 6, 2025
2dbd3b7
Update preset YAML
michaelsproul Jan 7, 2025
0cd263f
Remove empty RuntimeVarList awefullness
pawanjay176 Jan 7, 2025
3b788bf
Make max_blobs_per_block a config parameter (#6329)
michaelsproul Jan 7, 2025
7c215f8
Fix tests
pawanjay176 Jan 7, 2025
0f26408
Implement max_blobs_per_block_electra
michaelsproul Jan 7, 2025
d65e821
Fix config issues
michaelsproul Jan 7, 2025
26c409c
Simplify BlobSidecarListFromRoot
michaelsproul Jan 7, 2025
eee9218
Disable PeerDAS tests
michaelsproul Jan 7, 2025
07c039c
Merge remote-tracking branch 'origin/unstable' into max-blobs-preset
michaelsproul Jan 9, 2025
d4e152c
Bump quota to account for new target (6)
michaelsproul Jan 9, 2025
a73ecb5
Remove clone
michaelsproul Jan 9, 2025
f13bdfc
Fix issue from review
pawanjay176 Jan 9, 2025
70917f7
Try to remove ugliness
pawanjay176 Jan 10, 2025
22b7fcb
Merge branch 'unstable' into max-blobs-preset
pawanjay176 Jan 10, 2025
9e972b1
Merge remote-tracking branch 'origin/unstable' into electra-alpha10
michaelsproul Jan 10, 2025
bb59e7a
Merge commit '04b3743ec1e0b650269dd8e58b540c02430d1c0d' into electra-…
michaelsproul Jan 10, 2025
1d4dc59
Merge remote-tracking branch 'pawan/max-blobs-preset' into electra-al…
michaelsproul Jan 10, 2025
bba7310
Update tests to v1.5.0-beta.0
michaelsproul Jan 10, 2025
ef13f0f
Resolve merge conflicts
eserilev Jan 10, 2025
72bcc8a
Linting
eserilev Jan 10, 2025
344ba2b
fmt
eserilev Jan 10, 2025
a45c0f0
Fix test and add TODO
eserilev Jan 10, 2025
f4fe1b8
Gracefully handle slashed proposers in fork choice tests
michaelsproul Jan 13, 2025
1205d83
Merge remote-tracking branch 'origin/unstable' into electra-alpha10
michaelsproul Jan 13, 2025
3b17732
Keep latest changes from max_blobs_per_block PR in codec.rs
michaelsproul Jan 13, 2025
e2ff440
Revert a few more regressions and add a comment
michaelsproul Jan 13, 2025
7df6560
Disable more DAS tests
michaelsproul Jan 13, 2025
4fbca37
Improve validator monitor test a little
michaelsproul Jan 13, 2025
e821e62
Make test more robust
michaelsproul Jan 13, 2025
0b36d60
Fix sync test that didn't understand blobs
michaelsproul Jan 13, 2025
4f08ac7
Fill out cropped comment
michaelsproul Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ impl<'block, E: EthSpec> NewPayloadRequest<'block, E> {

let _timer = metrics::start_timer(&metrics::EXECUTION_LAYER_VERIFY_BLOCK_HASH);

// Check that no transactions in the payload are zero length
if payload.transactions().iter().any(|slice| slice.is_empty()) {
return Err(Error::ZeroLengthTransaction);
}

let (header_hash, rlp_transactions_root) = calculate_execution_block_hash(
payload,
parent_beacon_block_root,
Expand Down
1 change: 1 addition & 0 deletions beacon_node/execution_layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub enum Error {
payload: ExecutionBlockHash,
transactions_root: Hash256,
},
ZeroLengthTransaction,
PayloadBodiesByRangeNotSupported,
InvalidJWTSecret(String),
InvalidForkForPayload,
Expand Down
3 changes: 2 additions & 1 deletion beacon_node/lighthouse_network/src/rpc/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ pub static SIGNED_BEACON_BLOCK_DENEB_MAX: LazyLock<usize> = LazyLock::new(|| {
*SIGNED_BEACON_BLOCK_CAPELLA_MAX_WITHOUT_PAYLOAD
+ types::ExecutionPayload::<MainnetEthSpec>::max_execution_payload_deneb_size() // adding max size of execution payload (~16gb)
+ ssz::BYTES_PER_LENGTH_OFFSET // Adding the additional offsets for the `ExecutionPayload`
+ (<types::KzgCommitment as Encode>::ssz_fixed_len() * MainnetEthSpec::default_spec().max_blobs_per_block_by_fork(ForkName::Deneb) as usize)
+ ssz::BYTES_PER_LENGTH_OFFSET
}); // Length offset for the blob commitments field.
//
pub static SIGNED_BEACON_BLOCK_ELECTRA_MAX: LazyLock<usize> = LazyLock::new(|| {
*SIGNED_BEACON_BLOCK_ELECTRA_MAX_WITHOUT_PAYLOAD
+ types::ExecutionPayload::<MainnetEthSpec>::max_execution_payload_electra_size() // adding max size of execution payload (~16gb)
+ ssz::BYTES_PER_LENGTH_OFFSET // Adding the additional ssz offset for the `ExecutionPayload` field
+ (<types::KzgCommitment as Encode>::ssz_fixed_len() * MainnetEthSpec::default_spec().max_blobs_per_block_by_fork(ForkName::Electra) as usize)
+ ssz::BYTES_PER_LENGTH_OFFSET
}); // Length offset for the blob commitments field.

Expand Down Expand Up @@ -710,7 +712,6 @@ pub fn rpc_blob_limits<E: EthSpec>() -> RpcLimits {
}
}

// TODO(peerdas): fix hardcoded max here
pub fn rpc_data_column_limits<E: EthSpec>(fork_name: ForkName) -> RpcLimits {
RpcLimits::new(
DataColumnSidecar::<E>::empty().as_ssz_bytes().len(),
Expand Down
1 change: 0 additions & 1 deletion beacon_node/store/src/impls/execution_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use types::{
EthSpec, ExecutionPayload, ExecutionPayloadBellatrix, ExecutionPayloadCapella,
ExecutionPayloadDeneb, ExecutionPayloadElectra, ExecutionPayloadFulu,
};

macro_rules! impl_store_item {
($ty_name:ident) => {
impl<E: EthSpec> StoreItem for $ty_name<E> {
Expand Down
61 changes: 32 additions & 29 deletions consensus/fork_choice/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use beacon_chain::{
use fork_choice::{
ForkChoiceStore, InvalidAttestation, InvalidBlock, PayloadVerificationStatus, QueuedAttestation,
};
use state_processing::state_advance::complete_state_advance;
use std::fmt;
use std::sync::Mutex;
use std::time::Duration;
Expand Down Expand Up @@ -172,6 +173,20 @@ impl ForkChoiceTest {
let validators = self.harness.get_all_validators();
loop {
let slot = self.harness.get_current_slot();

// Skip slashed proposers, as we expect validators to get slashed in these tests.
// Presently `make_block` will panic if the proposer is slashed, so we just avoid
// calling it in this case.
complete_state_advance(&mut state, None, slot, &self.harness.spec).unwrap();
state.build_caches(&self.harness.spec).unwrap();
let proposer_index = state
.get_beacon_proposer_index(slot, &self.harness.chain.spec)
.unwrap();
if state.validators().get(proposer_index).unwrap().slashed {
self.harness.advance_slot();
continue;
}

let (block_contents, state_) = self.harness.make_block(state, slot).await;
state = state_;
if !predicate(block_contents.0.message(), &state) {
Expand All @@ -196,17 +211,20 @@ impl ForkChoiceTest {
}

/// Apply `count` blocks to the chain (with attestations).
///
/// Note that in the case of slashed validators, their proposals will be skipped and the chain
/// may be advanced by *more than* `count` slots.
pub async fn apply_blocks(self, count: usize) -> Self {
self.harness.advance_slot();
self.harness
.extend_chain(
count,
BlockStrategy::OnCanonicalHead,
AttestationStrategy::AllValidators,
)
.await;

self
// Use `Self::apply_blocks_while` which gracefully handles slashed validators.
let mut blocks_applied = 0;
self.apply_blocks_while(|_, _| {
// Blocks are applied after the predicate is called, so continue applying the block if
// less than *or equal* to the count.
blocks_applied += 1;
blocks_applied <= count
})
.await
.unwrap()
}

/// Slash a validator from the previous epoch committee.
Expand Down Expand Up @@ -244,6 +262,7 @@ impl ForkChoiceTest {

/// Apply `count` blocks to the chain (without attestations).
pub async fn apply_blocks_without_new_attestations(self, count: usize) -> Self {
// This function does not gracefully handle slashed proposers, but may need to in future.
self.harness.advance_slot();
self.harness
.extend_chain(
Expand Down Expand Up @@ -1226,14 +1245,6 @@ async fn progressive_balances_cache_attester_slashing() {
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch == 0)
.await
.unwrap()
// Note: This test may fail if the shuffling used changes, right now it re-runs with
// deterministic shuffling. A shuffling change my cause the slashed proposer to propose
// again in the next epoch, which results in a block processing failure
// (`HeaderInvalid::ProposerSlashed`). The harness should be re-worked to successfully skip
// the slot in this scenario rather than panic-ing. The same applies to
// `progressive_balances_cache_proposer_slashing`.
.apply_blocks(2)
.await
.add_previous_epoch_attester_slashing()
.await
// expect fork choice to import blocks successfully after a previous epoch attester is
Expand All @@ -1244,7 +1255,7 @@ async fn progressive_balances_cache_attester_slashing() {
// expect fork choice to import another epoch of blocks successfully - the slashed
// attester's balance should be excluded from the current epoch total balance in
// `ProgressiveBalancesCache` as well.
.apply_blocks(MainnetEthSpec::slots_per_epoch() as usize)
.apply_blocks(E::slots_per_epoch() as usize)
.await;
}

Expand All @@ -1257,15 +1268,7 @@ async fn progressive_balances_cache_proposer_slashing() {
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch == 0)
.await
.unwrap()
// Note: This test may fail if the shuffling used changes, right now it re-runs with
// deterministic shuffling. A shuffling change may cause the slashed proposer to propose
// again in the next epoch, which results in a block processing failure
// (`HeaderInvalid::ProposerSlashed`). The harness should be re-worked to successfully skip
// the slot in this scenario rather than panic-ing. The same applies to
// `progressive_balances_cache_attester_slashing`.
.apply_blocks(1)
.await
.add_previous_epoch_proposer_slashing(MainnetEthSpec::slots_per_epoch())
.add_previous_epoch_proposer_slashing(E::slots_per_epoch())
.await
// expect fork choice to import blocks successfully after a previous epoch proposer is
// slashed, i.e. the slashed proposer's balance is correctly excluded from
Expand All @@ -1275,6 +1278,6 @@ async fn progressive_balances_cache_proposer_slashing() {
// expect fork choice to import another epoch of blocks successfully - the slashed
// proposer's balance should be excluded from the current epoch total balance in
// `ProgressiveBalancesCache` as well.
.apply_blocks(MainnetEthSpec::slots_per_epoch() as usize)
.apply_blocks(E::slots_per_epoch() as usize)
.await;
}
36 changes: 23 additions & 13 deletions consensus/state_processing/src/per_block_processing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::consensus_context::ConsensusContext;
use errors::{BlockOperationError, BlockProcessingError, HeaderInvalid};
use rayon::prelude::*;
use safe_arith::{ArithError, SafeArith};
use safe_arith::{ArithError, SafeArith, SafeArithIter};
use signature_sets::{block_proposal_signature_set, get_pubkey_from_state, randao_signature_set};
use std::borrow::Cow;
use tree_hash::TreeHash;
Expand Down Expand Up @@ -509,7 +509,7 @@ pub fn compute_timestamp_at_slot<E: EthSpec>(

/// Compute the next batch of withdrawals which should be included in a block.
///
/// https://github.com/ethereum/consensus-specs/blob/dev/specs/capella/beacon-chain.md#new-get_expected_withdrawals
/// https://github.com/ethereum/consensus-specs/blob/dev/specs/electra/beacon-chain.md#new-get_expected_withdrawals
pub fn get_expected_withdrawals<E: EthSpec>(
state: &BeaconState<E>,
spec: &ChainSpec,
Expand All @@ -522,18 +522,18 @@ pub fn get_expected_withdrawals<E: EthSpec>(

// [New in Electra:EIP7251]
// Consume pending partial withdrawals
let partial_withdrawals_count =
let processed_partial_withdrawals_count =
if let Ok(partial_withdrawals) = state.pending_partial_withdrawals() {
let mut partial_withdrawals_count = 0;
let mut processed_partial_withdrawals_count = 0;
for withdrawal in partial_withdrawals {
if withdrawal.withdrawable_epoch > epoch
|| withdrawals.len() == spec.max_pending_partials_per_withdrawals_sweep as usize
{
break;
}

let withdrawal_balance = state.get_balance(withdrawal.index as usize)?;
let validator = state.get_validator(withdrawal.index as usize)?;
let withdrawal_balance = state.get_balance(withdrawal.validator_index as usize)?;
let validator = state.get_validator(withdrawal.validator_index as usize)?;

let has_sufficient_effective_balance =
validator.effective_balance >= spec.min_activation_balance;
Expand All @@ -549,17 +549,17 @@ pub fn get_expected_withdrawals<E: EthSpec>(
);
withdrawals.push(Withdrawal {
index: withdrawal_index,
validator_index: withdrawal.index,
validator_index: withdrawal.validator_index,
address: validator
.get_execution_withdrawal_address(spec)
.ok_or(BeaconStateError::NonExecutionAddresWithdrawalCredential)?,
amount: withdrawable_balance,
});
withdrawal_index.safe_add_assign(1)?;
}
partial_withdrawals_count.safe_add_assign(1)?;
processed_partial_withdrawals_count.safe_add_assign(1)?;
}
Some(partial_withdrawals_count)
Some(processed_partial_withdrawals_count)
} else {
None
};
Expand All @@ -570,9 +570,19 @@ pub fn get_expected_withdrawals<E: EthSpec>(
);
for _ in 0..bound {
let validator = state.get_validator(validator_index as usize)?;
let balance = *state.balances().get(validator_index as usize).ok_or(
BeaconStateError::BalancesOutOfBounds(validator_index as usize),
)?;
let partially_withdrawn_balance = withdrawals
.iter()
.filter_map(|withdrawal| {
(withdrawal.validator_index == validator_index).then_some(withdrawal.amount)
})
.safe_sum()?;
let balance = state
.balances()
.get(validator_index as usize)
.ok_or(BeaconStateError::BalancesOutOfBounds(
validator_index as usize,
))?
.safe_sub(partially_withdrawn_balance)?;
if validator.is_fully_withdrawable_at(balance, epoch, spec, fork_name) {
withdrawals.push(Withdrawal {
index: withdrawal_index,
Expand Down Expand Up @@ -604,7 +614,7 @@ pub fn get_expected_withdrawals<E: EthSpec>(
.safe_rem(state.validators().len() as u64)?;
}

Ok((withdrawals.into(), partial_withdrawals_count))
Ok((withdrawals.into(), processed_partial_withdrawals_count))
}

/// Apply withdrawals to the state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,11 @@ pub fn process_withdrawal_requests<E: EthSpec>(
}

// Verify pubkey exists
let Some(index) = state.pubkey_cache().get(&request.validator_pubkey) else {
let Some(validator_index) = state.pubkey_cache().get(&request.validator_pubkey) else {
continue;
};

let validator = state.get_validator(index)?;
let validator = state.get_validator(validator_index)?;
// Verify withdrawal credentials
let has_correct_credential = validator.has_execution_withdrawal_credential(spec);
let is_correct_source_address = validator
Expand Down Expand Up @@ -542,16 +542,16 @@ pub fn process_withdrawal_requests<E: EthSpec>(
continue;
}

let pending_balance_to_withdraw = state.get_pending_balance_to_withdraw(index)?;
let pending_balance_to_withdraw = state.get_pending_balance_to_withdraw(validator_index)?;
if is_full_exit_request {
// Only exit validator if it has no pending withdrawals in the queue
if pending_balance_to_withdraw == 0 {
initiate_validator_exit(state, index, spec)?
initiate_validator_exit(state, validator_index, spec)?
}
continue;
}

let balance = state.get_balance(index)?;
let balance = state.get_balance(validator_index)?;
let has_sufficient_effective_balance =
validator.effective_balance >= spec.min_activation_balance;
let has_excess_balance = balance
Expand All @@ -576,7 +576,7 @@ pub fn process_withdrawal_requests<E: EthSpec>(
state
.pending_partial_withdrawals_mut()?
.push(PendingPartialWithdrawal {
index: index as u64,
validator_index: validator_index as u64,
amount: to_withdraw,
withdrawable_epoch,
})?;
Expand Down Expand Up @@ -739,8 +739,8 @@ pub fn process_consolidation_request<E: EthSpec>(
}

let target_validator = state.get_validator(target_index)?;
// Verify the target has execution withdrawal credentials
if !target_validator.has_execution_withdrawal_credential(spec) {
// Verify the target has compounding withdrawal credentials
if !target_validator.has_compounding_withdrawal_credential(spec) {
return Ok(());
}

Expand All @@ -757,6 +757,18 @@ pub fn process_consolidation_request<E: EthSpec>(
{
return Ok(());
}
// Verify the source has been active long enough
if current_epoch
< source_validator
.activation_epoch
.safe_add(spec.shard_committee_period)?
{
return Ok(());
}
// Verify the source has no pending withdrawals in the queue
if state.get_pending_balance_to_withdraw(source_index)? > 0 {
return Ok(());
}

// Initiate source validator exit and append pending consolidation
let source_exit_epoch = state
Expand All @@ -772,10 +784,5 @@ pub fn process_consolidation_request<E: EthSpec>(
target_index: target_index as u64,
})?;

let target_validator = state.get_validator(target_index)?;
// Churn any target excess active balance of target and raise its max
if target_validator.has_eth1_withdrawal_credential(spec) {
state.switch_to_compounding_validator(target_index, spec)?;
}
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -1057,14 +1057,12 @@ fn process_pending_consolidations<E: EthSpec>(
}

// Calculate the consolidated balance
let max_effective_balance =
source_validator.get_max_effective_balance(spec, state_ctxt.fork_name);
let source_effective_balance = std::cmp::min(
*state
.balances()
.get(source_index)
.ok_or(BeaconStateError::UnknownValidator(source_index))?,
max_effective_balance,
source_validator.effective_balance,
);

// Move active balance to target. Excess balance is withdrawable.
Expand Down
4 changes: 3 additions & 1 deletion consensus/state_processing/src/upgrade/electra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ pub fn upgrade_to_electra<E: EthSpec>(
) -> Result<(), Error> {
let epoch = pre_state.current_epoch();

let activation_exit_epoch = spec.compute_activation_exit_epoch(epoch)?;
let earliest_exit_epoch = pre_state
.validators()
.iter()
.filter(|v| v.exit_epoch != spec.far_future_epoch)
.map(|v| v.exit_epoch)
.max()
.unwrap_or(epoch)
.unwrap_or(activation_exit_epoch)
.max(activation_exit_epoch)
.safe_add(1)?;

// The total active balance cache must be built before the consolidation churn limit
Expand Down
Loading
Loading