From 45be3d1edd1692e98f26bab7a68298fa84587430 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Fri, 13 Jan 2023 13:21:54 +1100 Subject: [PATCH 01/10] Add Capella types and presets --- src/capella/beacon_block.rs | 119 ++++++++++ src/capella/beacon_state.rs | 73 ++++++ src/capella/blinded_beacon_block.rs | 118 ++++++++++ src/capella/bls_to_execution_change.rs | 18 ++ src/capella/execution.rs | 294 +++++++++++++++++++++++++ src/capella/mod.rs | 41 ++++ src/capella/presets/mainnet.rs | 172 +++++++++++++++ src/capella/presets/minimal.rs | 172 +++++++++++++++ src/capella/presets/mod.rs | 8 + src/capella/withdrawal.rs | 11 + src/domains.rs | 1 + src/lib.rs | 1 + src/primitives.rs | 1 + 13 files changed, 1029 insertions(+) create mode 100644 src/capella/beacon_block.rs create mode 100644 src/capella/beacon_state.rs create mode 100644 src/capella/blinded_beacon_block.rs create mode 100644 src/capella/bls_to_execution_change.rs create mode 100644 src/capella/execution.rs create mode 100644 src/capella/mod.rs create mode 100644 src/capella/presets/mainnet.rs create mode 100644 src/capella/presets/minimal.rs create mode 100644 src/capella/presets/mod.rs create mode 100644 src/capella/withdrawal.rs diff --git a/src/capella/beacon_block.rs b/src/capella/beacon_block.rs new file mode 100644 index 000000000..6cde9d09a --- /dev/null +++ b/src/capella/beacon_block.rs @@ -0,0 +1,119 @@ +use crate::altair::SyncAggregate; +use crate::capella::{ExecutionPayload, SignedBlsToExecutionChange}; +use crate::phase0::{ + Attestation, AttesterSlashing, Deposit, Eth1Data, ProposerSlashing, SignedVoluntaryExit, +}; +use crate::primitives::{BlsSignature, Bytes32, Root, Slot, ValidatorIndex}; +use ssz_rs::prelude::*; + +#[derive(Default, Debug, Clone, SimpleSerialize, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct BeaconBlockBody< + const MAX_PROPOSER_SLASHINGS: usize, + const MAX_VALIDATORS_PER_COMMITTEE: usize, + const MAX_ATTESTER_SLASHINGS: usize, + const MAX_ATTESTATIONS: usize, + const MAX_DEPOSITS: usize, + const MAX_VOLUNTARY_EXITS: usize, + const SYNC_COMMITTEE_SIZE: usize, + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, + const MAX_BLS_TO_EXECUTION_CHANGES: usize, +> { + pub randao_reveal: BlsSignature, + pub eth1_data: Eth1Data, + pub graffiti: Bytes32, + pub proposer_slashings: List, + pub attester_slashings: + List, MAX_ATTESTER_SLASHINGS>, + pub attestations: List, MAX_ATTESTATIONS>, + pub deposits: List, + pub voluntary_exits: List, + pub sync_aggregate: SyncAggregate, + pub execution_payload: ExecutionPayload< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + >, + pub bls_to_execution_changes: List, +} + +#[derive(Default, Debug, Clone, SimpleSerialize, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct BeaconBlock< + const MAX_PROPOSER_SLASHINGS: usize, + const MAX_VALIDATORS_PER_COMMITTEE: usize, + const MAX_ATTESTER_SLASHINGS: usize, + const MAX_ATTESTATIONS: usize, + const MAX_DEPOSITS: usize, + const MAX_VOLUNTARY_EXITS: usize, + const SYNC_COMMITTEE_SIZE: usize, + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, + const MAX_BLS_TO_EXECUTION_CHANGES: usize, +> { + #[serde(with = "crate::serde::as_string")] + pub slot: Slot, + #[serde(with = "crate::serde::as_string")] + pub proposer_index: ValidatorIndex, + pub parent_root: Root, + pub state_root: Root, + pub body: BeaconBlockBody< + MAX_PROPOSER_SLASHINGS, + MAX_VALIDATORS_PER_COMMITTEE, + MAX_ATTESTER_SLASHINGS, + MAX_ATTESTATIONS, + MAX_DEPOSITS, + MAX_VOLUNTARY_EXITS, + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, + >, +} + +#[derive(Default, Debug, Clone, SimpleSerialize, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct SignedBeaconBlock< + const MAX_PROPOSER_SLASHINGS: usize, + const MAX_VALIDATORS_PER_COMMITTEE: usize, + const MAX_ATTESTER_SLASHINGS: usize, + const MAX_ATTESTATIONS: usize, + const MAX_DEPOSITS: usize, + const MAX_VOLUNTARY_EXITS: usize, + const SYNC_COMMITTEE_SIZE: usize, + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, + const MAX_BLS_TO_EXECUTION_CHANGES: usize, +> { + pub message: BeaconBlock< + MAX_PROPOSER_SLASHINGS, + MAX_VALIDATORS_PER_COMMITTEE, + MAX_ATTESTER_SLASHINGS, + MAX_ATTESTATIONS, + MAX_DEPOSITS, + MAX_VOLUNTARY_EXITS, + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, + >, + pub signature: BlsSignature, +} diff --git a/src/capella/beacon_state.rs b/src/capella/beacon_state.rs new file mode 100644 index 000000000..a04655676 --- /dev/null +++ b/src/capella/beacon_state.rs @@ -0,0 +1,73 @@ +use crate::altair::SyncCommittee; +use crate::capella::ExecutionPayloadHeader; +use crate::phase0::{ + BeaconBlockHeader, Checkpoint, Eth1Data, Fork, Validator, JUSTIFICATION_BITS_LENGTH, +}; +use crate::primitives::{Bytes32, Gwei, ParticipationFlags, Root, Slot, ValidatorIndex, WithdrawalIndex}; +use ssz_rs::prelude::*; + +#[derive(Default, Debug, SimpleSerialize, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct BeaconState< + const SLOTS_PER_HISTORICAL_ROOT: usize, + const HISTORICAL_ROOTS_LIMIT: usize, + const ETH1_DATA_VOTES_BOUND: usize, + const VALIDATOR_REGISTRY_LIMIT: usize, + const EPOCHS_PER_HISTORICAL_VECTOR: usize, + const EPOCHS_PER_SLASHINGS_VECTOR: usize, + const MAX_VALIDATORS_PER_COMMITTEE: usize, + const SYNC_COMMITTEE_SIZE: usize, + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, +> { + #[serde(with = "crate::serde::as_string")] + pub genesis_time: u64, + pub genesis_validators_root: Root, + #[serde(with = "crate::serde::as_string")] + pub slot: Slot, + pub fork: Fork, + pub latest_block_header: BeaconBlockHeader, + pub block_roots: Vector, + pub state_roots: Vector, + pub historical_roots: List, + pub eth1_data: Eth1Data, + pub eth1_data_votes: List, + #[serde(with = "crate::serde::as_string")] + pub eth1_deposit_index: u64, + pub validators: List, + #[serde(with = "crate::serde::collection_over_string")] + pub balances: List, + pub randao_mixes: Vector, + #[serde(with = "crate::serde::collection_over_string")] + pub slashings: Vector, + #[serde(with = "crate::serde::collection_over_string")] + pub previous_epoch_participation: List, + #[serde(with = "crate::serde::collection_over_string")] + pub current_epoch_participation: List, + pub justification_bits: Bitvector, + pub previous_justified_checkpoint: Checkpoint, + pub current_justified_checkpoint: Checkpoint, + pub finalized_checkpoint: Checkpoint, + #[serde(with = "crate::serde::collection_over_string")] + pub inactivity_scores: List, + pub current_sync_committee: SyncCommittee, + pub next_sync_committee: SyncCommittee, + pub latest_execution_payload_header: ExecutionPayloadHeader< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + >, + pub next_withdrawal_index: WithdrawalIndex, + pub next_withdrawal_validator_index: ValidatorIndex, + pub historical_summaries: List, +} + +#[derive(Default, Debug, SimpleSerialize, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct HistoricalSummary { + pub block_summary_root: Root, + pub state_summary_root: Root, +} diff --git a/src/capella/blinded_beacon_block.rs b/src/capella/blinded_beacon_block.rs new file mode 100644 index 000000000..0e7429eca --- /dev/null +++ b/src/capella/blinded_beacon_block.rs @@ -0,0 +1,118 @@ +use crate::altair::SyncAggregate; +use crate::capella::{ExecutionPayloadHeader, SignedBlsToExecutionChange}; +use crate::phase0::{ + Attestation, AttesterSlashing, Deposit, Eth1Data, ProposerSlashing, SignedVoluntaryExit, +}; +use crate::primitives::{BlsSignature, Bytes32, Root, Slot, ValidatorIndex}; +use ssz_rs::prelude::*; + +#[derive(Default, Debug, Clone, SimpleSerialize)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct BlindedBeaconBlockBody< + const MAX_PROPOSER_SLASHINGS: usize, + const MAX_VALIDATORS_PER_COMMITTEE: usize, + const MAX_ATTESTER_SLASHINGS: usize, + const MAX_ATTESTATIONS: usize, + const MAX_DEPOSITS: usize, + const MAX_VOLUNTARY_EXITS: usize, + const SYNC_COMMITTEE_SIZE: usize, + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, + const MAX_BLS_TO_EXECUTION_CHANGES: usize, +> { + pub randao_reveal: BlsSignature, + pub eth1_data: Eth1Data, + pub graffiti: Bytes32, + pub proposer_slashings: List, + pub attester_slashings: + List, MAX_ATTESTER_SLASHINGS>, + pub attestations: List, MAX_ATTESTATIONS>, + pub deposits: List, + pub voluntary_exits: List, + pub sync_aggregate: SyncAggregate, + pub execution_payload_header: ExecutionPayloadHeader< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + >, + pub bls_to_execution_changes: List, +} + +#[derive(Default, Debug, Clone, SimpleSerialize)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct BlindedBeaconBlock< + const MAX_PROPOSER_SLASHINGS: usize, + const MAX_VALIDATORS_PER_COMMITTEE: usize, + const MAX_ATTESTER_SLASHINGS: usize, + const MAX_ATTESTATIONS: usize, + const MAX_DEPOSITS: usize, + const MAX_VOLUNTARY_EXITS: usize, + const SYNC_COMMITTEE_SIZE: usize, + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, + const MAX_BLS_TO_EXECUTION_CHANGES: usize, +> { + #[serde(with = "crate::serde::as_string")] + pub slot: Slot, + #[serde(with = "crate::serde::as_string")] + pub proposer_index: ValidatorIndex, + pub parent_root: Root, + pub state_root: Root, + pub body: BlindedBeaconBlockBody< + MAX_PROPOSER_SLASHINGS, + MAX_VALIDATORS_PER_COMMITTEE, + MAX_ATTESTER_SLASHINGS, + MAX_ATTESTATIONS, + MAX_DEPOSITS, + MAX_VOLUNTARY_EXITS, + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, + >, +} + +#[derive(Default, Debug, Clone, SimpleSerialize)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct SignedBlindedBeaconBlock< + const MAX_PROPOSER_SLASHINGS: usize, + const MAX_VALIDATORS_PER_COMMITTEE: usize, + const MAX_ATTESTER_SLASHINGS: usize, + const MAX_ATTESTATIONS: usize, + const MAX_DEPOSITS: usize, + const MAX_VOLUNTARY_EXITS: usize, + const SYNC_COMMITTEE_SIZE: usize, + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, + const MAX_BLS_TO_EXECUTION_CHANGES: usize, +> { + pub message: BlindedBeaconBlock< + MAX_PROPOSER_SLASHINGS, + MAX_VALIDATORS_PER_COMMITTEE, + MAX_ATTESTER_SLASHINGS, + MAX_ATTESTATIONS, + MAX_DEPOSITS, + MAX_VOLUNTARY_EXITS, + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, + >, + pub signature: BlsSignature, +} diff --git a/src/capella/bls_to_execution_change.rs b/src/capella/bls_to_execution_change.rs new file mode 100644 index 000000000..70fdfbf01 --- /dev/null +++ b/src/capella/bls_to_execution_change.rs @@ -0,0 +1,18 @@ +use ssz_rs::prelude::*; +use crate::primitives::{BlsPublicKey, BlsSignature, ExecutionAddress, ValidatorIndex}; + +#[derive(Default, Debug, Clone, SimpleSerialize, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct BlsToExecutionChange { + pub validator_index: ValidatorIndex, + #[serde(rename = "from_bls_pubkey")] + pub from_bls_public_key: BlsPublicKey, + pub to_execution_address: ExecutionAddress, +} + +#[derive(Default, Debug, Clone, SimpleSerialize, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct SignedBlsToExecutionChange { + message: BlsToExecutionChange, + signature: BlsSignature, +} \ No newline at end of file diff --git a/src/capella/execution.rs b/src/capella/execution.rs new file mode 100644 index 000000000..35e5eb81a --- /dev/null +++ b/src/capella/execution.rs @@ -0,0 +1,294 @@ +use crate::primitives::{Bytes32, ExecutionAddress, Hash32, Root, U256}; +use crate::ssz::{ByteList, ByteVector}; +use crate::state_transition::{self, Error}; +use ssz_rs::prelude::*; +use crate::bellatrix::Transaction; +use crate::capella::withdrawal::Withdrawal; + +#[derive(Default, Debug, Clone, SimpleSerialize, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct ExecutionPayload< + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize +> { + pub parent_hash: Hash32, + pub fee_recipient: ExecutionAddress, + pub state_root: Bytes32, + pub receipts_root: Bytes32, + pub logs_bloom: ByteVector, + pub prev_randao: Bytes32, + #[serde(with = "crate::serde::as_string")] + pub block_number: u64, + #[serde(with = "crate::serde::as_string")] + pub gas_limit: u64, + #[serde(with = "crate::serde::as_string")] + pub gas_used: u64, + #[serde(with = "crate::serde::as_string")] + pub timestamp: u64, + pub extra_data: ByteList, + pub base_fee_per_gas: U256, + pub block_hash: Hash32, + pub transactions: List, MAX_TRANSACTIONS_PER_PAYLOAD>, + pub withdrawals: List +} + +#[derive(Default, Debug, Clone, SimpleSerialize, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct ExecutionPayloadHeader< + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, +> { + pub parent_hash: Hash32, + pub fee_recipient: ExecutionAddress, + pub state_root: Bytes32, + pub receipts_root: Bytes32, + pub logs_bloom: ByteVector, + pub prev_randao: Bytes32, + #[serde(with = "crate::serde::as_string")] + pub block_number: u64, + #[serde(with = "crate::serde::as_string")] + pub gas_limit: u64, + #[serde(with = "crate::serde::as_string")] + pub gas_used: u64, + #[serde(with = "crate::serde::as_string")] + pub timestamp: u64, + pub extra_data: ByteList, + pub base_fee_per_gas: U256, + pub block_hash: Hash32, + pub transactions_root: Root, + pub withdrawals_root: Root, +} + +impl< + 'a, + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize + > + TryFrom< + &'a mut ExecutionPayload< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD + >, + > + for ExecutionPayloadHeader< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + > +{ + type Error = Error; + + fn try_from( + payload: &'a mut ExecutionPayload< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD + >, + ) -> Result< + ExecutionPayloadHeader< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + >, + Self::Error, + > { + let transactions_root = payload.transactions.hash_tree_root()?; + let withdrawals_root = payload.withdrawals.hash_tree_root()?; + + Ok(ExecutionPayloadHeader { + parent_hash: payload.parent_hash.clone(), + fee_recipient: payload.fee_recipient.clone(), + state_root: payload.state_root.clone(), + receipts_root: payload.receipts_root.clone(), + logs_bloom: payload.logs_bloom.clone(), + prev_randao: payload.prev_randao.clone(), + block_number: payload.block_number, + gas_limit: payload.gas_limit, + gas_used: payload.gas_used, + timestamp: payload.timestamp, + extra_data: payload.extra_data.clone(), + base_fee_per_gas: payload.base_fee_per_gas.clone(), + block_hash: payload.block_hash.clone(), + transactions_root, + withdrawals_root, + }) + } +} + +pub trait ExecutionEngine< + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, +> where + Self: Clone, +{ + fn notify_new_payload( + &self, + execution_payload: &ExecutionPayload< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + >, + ) -> state_transition::Result<()>; +} + +#[derive(Clone)] +pub struct NoOpExecutionEngine< + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, +>; + +impl< + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize + > + ExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + > + for NoOpExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + > +{ + fn notify_new_payload( + &self, + _execution_payload: &ExecutionPayload< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD + >, + ) -> state_transition::Result<()> { + Ok(()) + } +} + +#[derive(Clone)] +pub struct MockExecutionEngine< + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, + F: Fn( + &ExecutionPayload< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD + >, + ) -> state_transition::Result<()>, +> { + f: F, +} + +impl< + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, + F: Fn( + &ExecutionPayload< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD + >, + ) -> state_transition::Result<()>, + > + MockExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + F, + > +{ + pub fn new(f: F) -> Self { + Self { f } + } +} + +impl< + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + const MAX_BYTES_PER_TRANSACTION: usize, + const MAX_TRANSACTIONS_PER_PAYLOAD: usize, + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, + F: Fn( + &ExecutionPayload< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + >, + ) -> state_transition::Result<()> + + Clone, + > + ExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + > + for MockExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + F, + > +{ + fn notify_new_payload( + &self, + execution_payload: &ExecutionPayload< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + >, + ) -> state_transition::Result<()> { + (self.f)(execution_payload) + } +} diff --git a/src/capella/mod.rs b/src/capella/mod.rs new file mode 100644 index 000000000..57413b818 --- /dev/null +++ b/src/capella/mod.rs @@ -0,0 +1,41 @@ +//! This module provides an implementation of the `capella` fork +//! of the consensus spec. The primary entrypoints should be one of +//! the "presets" like `mainnet` or `minimal`. +mod beacon_block; +mod beacon_state; +mod blinded_beacon_block; +mod execution; +mod withdrawal; +mod bls_to_execution_change; +mod presets; + +pub use beacon_block::*; +pub use beacon_state::*; +pub use blinded_beacon_block::*; +pub use execution::*; +pub use bls_to_execution_change::*; +pub use presets::Preset; + +pub use crate::bellatrix::{ + Transaction +}; +pub use crate::altair::{ + SyncAggregate, SyncAggregatorSelectionData, SyncCommittee, PARTICIPATION_FLAG_WEIGHTS, + PROPOSER_WEIGHT, SYNC_REWARD_WEIGHT, TIMELY_HEAD_FLAG_INDEX, TIMELY_SOURCE_FLAG_INDEX, + TIMELY_TARGET_FLAG_INDEX, WEIGHT_DENOMINATOR, +}; +pub use crate::phase0::{ + Attestation, AttestationData, AttesterSlashing, BeaconBlockHeader, Checkpoint, Deposit, + DepositData, DepositMessage, Eth1Block, Eth1Data, Fork, ForkData, HistoricalBatchAccumulator, + IndexedAttestation, ProposerSlashing, SignedBeaconBlockHeader, SignedVoluntaryExit, + SigningData, Validator, VoluntaryExit, BASE_REWARDS_PER_EPOCH, DEPOSIT_CONTRACT_TREE_DEPTH, + JUSTIFICATION_BITS_LENGTH, +}; + +pub mod mainnet { + pub use super::presets::mainnet::*; +} + +pub mod minimal { + pub use super::presets::minimal::*; +} diff --git a/src/capella/presets/mainnet.rs b/src/capella/presets/mainnet.rs new file mode 100644 index 000000000..acdea1cbd --- /dev/null +++ b/src/capella/presets/mainnet.rs @@ -0,0 +1,172 @@ +pub use crate::altair::mainnet::SYNC_COMMITTEE_SIZE; +pub use crate::altair::mainnet::{ + AggregateAndProof, Attestation, AttesterSlashing, ContributionAndProof, HistoricalBatch, + IndexedAttestation, LightClientUpdate, PendingAttestation, SignedAggregateAndProof, + SignedContributionAndProof, SyncAggregate, SyncCommittee, SyncCommitteeContribution, + SyncCommitteeMessage, +}; +use crate::bellatrix::mainnet::{BYTES_PER_LOGS_BLOOM, INACTIVITY_PENALTY_QUOTIENT_BELLATRIX, MAX_BYTES_PER_TRANSACTION, MAX_EXTRA_DATA_BYTES, MAX_TRANSACTIONS_PER_PAYLOAD, MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX, PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX}; +use crate::bellatrix::mainnet::Transaction; +use crate::capella; +use crate::capella::presets::Preset; +pub use crate::phase0::mainnet::{ + EPOCHS_PER_HISTORICAL_VECTOR, EPOCHS_PER_SLASHINGS_VECTOR, ETH1_DATA_VOTES_BOUND, + HISTORICAL_ROOTS_LIMIT, MAX_ATTESTATIONS, MAX_ATTESTER_SLASHINGS, MAX_DEPOSITS, + MAX_PROPOSER_SLASHINGS, MAX_VALIDATORS_PER_COMMITTEE, MAX_VOLUNTARY_EXITS, + SLOTS_PER_HISTORICAL_ROOT, VALIDATOR_REGISTRY_LIMIT, +}; + +pub use capella::*; + +pub const MAX_WITHDRAWALS_PER_PAYLOAD: usize = 16; +pub const MAX_BLS_TO_EXECUTION_CHANGES: usize = 16; +pub const MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP: usize =16384; + +pub const PRESET: Preset = Preset { + max_bls_to_execution_changes: MAX_BLS_TO_EXECUTION_CHANGES, + max_withdrawals_per_payload: MAX_WITHDRAWALS_PER_PAYLOAD, + max_validators_per_withdrawals_sweep: MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP +}; + +pub type ExecutionPayload = capella::ExecutionPayload< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, +>; + +pub type ExecutionPayloadHeader = capella::ExecutionPayloadHeader< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, +>; + +pub type BlindedBeaconBlock = capella::BlindedBeaconBlock< + MAX_PROPOSER_SLASHINGS, + MAX_VALIDATORS_PER_COMMITTEE, + MAX_ATTESTER_SLASHINGS, + MAX_ATTESTATIONS, + MAX_DEPOSITS, + MAX_VOLUNTARY_EXITS, + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, +>; + +pub type BlindedBeaconBlockBody = capella::BlindedBeaconBlockBody< + MAX_PROPOSER_SLASHINGS, + MAX_VALIDATORS_PER_COMMITTEE, + MAX_ATTESTER_SLASHINGS, + MAX_ATTESTATIONS, + MAX_DEPOSITS, + MAX_VOLUNTARY_EXITS, + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, +>; + +pub type SignedBlindedBeaconBlock = capella::SignedBlindedBeaconBlock< + MAX_PROPOSER_SLASHINGS, + MAX_VALIDATORS_PER_COMMITTEE, + MAX_ATTESTER_SLASHINGS, + MAX_ATTESTATIONS, + MAX_DEPOSITS, + MAX_VOLUNTARY_EXITS, + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, +>; + +pub type BeaconState = capella::BeaconState< + SLOTS_PER_HISTORICAL_ROOT, + HISTORICAL_ROOTS_LIMIT, + ETH1_DATA_VOTES_BOUND, + VALIDATOR_REGISTRY_LIMIT, + EPOCHS_PER_HISTORICAL_VECTOR, + EPOCHS_PER_SLASHINGS_VECTOR, + MAX_VALIDATORS_PER_COMMITTEE, + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, +>; + +pub type BeaconBlockBody = capella::BeaconBlockBody< + MAX_PROPOSER_SLASHINGS, + MAX_VALIDATORS_PER_COMMITTEE, + MAX_ATTESTER_SLASHINGS, + MAX_ATTESTATIONS, + MAX_DEPOSITS, + MAX_VOLUNTARY_EXITS, + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, +>; + +pub type BeaconBlock = capella::BeaconBlock< + MAX_PROPOSER_SLASHINGS, + MAX_VALIDATORS_PER_COMMITTEE, + MAX_ATTESTER_SLASHINGS, + MAX_ATTESTATIONS, + MAX_DEPOSITS, + MAX_VOLUNTARY_EXITS, + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, +>; + +pub type SignedBeaconBlock = capella::SignedBeaconBlock< + MAX_PROPOSER_SLASHINGS, + MAX_VALIDATORS_PER_COMMITTEE, + MAX_ATTESTER_SLASHINGS, + MAX_ATTESTATIONS, + MAX_DEPOSITS, + MAX_VOLUNTARY_EXITS, + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, +>; + +pub type NoOpExecutionEngine = capella::NoOpExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD +>; + +pub type MockExecutionEngine = capella::MockExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + F, +>; diff --git a/src/capella/presets/minimal.rs b/src/capella/presets/minimal.rs new file mode 100644 index 000000000..634916e3b --- /dev/null +++ b/src/capella/presets/minimal.rs @@ -0,0 +1,172 @@ +pub use crate::altair::minimal::SYNC_COMMITTEE_SIZE; +pub use crate::altair::minimal::{ + AggregateAndProof, Attestation, AttesterSlashing, ContributionAndProof, HistoricalBatch, + IndexedAttestation, LightClientUpdate, PendingAttestation, SignedAggregateAndProof, + SignedContributionAndProof, SyncAggregate, SyncCommittee, SyncCommitteeContribution, + SyncCommitteeMessage, +}; +use crate::bellatrix::minimal::{BYTES_PER_LOGS_BLOOM, INACTIVITY_PENALTY_QUOTIENT_BELLATRIX, MAX_BYTES_PER_TRANSACTION, MAX_EXTRA_DATA_BYTES, MAX_TRANSACTIONS_PER_PAYLOAD, MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX, PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX}; +use crate::bellatrix::minimal::Transaction; +use crate::capella; +use crate::capella::presets::Preset; +pub use crate::phase0::minimal::{ + EPOCHS_PER_HISTORICAL_VECTOR, EPOCHS_PER_SLASHINGS_VECTOR, ETH1_DATA_VOTES_BOUND, + HISTORICAL_ROOTS_LIMIT, MAX_ATTESTATIONS, MAX_ATTESTER_SLASHINGS, MAX_DEPOSITS, + MAX_PROPOSER_SLASHINGS, MAX_VALIDATORS_PER_COMMITTEE, MAX_VOLUNTARY_EXITS, + SLOTS_PER_HISTORICAL_ROOT, VALIDATOR_REGISTRY_LIMIT, +}; + +pub use capella::*; + +pub const MAX_WITHDRAWALS_PER_PAYLOAD: usize = 16; +pub const MAX_BLS_TO_EXECUTION_CHANGES: usize = 16; +pub const MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP: usize =16384; + +pub const PRESET: Preset = Preset { + max_bls_to_execution_changes: MAX_BLS_TO_EXECUTION_CHANGES, + max_withdrawals_per_payload: MAX_WITHDRAWALS_PER_PAYLOAD, + max_validators_per_withdrawals_sweep: MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP +}; + +pub type ExecutionPayload = capella::ExecutionPayload< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, +>; + +pub type ExecutionPayloadHeader = capella::ExecutionPayloadHeader< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, +>; + +pub type BlindedBeaconBlock = capella::BlindedBeaconBlock< + MAX_PROPOSER_SLASHINGS, + MAX_VALIDATORS_PER_COMMITTEE, + MAX_ATTESTER_SLASHINGS, + MAX_ATTESTATIONS, + MAX_DEPOSITS, + MAX_VOLUNTARY_EXITS, + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, +>; + +pub type BlindedBeaconBlockBody = capella::BlindedBeaconBlockBody< + MAX_PROPOSER_SLASHINGS, + MAX_VALIDATORS_PER_COMMITTEE, + MAX_ATTESTER_SLASHINGS, + MAX_ATTESTATIONS, + MAX_DEPOSITS, + MAX_VOLUNTARY_EXITS, + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, +>; + +pub type SignedBlindedBeaconBlock = capella::SignedBlindedBeaconBlock< + MAX_PROPOSER_SLASHINGS, + MAX_VALIDATORS_PER_COMMITTEE, + MAX_ATTESTER_SLASHINGS, + MAX_ATTESTATIONS, + MAX_DEPOSITS, + MAX_VOLUNTARY_EXITS, + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, +>; + +pub type BeaconState = capella::BeaconState< + SLOTS_PER_HISTORICAL_ROOT, + HISTORICAL_ROOTS_LIMIT, + ETH1_DATA_VOTES_BOUND, + VALIDATOR_REGISTRY_LIMIT, + EPOCHS_PER_HISTORICAL_VECTOR, + EPOCHS_PER_SLASHINGS_VECTOR, + MAX_VALIDATORS_PER_COMMITTEE, + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, +>; + +pub type BeaconBlockBody = capella::BeaconBlockBody< + MAX_PROPOSER_SLASHINGS, + MAX_VALIDATORS_PER_COMMITTEE, + MAX_ATTESTER_SLASHINGS, + MAX_ATTESTATIONS, + MAX_DEPOSITS, + MAX_VOLUNTARY_EXITS, + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, +>; + +pub type BeaconBlock = capella::BeaconBlock< + MAX_PROPOSER_SLASHINGS, + MAX_VALIDATORS_PER_COMMITTEE, + MAX_ATTESTER_SLASHINGS, + MAX_ATTESTATIONS, + MAX_DEPOSITS, + MAX_VOLUNTARY_EXITS, + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, +>; + +pub type SignedBeaconBlock = capella::SignedBeaconBlock< + MAX_PROPOSER_SLASHINGS, + MAX_VALIDATORS_PER_COMMITTEE, + MAX_ATTESTER_SLASHINGS, + MAX_ATTESTATIONS, + MAX_DEPOSITS, + MAX_VOLUNTARY_EXITS, + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, +>; + +pub type NoOpExecutionEngine = capella::NoOpExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD +>; + +pub type MockExecutionEngine = capella::MockExecutionEngine< + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + MAX_BYTES_PER_TRANSACTION, + MAX_TRANSACTIONS_PER_PAYLOAD, + MAX_WITHDRAWALS_PER_PAYLOAD, + F, +>; diff --git a/src/capella/presets/mod.rs b/src/capella/presets/mod.rs new file mode 100644 index 000000000..b92ef77b2 --- /dev/null +++ b/src/capella/presets/mod.rs @@ -0,0 +1,8 @@ +pub mod mainnet; +pub mod minimal; + +pub struct Preset { + pub max_bls_to_execution_changes: usize, + pub max_withdrawals_per_payload: usize, + pub max_validators_per_withdrawals_sweep: usize, +} diff --git a/src/capella/withdrawal.rs b/src/capella/withdrawal.rs new file mode 100644 index 000000000..b5e1473e5 --- /dev/null +++ b/src/capella/withdrawal.rs @@ -0,0 +1,11 @@ +use crate::primitives::{ExecutionAddress, Gwei, ValidatorIndex, WithdrawalIndex}; +use ssz_rs::prelude::*; + +#[derive(Default, Debug, Clone, SimpleSerialize, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct Withdrawal { + pub index: WithdrawalIndex, + pub validator_index: ValidatorIndex, + pub address: ExecutionAddress, + pub amount: Gwei, +} diff --git a/src/domains.rs b/src/domains.rs index 8a114bddd..4efddc4c9 100644 --- a/src/domains.rs +++ b/src/domains.rs @@ -10,6 +10,7 @@ pub enum DomainType { SyncCommittee, SyncCommitteeSelectionProof, ContributionAndProof, + BlsToExecutionChange, ApplicationMask, ApplicationBuilder, } diff --git a/src/lib.rs b/src/lib.rs index 7267c4c24..fa059dc6e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ pub mod altair; pub mod bellatrix; +pub mod capella; pub mod builder; pub(crate) mod bytes; pub mod clock; diff --git a/src/primitives.rs b/src/primitives.rs index 970ffd77f..6f981df0a 100644 --- a/src/primitives.rs +++ b/src/primitives.rs @@ -11,6 +11,7 @@ pub type Epoch = u64; pub type CommitteeIndex = usize; pub type ValidatorIndex = usize; +pub type WithdrawalIndex = usize; pub type Gwei = u64; pub type Hash32 = Bytes32; From f88a0aece7589d2a526a6671f11456ea8c04a1f7 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Fri, 13 Jan 2023 13:28:30 +1100 Subject: [PATCH 02/10] Update use crates --- src/capella/presets/mainnet.rs | 4 ++-- src/capella/presets/minimal.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/capella/presets/mainnet.rs b/src/capella/presets/mainnet.rs index acdea1cbd..c961eb9ba 100644 --- a/src/capella/presets/mainnet.rs +++ b/src/capella/presets/mainnet.rs @@ -5,8 +5,8 @@ pub use crate::altair::mainnet::{ SignedContributionAndProof, SyncAggregate, SyncCommittee, SyncCommitteeContribution, SyncCommitteeMessage, }; -use crate::bellatrix::mainnet::{BYTES_PER_LOGS_BLOOM, INACTIVITY_PENALTY_QUOTIENT_BELLATRIX, MAX_BYTES_PER_TRANSACTION, MAX_EXTRA_DATA_BYTES, MAX_TRANSACTIONS_PER_PAYLOAD, MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX, PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX}; -use crate::bellatrix::mainnet::Transaction; +pub use crate::bellatrix::mainnet::{BYTES_PER_LOGS_BLOOM, MAX_BYTES_PER_TRANSACTION, MAX_EXTRA_DATA_BYTES, MAX_TRANSACTIONS_PER_PAYLOAD, PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX}; +pub use crate::bellatrix::mainnet::Transaction; use crate::capella; use crate::capella::presets::Preset; pub use crate::phase0::mainnet::{ diff --git a/src/capella/presets/minimal.rs b/src/capella/presets/minimal.rs index 634916e3b..572222e4f 100644 --- a/src/capella/presets/minimal.rs +++ b/src/capella/presets/minimal.rs @@ -5,8 +5,8 @@ pub use crate::altair::minimal::{ SignedContributionAndProof, SyncAggregate, SyncCommittee, SyncCommitteeContribution, SyncCommitteeMessage, }; -use crate::bellatrix::minimal::{BYTES_PER_LOGS_BLOOM, INACTIVITY_PENALTY_QUOTIENT_BELLATRIX, MAX_BYTES_PER_TRANSACTION, MAX_EXTRA_DATA_BYTES, MAX_TRANSACTIONS_PER_PAYLOAD, MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX, PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX}; -use crate::bellatrix::minimal::Transaction; +pub use crate::bellatrix::minimal::{BYTES_PER_LOGS_BLOOM, MAX_BYTES_PER_TRANSACTION, MAX_EXTRA_DATA_BYTES, MAX_TRANSACTIONS_PER_PAYLOAD, PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX}; +pub use crate::bellatrix::minimal::Transaction; use crate::capella; use crate::capella::presets::Preset; pub use crate::phase0::minimal::{ From e55d7ddb556e68943342c4fb6177704036cabd50 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Sat, 14 Jan 2023 09:43:27 +1100 Subject: [PATCH 03/10] Run rustfmt on capella directory --- src/capella/beacon_state.rs | 4 +++- src/capella/bls_to_execution_change.rs | 4 ++-- src/capella/execution.rs | 22 +++++++++++----------- src/capella/mod.rs | 10 ++++------ src/capella/presets/mainnet.rs | 11 +++++++---- src/capella/presets/minimal.rs | 11 +++++++---- 6 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/capella/beacon_state.rs b/src/capella/beacon_state.rs index a04655676..44a23d549 100644 --- a/src/capella/beacon_state.rs +++ b/src/capella/beacon_state.rs @@ -3,7 +3,9 @@ use crate::capella::ExecutionPayloadHeader; use crate::phase0::{ BeaconBlockHeader, Checkpoint, Eth1Data, Fork, Validator, JUSTIFICATION_BITS_LENGTH, }; -use crate::primitives::{Bytes32, Gwei, ParticipationFlags, Root, Slot, ValidatorIndex, WithdrawalIndex}; +use crate::primitives::{ + Bytes32, Gwei, ParticipationFlags, Root, Slot, ValidatorIndex, WithdrawalIndex, +}; use ssz_rs::prelude::*; #[derive(Default, Debug, SimpleSerialize, Clone, PartialEq, Eq)] diff --git a/src/capella/bls_to_execution_change.rs b/src/capella/bls_to_execution_change.rs index 70fdfbf01..0af1dd528 100644 --- a/src/capella/bls_to_execution_change.rs +++ b/src/capella/bls_to_execution_change.rs @@ -1,5 +1,5 @@ -use ssz_rs::prelude::*; use crate::primitives::{BlsPublicKey, BlsSignature, ExecutionAddress, ValidatorIndex}; +use ssz_rs::prelude::*; #[derive(Default, Debug, Clone, SimpleSerialize, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -15,4 +15,4 @@ pub struct BlsToExecutionChange { pub struct SignedBlsToExecutionChange { message: BlsToExecutionChange, signature: BlsSignature, -} \ No newline at end of file +} diff --git a/src/capella/execution.rs b/src/capella/execution.rs index 35e5eb81a..f3eba728a 100644 --- a/src/capella/execution.rs +++ b/src/capella/execution.rs @@ -1,9 +1,9 @@ +use crate::bellatrix::Transaction; +use crate::capella::withdrawal::Withdrawal; use crate::primitives::{Bytes32, ExecutionAddress, Hash32, Root, U256}; use crate::ssz::{ByteList, ByteVector}; use crate::state_transition::{self, Error}; use ssz_rs::prelude::*; -use crate::bellatrix::Transaction; -use crate::capella::withdrawal::Withdrawal; #[derive(Default, Debug, Clone, SimpleSerialize, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -12,7 +12,7 @@ pub struct ExecutionPayload< const MAX_EXTRA_DATA_BYTES: usize, const MAX_BYTES_PER_TRANSACTION: usize, const MAX_TRANSACTIONS_PER_PAYLOAD: usize, - const MAX_WITHDRAWALS_PER_PAYLOAD: usize + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, > { pub parent_hash: Hash32, pub fee_recipient: ExecutionAddress, @@ -32,7 +32,7 @@ pub struct ExecutionPayload< pub base_fee_per_gas: U256, pub block_hash: Hash32, pub transactions: List, MAX_TRANSACTIONS_PER_PAYLOAD>, - pub withdrawals: List + pub withdrawals: List, } #[derive(Default, Debug, Clone, SimpleSerialize, PartialEq, Eq)] @@ -70,7 +70,7 @@ impl< const MAX_EXTRA_DATA_BYTES: usize, const MAX_BYTES_PER_TRANSACTION: usize, const MAX_TRANSACTIONS_PER_PAYLOAD: usize, - const MAX_WITHDRAWALS_PER_PAYLOAD: usize + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, > TryFrom< &'a mut ExecutionPayload< @@ -78,7 +78,7 @@ impl< MAX_EXTRA_DATA_BYTES, MAX_BYTES_PER_TRANSACTION, MAX_TRANSACTIONS_PER_PAYLOAD, - MAX_WITHDRAWALS_PER_PAYLOAD + MAX_WITHDRAWALS_PER_PAYLOAD, >, > for ExecutionPayloadHeader< @@ -96,7 +96,7 @@ impl< MAX_EXTRA_DATA_BYTES, MAX_BYTES_PER_TRANSACTION, MAX_TRANSACTIONS_PER_PAYLOAD, - MAX_WITHDRAWALS_PER_PAYLOAD + MAX_WITHDRAWALS_PER_PAYLOAD, >, ) -> Result< ExecutionPayloadHeader< @@ -165,7 +165,7 @@ impl< const MAX_EXTRA_DATA_BYTES: usize, const MAX_BYTES_PER_TRANSACTION: usize, const MAX_TRANSACTIONS_PER_PAYLOAD: usize, - const MAX_WITHDRAWALS_PER_PAYLOAD: usize + const MAX_WITHDRAWALS_PER_PAYLOAD: usize, > ExecutionEngine< BYTES_PER_LOGS_BLOOM, @@ -189,7 +189,7 @@ impl< MAX_EXTRA_DATA_BYTES, MAX_BYTES_PER_TRANSACTION, MAX_TRANSACTIONS_PER_PAYLOAD, - MAX_WITHDRAWALS_PER_PAYLOAD + MAX_WITHDRAWALS_PER_PAYLOAD, >, ) -> state_transition::Result<()> { Ok(()) @@ -209,7 +209,7 @@ pub struct MockExecutionEngine< MAX_EXTRA_DATA_BYTES, MAX_BYTES_PER_TRANSACTION, MAX_TRANSACTIONS_PER_PAYLOAD, - MAX_WITHDRAWALS_PER_PAYLOAD + MAX_WITHDRAWALS_PER_PAYLOAD, >, ) -> state_transition::Result<()>, > { @@ -228,7 +228,7 @@ impl< MAX_EXTRA_DATA_BYTES, MAX_BYTES_PER_TRANSACTION, MAX_TRANSACTIONS_PER_PAYLOAD, - MAX_WITHDRAWALS_PER_PAYLOAD + MAX_WITHDRAWALS_PER_PAYLOAD, >, ) -> state_transition::Result<()>, > diff --git a/src/capella/mod.rs b/src/capella/mod.rs index 57413b818..7bf526baf 100644 --- a/src/capella/mod.rs +++ b/src/capella/mod.rs @@ -4,26 +4,24 @@ mod beacon_block; mod beacon_state; mod blinded_beacon_block; -mod execution; -mod withdrawal; mod bls_to_execution_change; +mod execution; mod presets; +mod withdrawal; pub use beacon_block::*; pub use beacon_state::*; pub use blinded_beacon_block::*; -pub use execution::*; pub use bls_to_execution_change::*; +pub use execution::*; pub use presets::Preset; -pub use crate::bellatrix::{ - Transaction -}; pub use crate::altair::{ SyncAggregate, SyncAggregatorSelectionData, SyncCommittee, PARTICIPATION_FLAG_WEIGHTS, PROPOSER_WEIGHT, SYNC_REWARD_WEIGHT, TIMELY_HEAD_FLAG_INDEX, TIMELY_SOURCE_FLAG_INDEX, TIMELY_TARGET_FLAG_INDEX, WEIGHT_DENOMINATOR, }; +pub use crate::bellatrix::Transaction; pub use crate::phase0::{ Attestation, AttestationData, AttesterSlashing, BeaconBlockHeader, Checkpoint, Deposit, DepositData, DepositMessage, Eth1Block, Eth1Data, Fork, ForkData, HistoricalBatchAccumulator, diff --git a/src/capella/presets/mainnet.rs b/src/capella/presets/mainnet.rs index c961eb9ba..5d97401ea 100644 --- a/src/capella/presets/mainnet.rs +++ b/src/capella/presets/mainnet.rs @@ -5,8 +5,11 @@ pub use crate::altair::mainnet::{ SignedContributionAndProof, SyncAggregate, SyncCommittee, SyncCommitteeContribution, SyncCommitteeMessage, }; -pub use crate::bellatrix::mainnet::{BYTES_PER_LOGS_BLOOM, MAX_BYTES_PER_TRANSACTION, MAX_EXTRA_DATA_BYTES, MAX_TRANSACTIONS_PER_PAYLOAD, PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX}; pub use crate::bellatrix::mainnet::Transaction; +pub use crate::bellatrix::mainnet::{ + BYTES_PER_LOGS_BLOOM, MAX_BYTES_PER_TRANSACTION, MAX_EXTRA_DATA_BYTES, + MAX_TRANSACTIONS_PER_PAYLOAD, PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX, +}; use crate::capella; use crate::capella::presets::Preset; pub use crate::phase0::mainnet::{ @@ -20,12 +23,12 @@ pub use capella::*; pub const MAX_WITHDRAWALS_PER_PAYLOAD: usize = 16; pub const MAX_BLS_TO_EXECUTION_CHANGES: usize = 16; -pub const MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP: usize =16384; +pub const MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP: usize = 16384; pub const PRESET: Preset = Preset { max_bls_to_execution_changes: MAX_BLS_TO_EXECUTION_CHANGES, max_withdrawals_per_payload: MAX_WITHDRAWALS_PER_PAYLOAD, - max_validators_per_withdrawals_sweep: MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP + max_validators_per_withdrawals_sweep: MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP, }; pub type ExecutionPayload = capella::ExecutionPayload< @@ -159,7 +162,7 @@ pub type NoOpExecutionEngine = capella::NoOpExecutionEngine< MAX_EXTRA_DATA_BYTES, MAX_BYTES_PER_TRANSACTION, MAX_TRANSACTIONS_PER_PAYLOAD, - MAX_WITHDRAWALS_PER_PAYLOAD + MAX_WITHDRAWALS_PER_PAYLOAD, >; pub type MockExecutionEngine = capella::MockExecutionEngine< diff --git a/src/capella/presets/minimal.rs b/src/capella/presets/minimal.rs index 572222e4f..07c7b450a 100644 --- a/src/capella/presets/minimal.rs +++ b/src/capella/presets/minimal.rs @@ -5,8 +5,11 @@ pub use crate::altair::minimal::{ SignedContributionAndProof, SyncAggregate, SyncCommittee, SyncCommitteeContribution, SyncCommitteeMessage, }; -pub use crate::bellatrix::minimal::{BYTES_PER_LOGS_BLOOM, MAX_BYTES_PER_TRANSACTION, MAX_EXTRA_DATA_BYTES, MAX_TRANSACTIONS_PER_PAYLOAD, PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX}; pub use crate::bellatrix::minimal::Transaction; +pub use crate::bellatrix::minimal::{ + BYTES_PER_LOGS_BLOOM, MAX_BYTES_PER_TRANSACTION, MAX_EXTRA_DATA_BYTES, + MAX_TRANSACTIONS_PER_PAYLOAD, PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX, +}; use crate::capella; use crate::capella::presets::Preset; pub use crate::phase0::minimal::{ @@ -20,12 +23,12 @@ pub use capella::*; pub const MAX_WITHDRAWALS_PER_PAYLOAD: usize = 16; pub const MAX_BLS_TO_EXECUTION_CHANGES: usize = 16; -pub const MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP: usize =16384; +pub const MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP: usize = 16384; pub const PRESET: Preset = Preset { max_bls_to_execution_changes: MAX_BLS_TO_EXECUTION_CHANGES, max_withdrawals_per_payload: MAX_WITHDRAWALS_PER_PAYLOAD, - max_validators_per_withdrawals_sweep: MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP + max_validators_per_withdrawals_sweep: MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP, }; pub type ExecutionPayload = capella::ExecutionPayload< @@ -159,7 +162,7 @@ pub type NoOpExecutionEngine = capella::NoOpExecutionEngine< MAX_EXTRA_DATA_BYTES, MAX_BYTES_PER_TRANSACTION, MAX_TRANSACTIONS_PER_PAYLOAD, - MAX_WITHDRAWALS_PER_PAYLOAD + MAX_WITHDRAWALS_PER_PAYLOAD, >; pub type MockExecutionEngine = capella::MockExecutionEngine< From bac74691418d600dbdd1c2e26fd43fd61a5fe0c4 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Sat, 14 Jan 2023 09:45:15 +1100 Subject: [PATCH 04/10] Fix incorrect config values in minimal preset --- src/capella/presets/minimal.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/capella/presets/minimal.rs b/src/capella/presets/minimal.rs index 07c7b450a..41ae0eb5d 100644 --- a/src/capella/presets/minimal.rs +++ b/src/capella/presets/minimal.rs @@ -21,9 +21,9 @@ pub use crate::phase0::minimal::{ pub use capella::*; -pub const MAX_WITHDRAWALS_PER_PAYLOAD: usize = 16; +pub const MAX_WITHDRAWALS_PER_PAYLOAD: usize = 4; pub const MAX_BLS_TO_EXECUTION_CHANGES: usize = 16; -pub const MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP: usize = 16384; +pub const MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP: usize = 16; pub const PRESET: Preset = Preset { max_bls_to_execution_changes: MAX_BLS_TO_EXECUTION_CHANGES, From d17c5bad255fabce98786be16575e7ef0bef26f1 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Mon, 16 Jan 2023 17:13:13 +1100 Subject: [PATCH 05/10] Unify HistoricalSummary with existing HistoricalBatchAccumulator utility --- src/altair/mod.rs | 2 +- src/altair/state_transition/epoch_processing.rs | 8 ++++---- src/bellatrix/mod.rs | 2 +- src/bellatrix/state_transition/epoch_processing.rs | 8 ++++---- src/capella/beacon_state.rs | 9 +-------- src/capella/mod.rs | 2 +- src/phase0/beacon_state.rs | 12 ++++++------ src/phase0/epoch_processing.rs | 8 ++++---- 8 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/altair/mod.rs b/src/altair/mod.rs index c5dc5c963..7fa3f74cc 100644 --- a/src/altair/mod.rs +++ b/src/altair/mod.rs @@ -29,7 +29,7 @@ pub use validator::*; pub use crate::phase0::{ Attestation, AttestationData, AttesterSlashing, BeaconBlockHeader, Checkpoint, Deposit, - DepositData, DepositMessage, Eth1Block, Eth1Data, Fork, ForkData, HistoricalBatchAccumulator, + DepositData, DepositMessage, Eth1Block, Eth1Data, Fork, ForkData, HistoricalSummary, IndexedAttestation, ProposerSlashing, SignedBeaconBlockHeader, SignedVoluntaryExit, SigningData, Validator, VoluntaryExit, BASE_REWARDS_PER_EPOCH, DEPOSIT_CONTRACT_TREE_DEPTH, JUSTIFICATION_BITS_LENGTH, diff --git a/src/altair/state_transition/epoch_processing.rs b/src/altair/state_transition/epoch_processing.rs index 52af8a298..e764b5661 100644 --- a/src/altair/state_transition/epoch_processing.rs +++ b/src/altair/state_transition/epoch_processing.rs @@ -14,7 +14,7 @@ use spec::{ compute_activation_exit_epoch, get_block_root, get_current_epoch, get_previous_epoch, get_randao_mix, get_validator_churn_limit, initiate_validator_exit, is_active_validator, is_eligible_for_activation, is_eligible_for_activation_queue, BeaconState, Checkpoint, - HistoricalBatchAccumulator, JUSTIFICATION_BITS_LENGTH, + HistoricalSummary, JUSTIFICATION_BITS_LENGTH, }; use ssz_rs::prelude::*; @@ -182,9 +182,9 @@ pub fn process_historical_roots_update< let next_epoch = get_current_epoch(state, context) + 1; let epochs_per_historical_root = context.slots_per_historical_root / context.slots_per_epoch; if next_epoch % epochs_per_historical_root == 0 { - let mut historical_batch = HistoricalBatchAccumulator { - block_roots_root: state.block_roots.hash_tree_root()?, - state_roots_root: state.state_roots.hash_tree_root()?, + let mut historical_batch = HistoricalSummary { + block_summary_root: state.block_roots.hash_tree_root()?, + state_summary_root: state.state_roots.hash_tree_root()?, }; state .historical_roots diff --git a/src/bellatrix/mod.rs b/src/bellatrix/mod.rs index ee25b7308..c501d1cb9 100644 --- a/src/bellatrix/mod.rs +++ b/src/bellatrix/mod.rs @@ -35,7 +35,7 @@ pub use crate::altair::{ }; pub use crate::phase0::{ Attestation, AttestationData, AttesterSlashing, BeaconBlockHeader, Checkpoint, Deposit, - DepositData, DepositMessage, Eth1Block, Eth1Data, Fork, ForkData, HistoricalBatchAccumulator, + DepositData, DepositMessage, Eth1Block, Eth1Data, Fork, ForkData, HistoricalSummary, IndexedAttestation, ProposerSlashing, SignedBeaconBlockHeader, SignedVoluntaryExit, SigningData, Validator, VoluntaryExit, BASE_REWARDS_PER_EPOCH, DEPOSIT_CONTRACT_TREE_DEPTH, JUSTIFICATION_BITS_LENGTH, diff --git a/src/bellatrix/state_transition/epoch_processing.rs b/src/bellatrix/state_transition/epoch_processing.rs index bf144f55c..e63551ad8 100644 --- a/src/bellatrix/state_transition/epoch_processing.rs +++ b/src/bellatrix/state_transition/epoch_processing.rs @@ -11,7 +11,7 @@ use spec::{ get_next_sync_committee, get_previous_epoch, get_randao_mix, get_total_active_balance, get_total_balance, get_unslashed_participating_indices, get_validator_churn_limit, increase_balance, initiate_validator_exit, is_active_validator, is_eligible_for_activation, - is_eligible_for_activation_queue, BeaconState, Checkpoint, HistoricalBatchAccumulator, + is_eligible_for_activation_queue, BeaconState, Checkpoint, HistoricalSummary, JUSTIFICATION_BITS_LENGTH, PARTICIPATION_FLAG_WEIGHTS, TIMELY_TARGET_FLAG_INDEX, }; use ssz_rs::prelude::*; @@ -262,9 +262,9 @@ pub fn process_historical_roots_update< let next_epoch = get_current_epoch(state, context) + 1; let epochs_per_historical_root = context.slots_per_historical_root / context.slots_per_epoch; if next_epoch % epochs_per_historical_root == 0 { - let mut historical_batch = HistoricalBatchAccumulator { - block_roots_root: state.block_roots.hash_tree_root()?, - state_roots_root: state.state_roots.hash_tree_root()?, + let mut historical_batch = HistoricalSummary { + block_summary_root: state.block_roots.hash_tree_root()?, + state_summary_root: state.state_roots.hash_tree_root()?, }; state .historical_roots diff --git a/src/capella/beacon_state.rs b/src/capella/beacon_state.rs index 44a23d549..a752d1a32 100644 --- a/src/capella/beacon_state.rs +++ b/src/capella/beacon_state.rs @@ -1,5 +1,5 @@ use crate::altair::SyncCommittee; -use crate::capella::ExecutionPayloadHeader; +use crate::capella::{ExecutionPayloadHeader, HistoricalSummary}; use crate::phase0::{ BeaconBlockHeader, Checkpoint, Eth1Data, Fork, Validator, JUSTIFICATION_BITS_LENGTH, }; @@ -66,10 +66,3 @@ pub struct BeaconState< pub next_withdrawal_validator_index: ValidatorIndex, pub historical_summaries: List, } - -#[derive(Default, Debug, SimpleSerialize, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct HistoricalSummary { - pub block_summary_root: Root, - pub state_summary_root: Root, -} diff --git a/src/capella/mod.rs b/src/capella/mod.rs index 7bf526baf..7bf3f7fe7 100644 --- a/src/capella/mod.rs +++ b/src/capella/mod.rs @@ -24,7 +24,7 @@ pub use crate::altair::{ pub use crate::bellatrix::Transaction; pub use crate::phase0::{ Attestation, AttestationData, AttesterSlashing, BeaconBlockHeader, Checkpoint, Deposit, - DepositData, DepositMessage, Eth1Block, Eth1Data, Fork, ForkData, HistoricalBatchAccumulator, + DepositData, DepositMessage, Eth1Block, Eth1Data, Fork, ForkData, HistoricalSummary, IndexedAttestation, ProposerSlashing, SignedBeaconBlockHeader, SignedVoluntaryExit, SigningData, Validator, VoluntaryExit, BASE_REWARDS_PER_EPOCH, DEPOSIT_CONTRACT_TREE_DEPTH, JUSTIFICATION_BITS_LENGTH, diff --git a/src/phase0/beacon_state.rs b/src/phase0/beacon_state.rs index 505b8bdd0..2c40b6580 100644 --- a/src/phase0/beacon_state.rs +++ b/src/phase0/beacon_state.rs @@ -31,19 +31,19 @@ pub struct HistoricalBatch { /// being of type `Vector`, a single `Root` is pulled out to allow Merkleization of each root to be /// performed manually (using the `ssz_rs` crate). /// -/// Instead of requiring a full copy of the roots, the container is summarized as `HistoricalBatchAccumulator` -/// with `block_roots_root` & `state_roots_root`. +/// Instead of requiring a full copy of the roots, the container is summarized as `HistoricalSummary` +/// with `block_summary_root` & `state_summary_root`. /// /// This design decision was chosen for memory optimization purposes, for example, in the /// `state_transition` crate's `process_historical_roots_update` function. Also note that the /// `HistoricalBatch` container has no need for serialization, otherwise, this design would pose an issue. /// /// For more information, see the comment here: -#[derive(Default, Debug, SimpleSerialize)] +#[derive(Default, Debug, SimpleSerialize, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct HistoricalBatchAccumulator { - pub block_roots_root: Root, - pub state_roots_root: Root, +pub struct HistoricalSummary { + pub block_summary_root: Root, + pub state_summary_root: Root, } #[derive(Default, Debug, SimpleSerialize, Clone, PartialEq, Eq)] diff --git a/src/phase0/epoch_processing.rs b/src/phase0/epoch_processing.rs index 2099259e3..5e4dd0959 100644 --- a/src/phase0/epoch_processing.rs +++ b/src/phase0/epoch_processing.rs @@ -8,7 +8,7 @@ use spec::{ get_block_root_at_slot, get_current_epoch, get_eligible_validator_indices, get_previous_epoch, get_randao_mix, get_total_active_balance, get_total_balance, get_validator_churn_limit, increase_balance, initiate_validator_exit, is_active_validator, is_eligible_for_activation, - is_eligible_for_activation_queue, BeaconState, Checkpoint, HistoricalBatchAccumulator, + is_eligible_for_activation_queue, BeaconState, Checkpoint, HistoricalSummary, PendingAttestation, BASE_REWARDS_PER_EPOCH, JUSTIFICATION_BITS_LENGTH, }; use ssz_rs::prelude::*; @@ -508,9 +508,9 @@ pub fn process_historical_roots_update< let next_epoch = get_current_epoch(state, context) + 1; let epochs_per_historical_root = context.slots_per_historical_root / context.slots_per_epoch; if next_epoch % epochs_per_historical_root == 0 { - let mut historical_batch = HistoricalBatchAccumulator { - block_roots_root: state.block_roots.hash_tree_root()?, - state_roots_root: state.state_roots.hash_tree_root()?, + let mut historical_batch = HistoricalSummary { + block_summary_root: state.block_roots.hash_tree_root()?, + state_summary_root: state.state_roots.hash_tree_root()?, }; state .historical_roots From b658e6c4edb1f872d87ea1644a91c9cf998bf504 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Tue, 17 Jan 2023 02:05:26 +1100 Subject: [PATCH 06/10] Formatting fix only --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index fa059dc6e..41c1f2283 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,8 @@ pub mod altair; pub mod bellatrix; -pub mod capella; pub mod builder; pub(crate) mod bytes; +pub mod capella; pub mod clock; pub mod configs; pub mod crypto; From 835b48bcdecfe06e2927c15e3e780b9456c95bd5 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Thu, 19 Jan 2023 22:53:39 +1100 Subject: [PATCH 07/10] Add missing serde annotations Co-authored-by: Alex Stokes --- src/capella/withdrawal.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/capella/withdrawal.rs b/src/capella/withdrawal.rs index b5e1473e5..eb915e6cd 100644 --- a/src/capella/withdrawal.rs +++ b/src/capella/withdrawal.rs @@ -4,8 +4,11 @@ use ssz_rs::prelude::*; #[derive(Default, Debug, Clone, SimpleSerialize, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Withdrawal { + #[serde(with = "crate::serde::as_string")] pub index: WithdrawalIndex, + #[serde(with = "crate::serde::as_string")] pub validator_index: ValidatorIndex, pub address: ExecutionAddress, + #[serde(with = "crate::serde::as_string")] pub amount: Gwei, } From 8bbc7cc65cb57640a1374b1f687e1fdb137aa5c4 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Thu, 19 Jan 2023 22:53:55 +1100 Subject: [PATCH 08/10] Add missing serde annotations Co-authored-by: Alex Stokes --- src/capella/bls_to_execution_change.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/capella/bls_to_execution_change.rs b/src/capella/bls_to_execution_change.rs index 0af1dd528..10f094ab8 100644 --- a/src/capella/bls_to_execution_change.rs +++ b/src/capella/bls_to_execution_change.rs @@ -4,6 +4,7 @@ use ssz_rs::prelude::*; #[derive(Default, Debug, Clone, SimpleSerialize, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct BlsToExecutionChange { + #[serde(with = "crate::serde::as_string")] pub validator_index: ValidatorIndex, #[serde(rename = "from_bls_pubkey")] pub from_bls_public_key: BlsPublicKey, From 7336b29c4dfa3721718d505b8bc98ad4ce5bf3b3 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Fri, 27 Jan 2023 12:24:43 +0100 Subject: [PATCH 09/10] Update src/capella/beacon_state.rs --- src/capella/beacon_state.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/capella/beacon_state.rs b/src/capella/beacon_state.rs index a752d1a32..4e272ee10 100644 --- a/src/capella/beacon_state.rs +++ b/src/capella/beacon_state.rs @@ -62,7 +62,9 @@ pub struct BeaconState< MAX_BYTES_PER_TRANSACTION, MAX_TRANSACTIONS_PER_PAYLOAD, >, + #[serde(with = "crate::serde::as_string")] pub next_withdrawal_index: WithdrawalIndex, + #[serde(with = "crate::serde::as_string")] pub next_withdrawal_validator_index: ValidatorIndex, pub historical_summaries: List, } From 0ddce7f3e12527ba77922ad05e7602f3402d0838 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Fri, 27 Jan 2023 12:52:29 +0100 Subject: [PATCH 10/10] Fix lint with extra space from GH suggestion --- src/capella/beacon_state.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/capella/beacon_state.rs b/src/capella/beacon_state.rs index 4e272ee10..01dd5eae7 100644 --- a/src/capella/beacon_state.rs +++ b/src/capella/beacon_state.rs @@ -62,9 +62,9 @@ pub struct BeaconState< MAX_BYTES_PER_TRANSACTION, MAX_TRANSACTIONS_PER_PAYLOAD, >, - #[serde(with = "crate::serde::as_string")] + #[serde(with = "crate::serde::as_string")] pub next_withdrawal_index: WithdrawalIndex, - #[serde(with = "crate::serde::as_string")] + #[serde(with = "crate::serde::as_string")] pub next_withdrawal_validator_index: ValidatorIndex, pub historical_summaries: List, }