Queue deposit requests and apply them during epoch processing

This commit is contained in:
Pawan Dhananjay
2024-10-11 17:56:30 -07:00
parent 0a4e6be223
commit c0cac0e2cd
14 changed files with 284 additions and 128 deletions

View File

@@ -510,7 +510,7 @@ where
#[compare_fields(as_iter)]
#[test_random(default)]
#[superstruct(only(Electra))]
pub pending_balance_deposits: List<PendingBalanceDeposit, E::PendingBalanceDepositsLimit>,
pub pending_deposits: List<PendingDeposit, E::PendingDepositsLimit>,
#[compare_fields(as_iter)]
#[test_random(default)]
#[superstruct(only(Electra))]
@@ -2147,11 +2147,14 @@ impl<E: EthSpec> BeaconState<E> {
if *balance > spec.min_activation_balance {
let excess_balance = balance.safe_sub(spec.min_activation_balance)?;
*balance = spec.min_activation_balance;
self.pending_balance_deposits_mut()?
.push(PendingBalanceDeposit {
index: validator_index as u64,
amount: excess_balance,
})?;
let validator = self.get_validator(validator_index)?.clone();
self.pending_deposits_mut()?.push(PendingDeposit {
pubkey: validator.pubkey,
withdrawal_credentials: validator.withdrawal_credentials,
amount: excess_balance,
signature: Signature::infinity()?,
slot: spec.genesis_slot,
})?;
}
Ok(())
}

View File

@@ -151,7 +151,7 @@ pub trait EthSpec:
/*
* New in Electra
*/
type PendingBalanceDepositsLimit: Unsigned + Clone + Sync + Send + Debug + PartialEq;
type PendingDepositsLimit: Unsigned + Clone + Sync + Send + Debug + PartialEq;
type PendingPartialWithdrawalsLimit: Unsigned + Clone + Sync + Send + Debug + PartialEq;
type PendingConsolidationsLimit: Unsigned + Clone + Sync + Send + Debug + PartialEq;
type MaxConsolidationRequestsPerPayload: Unsigned + Clone + Sync + Send + Debug + PartialEq;
@@ -159,6 +159,7 @@ pub trait EthSpec:
type MaxAttesterSlashingsElectra: Unsigned + Clone + Sync + Send + Debug + PartialEq;
type MaxAttestationsElectra: Unsigned + Clone + Sync + Send + Debug + PartialEq;
type MaxWithdrawalRequestsPerPayload: Unsigned + Clone + Sync + Send + Debug + PartialEq;
type MaxPendingDepositsPerEpoch: Unsigned + Clone + Sync + Send + Debug + PartialEq;
fn default_spec() -> ChainSpec;
@@ -331,9 +332,9 @@ pub trait EthSpec:
.expect("Preset values are not configurable and never result in non-positive block body depth")
}
/// Returns the `PENDING_BALANCE_DEPOSITS_LIMIT` constant for this specification.
fn pending_balance_deposits_limit() -> usize {
Self::PendingBalanceDepositsLimit::to_usize()
/// Returns the `PENDING_DEPOSITS_LIMIT` constant for this specification.
fn pending_deposits_limit() -> usize {
Self::PendingDepositsLimit::to_usize()
}
/// Returns the `PENDING_PARTIAL_WITHDRAWALS_LIMIT` constant for this specification.
@@ -371,6 +372,11 @@ pub trait EthSpec:
Self::MaxWithdrawalRequestsPerPayload::to_usize()
}
/// Returns the `MAX_PENDING_DEPOSITS_PER_EPOCH` constant for this specification.
fn max_pending_deposits_per_epoch() -> usize {
Self::MaxPendingDepositsPerEpoch::to_usize()
}
fn kzg_commitments_inclusion_proof_depth() -> usize {
Self::KzgCommitmentsInclusionProofDepth::to_usize()
}
@@ -430,7 +436,7 @@ impl EthSpec for MainnetEthSpec {
type SlotsPerEth1VotingPeriod = U2048; // 64 epochs * 32 slots per epoch
type MaxBlsToExecutionChanges = U16;
type MaxWithdrawalsPerPayload = U16;
type PendingBalanceDepositsLimit = U134217728;
type PendingDepositsLimit = U134217728;
type PendingPartialWithdrawalsLimit = U134217728;
type PendingConsolidationsLimit = U262144;
type MaxConsolidationRequestsPerPayload = U1;
@@ -438,6 +444,7 @@ impl EthSpec for MainnetEthSpec {
type MaxAttesterSlashingsElectra = U1;
type MaxAttestationsElectra = U8;
type MaxWithdrawalRequestsPerPayload = U16;
type MaxPendingDepositsPerEpoch = U16;
fn default_spec() -> ChainSpec {
ChainSpec::mainnet()
@@ -500,7 +507,8 @@ impl EthSpec for MinimalEthSpec {
MaxBlsToExecutionChanges,
MaxBlobsPerBlock,
BytesPerFieldElement,
PendingBalanceDepositsLimit,
PendingDepositsLimit,
MaxPendingDepositsPerEpoch,
MaxConsolidationRequestsPerPayload,
MaxAttesterSlashingsElectra,
MaxAttestationsElectra
@@ -557,7 +565,7 @@ impl EthSpec for GnosisEthSpec {
type BytesPerFieldElement = U32;
type BytesPerBlob = U131072;
type KzgCommitmentInclusionProofDepth = U17;
type PendingBalanceDepositsLimit = U134217728;
type PendingDepositsLimit = U134217728;
type PendingPartialWithdrawalsLimit = U134217728;
type PendingConsolidationsLimit = U262144;
type MaxConsolidationRequestsPerPayload = U1;
@@ -565,6 +573,7 @@ impl EthSpec for GnosisEthSpec {
type MaxAttesterSlashingsElectra = U1;
type MaxAttestationsElectra = U8;
type MaxWithdrawalRequestsPerPayload = U16;
type MaxPendingDepositsPerEpoch = U16;
type FieldElementsPerCell = U64;
type FieldElementsPerExtBlob = U8192;
type BytesPerCell = U2048;

View File

@@ -54,8 +54,8 @@ pub mod light_client_finality_update;
pub mod light_client_optimistic_update;
pub mod light_client_update;
pub mod pending_attestation;
pub mod pending_balance_deposit;
pub mod pending_consolidation;
pub mod pending_deposit;
pub mod pending_partial_withdrawal;
pub mod proposer_preparation_data;
pub mod proposer_slashing;
@@ -210,8 +210,8 @@ pub use crate::payload::{
FullPayloadRef, OwnedExecPayload,
};
pub use crate::pending_attestation::PendingAttestation;
pub use crate::pending_balance_deposit::PendingBalanceDeposit;
pub use crate::pending_consolidation::PendingConsolidation;
pub use crate::pending_deposit::PendingDeposit;
pub use crate::pending_partial_withdrawal::PendingPartialWithdrawal;
pub use crate::preset::{
AltairPreset, BasePreset, BellatrixPreset, CapellaPreset, DenebPreset, ElectraPreset,

View File

@@ -1,4 +1,5 @@
use crate::test_utils::TestRandom;
use crate::*;
use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
use test_random_derive::TestRandom;
@@ -18,16 +19,18 @@ use tree_hash_derive::TreeHash;
TreeHash,
TestRandom,
)]
pub struct PendingBalanceDeposit {
#[serde(with = "serde_utils::quoted_u64")]
pub index: u64,
pub struct PendingDeposit {
pub pubkey: PublicKeyBytes,
pub withdrawal_credentials: Hash256,
#[serde(with = "serde_utils::quoted_u64")]
pub amount: u64,
pub signature: Signature,
pub slot: Slot,
}
#[cfg(test)]
mod tests {
use super::*;
ssz_and_tree_hash_tests!(PendingBalanceDeposit);
ssz_and_tree_hash_tests!(PendingDeposit);
}

View File

@@ -266,7 +266,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_balance_deposits_limit() as u64,
pending_balance_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()