From da98ffec8d67579b3f5a7ce6d905ff9b00fd8199 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Mon, 19 Jan 2026 16:45:39 +1100 Subject: [PATCH] Add new fields to `BeaconState` to match v1.7.0-alpha.1. --- .../src/envelope_processing.rs | 9 -------- .../process_withdrawals.rs | 2 -- .../state_processing/src/upgrade/gloas.rs | 7 +++--- consensus/types/presets/mainnet/gloas.yaml | 22 +++++++++++++++++++ consensus/types/presets/minimal/gloas.yaml | 22 +++++++++++++++++++ consensus/types/src/builder/builder.rs | 22 +++++++++++++++++++ consensus/types/src/builder/mod.rs | 2 ++ consensus/types/src/core/eth_spec.rs | 9 +++++++- consensus/types/src/state/beacon_state.rs | 18 +++++++++++---- 9 files changed, 94 insertions(+), 19 deletions(-) create mode 100644 consensus/types/src/builder/builder.rs diff --git a/consensus/state_processing/src/envelope_processing.rs b/consensus/state_processing/src/envelope_processing.rs index 9ee2be3f18..0c48b7efd0 100644 --- a/consensus/state_processing/src/envelope_processing.rs +++ b/consensus/state_processing/src/envelope_processing.rs @@ -162,15 +162,6 @@ pub fn envelope_processing( }); }; - // Verify the withdrawals root - envelope_verify!( - payload.withdrawals.tree_hash_root() == *state.latest_withdrawals_root()?, - EnvelopeProcessingError::WithdrawalsRootMismatch { - state: *state.latest_withdrawals_root()?, - envelope: payload.withdrawals.tree_hash_root(), - } - ); - // Verify the gas limit envelope_verify!( payload.gas_limit == committed_bid.gas_limit, diff --git a/consensus/state_processing/src/per_block_processing/process_withdrawals.rs b/consensus/state_processing/src/per_block_processing/process_withdrawals.rs index eef365333e..ed72dd9205 100644 --- a/consensus/state_processing/src/per_block_processing/process_withdrawals.rs +++ b/consensus/state_processing/src/per_block_processing/process_withdrawals.rs @@ -130,8 +130,6 @@ pub mod gloas { let (expected_withdrawals, builder_withdrawals_count, partial_withdrawals_count) = get_expected_withdrawals(state, spec)?; - *state.latest_withdrawals_root_mut()? = expected_withdrawals.tree_hash_root(); - for withdrawal in expected_withdrawals.iter() { decrease_balance( state, diff --git a/consensus/state_processing/src/upgrade/gloas.rs b/consensus/state_processing/src/upgrade/gloas.rs index 81c0fcfe63..0dfc4fbc6d 100644 --- a/consensus/state_processing/src/upgrade/gloas.rs +++ b/consensus/state_processing/src/upgrade/gloas.rs @@ -1,4 +1,3 @@ -use bls::Hash256; use milhouse::{List, Vector}; use ssz_types::BitVector; use std::mem; @@ -88,7 +87,10 @@ pub fn upgrade_state_to_gloas( pending_deposits: pre.pending_deposits.clone(), pending_partial_withdrawals: pre.pending_partial_withdrawals.clone(), pending_consolidations: pre.pending_consolidations.clone(), + proposer_lookahead: mem::take(&mut pre.proposer_lookahead), // Gloas + builders: List::default(), + next_withdrawal_builder_index: 0, execution_payload_availability: BitVector::default(), // All bits set to false initially builder_pending_payments: Vector::new(vec![ BuilderPendingPayment::default(); @@ -96,7 +98,7 @@ pub fn upgrade_state_to_gloas( ])?, builder_pending_withdrawals: List::default(), // Empty list initially, latest_block_hash: pre.latest_execution_payload_header.block_hash, - latest_withdrawals_root: Hash256::default(), + payload_expected_withdrawals: List::default(), // Caches total_active_balance: pre.total_active_balance, progressive_balances_cache: mem::take(&mut pre.progressive_balances_cache), @@ -105,7 +107,6 @@ pub fn upgrade_state_to_gloas( exit_cache: mem::take(&mut pre.exit_cache), slashings_cache: mem::take(&mut pre.slashings_cache), epoch_cache: mem::take(&mut pre.epoch_cache), - proposer_lookahead: mem::take(&mut pre.proposer_lookahead), }); Ok(post) } diff --git a/consensus/types/presets/mainnet/gloas.yaml b/consensus/types/presets/mainnet/gloas.yaml index 45b7b8ae96..2da198dcae 100644 --- a/consensus/types/presets/mainnet/gloas.yaml +++ b/consensus/types/presets/mainnet/gloas.yaml @@ -1 +1,23 @@ # Mainnet preset - Gloas + +# Misc +# --------------------------------------------------------------- +# 2**9 (= 512) validators +PTC_SIZE: 512 + +# Max operations per block +# --------------------------------------------------------------- +# 2**2 (= 4) attestations +MAX_PAYLOAD_ATTESTATIONS: 4 + +# State list lengths +# --------------------------------------------------------------- +# 2**40 (= 1,099,511,627,776) builder spots +BUILDER_REGISTRY_LIMIT: 1099511627776 +# 2**20 (= 1,048,576) builder pending withdrawals +BUILDER_PENDING_WITHDRAWALS_LIMIT: 1048576 + +# Withdrawals processing +# --------------------------------------------------------------- +# 2**14 (= 16,384) builders +MAX_BUILDERS_PER_WITHDRAWALS_SWEEP: 16384 \ No newline at end of file diff --git a/consensus/types/presets/minimal/gloas.yaml b/consensus/types/presets/minimal/gloas.yaml index 51b3f04857..7ae61ddf97 100644 --- a/consensus/types/presets/minimal/gloas.yaml +++ b/consensus/types/presets/minimal/gloas.yaml @@ -1 +1,23 @@ # Minimal preset - Gloas + +# Misc +# --------------------------------------------------------------- +# [customized] 2**1 (= 2) validators +PTC_SIZE: 2 + +# Max operations per block +# --------------------------------------------------------------- +# 2**2 (= 4) attestations +MAX_PAYLOAD_ATTESTATIONS: 4 + +# State list lengths +# --------------------------------------------------------------- +# 2**40 (= 1,099,511,627,776) builder spots +BUILDER_REGISTRY_LIMIT: 1099511627776 +# 2**20 (= 1,048,576) builder pending withdrawals +BUILDER_PENDING_WITHDRAWALS_LIMIT: 1048576 + +# Withdrawals processing +# --------------------------------------------------------------- +# [customized] 2**4 (= 16) builders +MAX_BUILDERS_PER_WITHDRAWALS_SWEEP: 16 diff --git a/consensus/types/src/builder/builder.rs b/consensus/types/src/builder/builder.rs new file mode 100644 index 0000000000..54891cd8d8 --- /dev/null +++ b/consensus/types/src/builder/builder.rs @@ -0,0 +1,22 @@ +use crate::test_utils::TestRandom; +use crate::{Address, Epoch}; +use bls::PublicKeyBytes; +use serde::{Deserialize, Serialize}; +use ssz_derive::{Decode, Encode}; +use test_random_derive::TestRandom; +use tree_hash_derive::TreeHash; + +pub type BuilderIndex = u64; + +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] +#[derive( + Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Encode, Decode, TestRandom, TreeHash, +)] +pub struct Builder { + pub pubkey: PublicKeyBytes, + pub version: u8, + pub execution_address: Address, + pub balance: u64, + pub deposit_epoch: Epoch, + pub withdrawable_epoch: Epoch, +} diff --git a/consensus/types/src/builder/mod.rs b/consensus/types/src/builder/mod.rs index 54d0ae4eb7..f4e0e346f2 100644 --- a/consensus/types/src/builder/mod.rs +++ b/consensus/types/src/builder/mod.rs @@ -1,7 +1,9 @@ +mod builder; mod builder_bid; mod builder_pending_payment; mod builder_pending_withdrawal; +pub use builder::{Builder, BuilderIndex}; pub use builder_bid::{ BuilderBid, BuilderBidBellatrix, BuilderBidCapella, BuilderBidDeneb, BuilderBidElectra, BuilderBidFulu, SignedBuilderBid, diff --git a/consensus/types/src/core/eth_spec.rs b/consensus/types/src/core/eth_spec.rs index 2983fc2c62..ac20c1abdf 100644 --- a/consensus/types/src/core/eth_spec.rs +++ b/consensus/types/src/core/eth_spec.rs @@ -122,6 +122,10 @@ pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq + type CellsPerExtBlob: Unsigned + Clone + Sync + Send + Debug + PartialEq; type NumberOfColumns: Unsigned + Clone + Sync + Send + Debug + PartialEq; type ProposerLookaheadSlots: Unsigned + Clone + Sync + Send + Debug + PartialEq; + /* + * New in Gloas + */ + type BuilderRegistryLimit: Unsigned + Clone + Sync + Send + Debug + PartialEq; /* * Derived values (set these CAREFULLY) */ @@ -484,6 +488,7 @@ impl EthSpec for MainnetEthSpec { type CellsPerExtBlob = U128; type NumberOfColumns = U128; type ProposerLookaheadSlots = U64; // Derived from (MIN_SEED_LOOKAHEAD + 1) * SLOTS_PER_EPOCH + type BuilderRegistryLimit = U1099511627776; type SyncSubcommitteeSize = U128; // 512 committee size / 4 sync committee subnet count type MaxPendingAttestations = U4096; // 128 max attestations * 32 slots per epoch type SlotsPerEth1VotingPeriod = U2048; // 64 epochs * 32 slots per epoch @@ -574,7 +579,8 @@ impl EthSpec for MinimalEthSpec { MaxDepositRequestsPerPayload, MaxWithdrawalRequestsPerPayload, PTCSize, - MaxPayloadAttestations + MaxPayloadAttestations, + BuilderRegistryLimit }); fn default_spec() -> ChainSpec { @@ -647,6 +653,7 @@ impl EthSpec for GnosisEthSpec { type CellsPerExtBlob = U128; type NumberOfColumns = U128; type ProposerLookaheadSlots = U32; // Derived from (MIN_SEED_LOOKAHEAD + 1) * SLOTS_PER_EPOCH + type BuilderRegistryLimit = U1099511627776; type PTCSize = U512; type MaxPayloadAttestations = U2; diff --git a/consensus/types/src/state/beacon_state.rs b/consensus/types/src/state/beacon_state.rs index 7a872170d0..0416e066c5 100644 --- a/consensus/types/src/state/beacon_state.rs +++ b/consensus/types/src/state/beacon_state.rs @@ -23,7 +23,8 @@ use tree_hash_derive::TreeHash; use typenum::Unsigned; use crate::{ - BuilderPendingPayment, BuilderPendingWithdrawal, ExecutionBlockHash, ExecutionPayloadBid, + Builder, BuilderIndex, BuilderPendingPayment, BuilderPendingWithdrawal, ExecutionBlockHash, + ExecutionPayloadBid, Withdrawal, attestation::{ AttestationData, AttestationDuty, BeaconCommittee, Checkpoint, CommitteeIndex, PTC, ParticipationFlags, PendingAttestation, @@ -608,8 +609,17 @@ where #[superstruct(only(Fulu, Gloas))] #[serde(with = "ssz_types::serde_utils::quoted_u64_fixed_vec")] pub proposer_lookahead: Vector, - // Gloas + #[compare_fields(as_iter)] + #[test_random(default)] + #[superstruct(only(Gloas))] + pub builders: List, + + #[metastruct(exclude_from(tree_lists))] + #[serde(with = "serde_utils::quoted_u64")] + #[superstruct(only(Gloas), partial_getter(copy))] + pub next_withdrawal_builder_index: BuilderIndex, + #[test_random(default)] #[superstruct(only(Gloas))] #[metastruct(exclude_from(tree_lists))] @@ -631,10 +641,10 @@ where #[metastruct(exclude_from(tree_lists))] pub latest_block_hash: ExecutionBlockHash, + #[compare_fields(as_iter)] #[test_random(default)] #[superstruct(only(Gloas))] - #[metastruct(exclude_from(tree_lists))] - pub latest_withdrawals_root: Hash256, + pub payload_expected_withdrawals: List, // Caching (not in the spec) #[serde(skip_serializing, skip_deserializing)]