Skip to content

Commit

Permalink
Add electra presets to beacon API (#5630)
Browse files Browse the repository at this point in the history
* add presets to API

* add extra fields to config spec in beacon API

* remove unused

* add mainnet presets for gnosis and fix minimal preset default values
  • Loading branch information
realbigsean authored Apr 25, 2024
1 parent dd340ee commit 3203456
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 14 deletions.
46 changes: 44 additions & 2 deletions consensus/types/presets/gnosis/electra.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
# Gnosis preset - Electra
# Mainnet preset - Electra

ELECTRA_PLACEHOLDER: 0
# Gwei values
# ---------------------------------------------------------------
# 2**5 * 10**9 (= 32,000,000,000) Gwei
MIN_ACTIVATION_BALANCE: 32000000000
# 2**11 * 10**9 (= 2,048,000,000,000) Gwei
MAX_EFFECTIVE_BALANCE_ELECTRA: 2048000000000

# State list lengths
# ---------------------------------------------------------------
# `uint64(2**27)` (= 134,217,728)
PENDING_BALANCE_DEPOSITS_LIMIT: 134217728
# `uint64(2**27)` (= 134,217,728)
PENDING_PARTIAL_WITHDRAWALS_LIMIT: 134217728
# `uint64(2**18)` (= 262,144)
PENDING_CONSOLIDATIONS_LIMIT: 262144

# Reward and penalty quotients
# ---------------------------------------------------------------
# `uint64(2**12)` (= 4,096)
MIN_SLASHING_PENALTY_QUOTIENT_ELECTRA: 4096
# `uint64(2**12)` (= 4,096)
WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA: 4096

# # Max operations per block
# ---------------------------------------------------------------
# `uint64(2**0)` (= 1)
MAX_ATTESTER_SLASHINGS_ELECTRA: 1
# `uint64(2**3)` (= 8)
MAX_ATTESTATIONS_ELECTRA: 8
# `uint64(2**0)` (= 1)
MAX_CONSOLIDATIONS: 1

# Execution
# ---------------------------------------------------------------
# 2**13 (= 8192) receipts
MAX_DEPOSIT_RECEIPTS_PER_PAYLOAD: 8192
# 2**4 (= 16) withdrawal requests
MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD: 16

# Withdrawals processing
# ---------------------------------------------------------------
# 2**3 ( = 8) pending withdrawals
MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP: 8
44 changes: 43 additions & 1 deletion consensus/types/presets/mainnet/electra.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
# Mainnet preset - Electra

ELECTRA_PLACEHOLDER: 0
# Gwei values
# ---------------------------------------------------------------
# 2**5 * 10**9 (= 32,000,000,000) Gwei
MIN_ACTIVATION_BALANCE: 32000000000
# 2**11 * 10**9 (= 2,048,000,000,000) Gwei
MAX_EFFECTIVE_BALANCE_ELECTRA: 2048000000000

# State list lengths
# ---------------------------------------------------------------
# `uint64(2**27)` (= 134,217,728)
PENDING_BALANCE_DEPOSITS_LIMIT: 134217728
# `uint64(2**27)` (= 134,217,728)
PENDING_PARTIAL_WITHDRAWALS_LIMIT: 134217728
# `uint64(2**18)` (= 262,144)
PENDING_CONSOLIDATIONS_LIMIT: 262144

# Reward and penalty quotients
# ---------------------------------------------------------------
# `uint64(2**12)` (= 4,096)
MIN_SLASHING_PENALTY_QUOTIENT_ELECTRA: 4096
# `uint64(2**12)` (= 4,096)
WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA: 4096

# # Max operations per block
# ---------------------------------------------------------------
# `uint64(2**0)` (= 1)
MAX_ATTESTER_SLASHINGS_ELECTRA: 1
# `uint64(2**3)` (= 8)
MAX_ATTESTATIONS_ELECTRA: 8
# `uint64(2**0)` (= 1)
MAX_CONSOLIDATIONS: 1

# Execution
# ---------------------------------------------------------------
# 2**13 (= 8192) receipts
MAX_DEPOSIT_RECEIPTS_PER_PAYLOAD: 8192
# 2**4 (= 16) withdrawal requests
MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD: 16

# Withdrawals processing
# ---------------------------------------------------------------
# 2**3 ( = 8) pending withdrawals
MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP: 8
44 changes: 43 additions & 1 deletion consensus/types/presets/minimal/electra.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
# Minimal preset - Electra

ELECTRA_PLACEHOLDER: 0
# Gwei values
# ---------------------------------------------------------------
# 2**5 * 10**9 (= 32,000,000,000) Gwei
MIN_ACTIVATION_BALANCE: 32000000000
# 2**11 * 10**9 (= 2,048,000,000,000) Gwei
MAX_EFFECTIVE_BALANCE_ELECTRA: 2048000000000

# State list lengths
# ---------------------------------------------------------------
# `uint64(2**27)` (= 134,217,728)
PENDING_BALANCE_DEPOSITS_LIMIT: 134217728
# [customized] `uint64(2**6)` (= 64)
PENDING_PARTIAL_WITHDRAWALS_LIMIT: 64
# [customized] `uint64(2**6)` (= 64)
PENDING_CONSOLIDATIONS_LIMIT: 64

# Reward and penalty quotients
# ---------------------------------------------------------------
# `uint64(2**12)` (= 4,096)
MIN_SLASHING_PENALTY_QUOTIENT_ELECTRA: 4096
# `uint64(2**12)` (= 4,096)
WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA: 4096

# # Max operations per block
# ---------------------------------------------------------------
# `uint64(2**0)` (= 1)
MAX_ATTESTER_SLASHINGS_ELECTRA: 1
# `uint64(2**3)` (= 8)
MAX_ATTESTATIONS_ELECTRA: 8
# `uint64(2**0)` (= 1)
MAX_CONSOLIDATIONS: 1

# Execution
# ---------------------------------------------------------------
# [customized]
MAX_DEPOSIT_RECEIPTS_PER_PAYLOAD: 4
# [customized] 2**1 (= 2) withdrawal requests
MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD: 2

# Withdrawals processing
# ---------------------------------------------------------------
# 2**0 ( = 1) pending withdrawals
MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP: 1
2 changes: 2 additions & 0 deletions consensus/types/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,8 @@ 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)
.expect("pow does not overflow"),
// Other
network_id: 2, // lighthouse testnet network id
deposit_chain_id: 5,
Expand Down
12 changes: 10 additions & 2 deletions consensus/types/src/config_and_preset.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
consts::altair, AltairPreset, BasePreset, BellatrixPreset, CapellaPreset, ChainSpec, Config,
DenebPreset, ElectraPreset, EthSpec, ForkName,
consts::altair, consts::deneb, AltairPreset, BasePreset, BellatrixPreset, CapellaPreset,
ChainSpec, Config, DenebPreset, ElectraPreset, EthSpec, ForkName,
};
use maplit::hashmap;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -100,6 +100,7 @@ pub fn get_extra_fields(spec: &ChainSpec) -> HashMap<String, Value> {
let u8_hex = |v: u8| hex_string(&v.to_le_bytes());
hashmap! {
"bls_withdrawal_prefix".to_uppercase() => u8_hex(spec.bls_withdrawal_prefix_byte),
"eth1_address_withdrawal_prefix".to_uppercase() => u8_hex(spec.eth1_address_withdrawal_prefix_byte),
"domain_beacon_proposer".to_uppercase() => u32_hex(spec.domain_beacon_proposer),
"domain_beacon_attester".to_uppercase() => u32_hex(spec.domain_beacon_attester),
"domain_randao".to_uppercase()=> u32_hex(spec.domain_randao),
Expand All @@ -119,6 +120,13 @@ pub fn get_extra_fields(spec: &ChainSpec) -> HashMap<String, Value> {
altair::SYNC_COMMITTEE_SUBNET_COUNT.to_string().into(),
"target_aggregators_per_sync_subcommittee".to_uppercase() =>
altair::TARGET_AGGREGATORS_PER_SYNC_SUBCOMMITTEE.to_string().into(),
// Deneb
"versioned_hash_version_kzg".to_uppercase() => deneb::VERSIONED_HASH_VERSION_KZG.to_string().into(),
// Electra
"compounding_withdrawal_prefix".to_uppercase() => u8_hex(spec.compounding_withdrawal_prefix_byte),
"unset_deposit_receipts_start_index".to_uppercase() => spec.unset_deposit_receipts_start_index.to_string().into(),
"full_exit_request_amount".to_uppercase() => spec.full_exit_request_amount.to_string().into(),
"domain_consolidation".to_uppercase()=> u32_hex(spec.domain_consolidation),
}
}

Expand Down
3 changes: 3 additions & 0 deletions consensus/types/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ pub mod altair {
pub mod merge {
pub const INTERVALS_PER_SLOT: u64 = 3;
}
pub mod deneb {
pub use crate::VERSIONED_HASH_VERSION_KZG;
}
10 changes: 5 additions & 5 deletions consensus/types/src/eth_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@ impl EthSpec for MinimalEthSpec {
type BytesPerBlob = U131072;
type MaxBlobCommitmentsPerBlock = U16;
type KzgCommitmentInclusionProofDepth = U9;
type PendingPartialWithdrawalsLimit = U64;
type PendingConsolidationsLimit = U64;
type MaxDepositReceiptsPerPayload = U4;
type MaxWithdrawalRequestsPerPayload = U2;

params_from_eth_spec!(MainnetEthSpec {
JustificationBitsLength,
Expand All @@ -442,13 +446,9 @@ impl EthSpec for MinimalEthSpec {
MaxBlobsPerBlock,
BytesPerFieldElement,
PendingBalanceDepositsLimit,
PendingPartialWithdrawalsLimit,
PendingConsolidationsLimit,
MaxConsolidations,
MaxDepositReceiptsPerPayload,
MaxAttesterSlashingsElectra,
MaxAttestationsElectra,
MaxWithdrawalRequestsPerPayload
MaxAttestationsElectra
});

fn default_spec() -> ChainSpec {
Expand Down
43 changes: 40 additions & 3 deletions consensus/types/src/preset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,50 @@ impl DenebPreset {
#[serde(rename_all = "UPPERCASE")]
pub struct ElectraPreset {
#[serde(with = "serde_utils::quoted_u64")]
pub electra_placeholder: u64,
pub min_activation_balance: u64,
#[serde(with = "serde_utils::quoted_u64")]
pub max_effective_balance_electra: u64,
#[serde(with = "serde_utils::quoted_u64")]
pub min_slashing_penalty_quotient_electra: u64,
#[serde(with = "serde_utils::quoted_u64")]
pub whistleblower_reward_quotient_electra: u64,
#[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,
#[serde(with = "serde_utils::quoted_u64")]
pub pending_partial_withdrawals_limit: u64,
#[serde(with = "serde_utils::quoted_u64")]
pub pending_consolidations_limit: u64,
#[serde(with = "serde_utils::quoted_u64")]
pub max_consolidations: u64,
#[serde(with = "serde_utils::quoted_u64")]
pub max_deposit_receipts_per_payload: u64,
#[serde(with = "serde_utils::quoted_u64")]
pub max_attester_slashings_electra: u64,
#[serde(with = "serde_utils::quoted_u64")]
pub max_attestations_electra: u64,
#[serde(with = "serde_utils::quoted_u64")]
pub max_withdrawal_requests_per_payload: u64,
}

impl ElectraPreset {
pub fn from_chain_spec<E: EthSpec>(_spec: &ChainSpec) -> Self {
pub fn from_chain_spec<E: EthSpec>(spec: &ChainSpec) -> Self {
Self {
electra_placeholder: 0,
min_activation_balance: spec.min_activation_balance,
max_effective_balance_electra: spec.max_effective_balance_electra,
min_slashing_penalty_quotient_electra: spec.min_slashing_penalty_quotient_electra,
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_partial_withdrawals_limit: E::pending_partial_withdrawals_limit() as u64,
pending_consolidations_limit: E::pending_consolidations_limit() as u64,
max_consolidations: E::max_consolidations() as u64,
max_deposit_receipts_per_payload: E::max_deposit_receipts_per_payload() as u64,
max_attester_slashings_electra: E::max_attester_slashings_electra() as u64,
max_attestations_electra: E::max_attestations_electra() as u64,
max_withdrawal_requests_per_payload: E::max_withdrawal_requests_per_payload() as u64,
}
}
}
Expand Down

0 comments on commit 3203456

Please sign in to comment.