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

Add Capella types and presets #168

Merged
merged 13 commits into from
Jan 27, 2023
2 changes: 1 addition & 1 deletion src/altair/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/altair/state_transition/epoch_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/bellatrix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/bellatrix/state_transition/epoch_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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
Expand Down
119 changes: 119 additions & 0 deletions src/capella/beacon_block.rs
Original file line number Diff line number Diff line change
@@ -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<ProposerSlashing, MAX_PROPOSER_SLASHINGS>,
pub attester_slashings:
List<AttesterSlashing<MAX_VALIDATORS_PER_COMMITTEE>, MAX_ATTESTER_SLASHINGS>,
pub attestations: List<Attestation<MAX_VALIDATORS_PER_COMMITTEE>, MAX_ATTESTATIONS>,
pub deposits: List<Deposit, MAX_DEPOSITS>,
pub voluntary_exits: List<SignedVoluntaryExit, MAX_VOLUNTARY_EXITS>,
pub sync_aggregate: SyncAggregate<SYNC_COMMITTEE_SIZE>,
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<SignedBlsToExecutionChange, MAX_BLS_TO_EXECUTION_CHANGES>,
}

#[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,
}
68 changes: 68 additions & 0 deletions src/capella/beacon_state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use crate::altair::SyncCommittee;
use crate::capella::{ExecutionPayloadHeader, HistoricalSummary};
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<Root, SLOTS_PER_HISTORICAL_ROOT>,
pub state_roots: Vector<Root, SLOTS_PER_HISTORICAL_ROOT>,
pub historical_roots: List<Root, HISTORICAL_ROOTS_LIMIT>,
pub eth1_data: Eth1Data,
pub eth1_data_votes: List<Eth1Data, ETH1_DATA_VOTES_BOUND>,
#[serde(with = "crate::serde::as_string")]
pub eth1_deposit_index: u64,
pub validators: List<Validator, VALIDATOR_REGISTRY_LIMIT>,
#[serde(with = "crate::serde::collection_over_string")]
pub balances: List<Gwei, VALIDATOR_REGISTRY_LIMIT>,
pub randao_mixes: Vector<Bytes32, EPOCHS_PER_HISTORICAL_VECTOR>,
#[serde(with = "crate::serde::collection_over_string")]
pub slashings: Vector<Gwei, EPOCHS_PER_SLASHINGS_VECTOR>,
#[serde(with = "crate::serde::collection_over_string")]
pub previous_epoch_participation: List<ParticipationFlags, VALIDATOR_REGISTRY_LIMIT>,
#[serde(with = "crate::serde::collection_over_string")]
pub current_epoch_participation: List<ParticipationFlags, VALIDATOR_REGISTRY_LIMIT>,
pub justification_bits: Bitvector<JUSTIFICATION_BITS_LENGTH>,
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<u64, VALIDATOR_REGISTRY_LIMIT>,
pub current_sync_committee: SyncCommittee<SYNC_COMMITTEE_SIZE>,
pub next_sync_committee: SyncCommittee<SYNC_COMMITTEE_SIZE>,
pub latest_execution_payload_header: ExecutionPayloadHeader<
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
ralexstokes marked this conversation as resolved.
Show resolved Hide resolved
>,
pub next_withdrawal_index: WithdrawalIndex,
pub next_withdrawal_validator_index: ValidatorIndex,
ralexstokes marked this conversation as resolved.
Show resolved Hide resolved
pub historical_summaries: List<HistoricalSummary, HISTORICAL_ROOTS_LIMIT>,
}
118 changes: 118 additions & 0 deletions src/capella/blinded_beacon_block.rs
Original file line number Diff line number Diff line change
@@ -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<ProposerSlashing, MAX_PROPOSER_SLASHINGS>,
pub attester_slashings:
List<AttesterSlashing<MAX_VALIDATORS_PER_COMMITTEE>, MAX_ATTESTER_SLASHINGS>,
pub attestations: List<Attestation<MAX_VALIDATORS_PER_COMMITTEE>, MAX_ATTESTATIONS>,
pub deposits: List<Deposit, MAX_DEPOSITS>,
pub voluntary_exits: List<SignedVoluntaryExit, MAX_VOLUNTARY_EXITS>,
pub sync_aggregate: SyncAggregate<SYNC_COMMITTEE_SIZE>,
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<SignedBlsToExecutionChange, MAX_BLS_TO_EXECUTION_CHANGES>,
}

#[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,
}
18 changes: 18 additions & 0 deletions src/capella/bls_to_execution_change.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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))]
pub struct BlsToExecutionChange {
pub validator_index: ValidatorIndex,
jimmygchen marked this conversation as resolved.
Show resolved Hide resolved
#[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,
}
Loading