merge with capella

This commit is contained in:
realbigsean
2022-12-15 09:33:18 -05:00
95 changed files with 3783 additions and 539 deletions

View File

@@ -51,6 +51,7 @@ pub mod graffiti;
pub mod historical_batch;
pub mod indexed_attestation;
pub mod light_client_bootstrap;
pub mod light_client_finality_update;
pub mod light_client_optimistic_update;
pub mod light_client_update;
pub mod pending_attestation;
@@ -149,6 +150,10 @@ pub use crate::free_attestation::FreeAttestation;
pub use crate::graffiti::{Graffiti, GRAFFITI_BYTES_LEN};
pub use crate::historical_batch::HistoricalBatch;
pub use crate::indexed_attestation::IndexedAttestation;
pub use crate::kzg_commitment::KzgCommitment;
pub use crate::kzg_proof::KzgProof;
pub use crate::light_client_finality_update::LightClientFinalityUpdate;
pub use crate::light_client_optimistic_update::LightClientOptimisticUpdate;
pub use crate::participation_flags::ParticipationFlags;
pub use crate::participation_list::ParticipationList;
pub use crate::payload::{

View File

@@ -1,10 +1,10 @@
use super::{BeaconBlockHeader, EthSpec, FixedVector, Hash256, Slot, SyncAggregate, SyncCommittee};
use crate::{light_client_update::*, test_utils::TestRandom, BeaconBlock, BeaconState, ChainSpec};
use safe_arith::ArithError;
use super::{
BeaconBlockHeader, EthSpec, FixedVector, Hash256, SignedBeaconBlock, SignedBlindedBeaconBlock,
Slot, SyncAggregate,
};
use crate::{light_client_update::*, test_utils::TestRandom, BeaconState, ChainSpec};
use serde_derive::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
use ssz_types::typenum::{U5, U6};
use std::sync::Arc;
use test_random_derive::TestRandom;
use tree_hash::TreeHash;
@@ -28,43 +28,38 @@ pub struct LightClientFinalityUpdate<T: EthSpec> {
impl<T: EthSpec> LightClientFinalityUpdate<T> {
pub fn new(
chain_spec: ChainSpec,
beacon_state: BeaconState<T>,
block: BeaconBlock<T>,
chain_spec: &ChainSpec,
beacon_state: &BeaconState<T>,
block: &SignedBeaconBlock<T>,
attested_state: &mut BeaconState<T>,
finalized_block: BeaconBlock<T>,
finalized_block: &SignedBlindedBeaconBlock<T>,
) -> Result<Self, Error> {
let altair_fork_epoch = chain_spec
.altair_fork_epoch
.ok_or(Error::AltairForkNotActive)?;
if attested_state.slot().epoch(T::slots_per_epoch()) < altair_fork_epoch {
if beacon_state.slot().epoch(T::slots_per_epoch()) < altair_fork_epoch {
return Err(Error::AltairForkNotActive);
}
let sync_aggregate = block.body().sync_aggregate()?;
let sync_aggregate = block.message().body().sync_aggregate()?;
if sync_aggregate.num_set_bits() < chain_spec.min_sync_committee_participants as usize {
return Err(Error::NotEnoughSyncCommitteeParticipants);
}
// Compute and validate attested header.
let mut attested_header = attested_state.latest_block_header().clone();
attested_header.state_root = attested_state.tree_hash_root();
attested_header.state_root = attested_state.update_tree_hash_cache()?;
// Build finalized header from finalized block
let finalized_header = BeaconBlockHeader {
slot: finalized_block.slot(),
proposer_index: finalized_block.proposer_index(),
parent_root: finalized_block.parent_root(),
state_root: finalized_block.state_root(),
body_root: finalized_block.body_root(),
};
let finalized_header = finalized_block.message().block_header();
if finalized_header.tree_hash_root() != beacon_state.finalized_checkpoint().root {
return Err(Error::InvalidFinalizedBlock);
}
let finality_branch = attested_state.compute_merkle_proof(FINALIZED_ROOT_INDEX)?;
Ok(Self {
attested_header: attested_header,
finalized_header: finalized_header,
attested_header,
finalized_header,
finality_branch: FixedVector::new(finality_branch)?,
sync_aggregate: sync_aggregate.clone(),
signature_slot: block.slot(),

View File

@@ -1,6 +1,6 @@
use super::{BeaconBlockHeader, EthSpec, Slot, SyncAggregate};
use crate::{
light_client_update::Error, test_utils::TestRandom, BeaconBlock, BeaconState, ChainSpec,
light_client_update::Error, test_utils::TestRandom, BeaconState, ChainSpec, SignedBeaconBlock,
};
use serde_derive::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
@@ -23,9 +23,9 @@ pub struct LightClientOptimisticUpdate<T: EthSpec> {
impl<T: EthSpec> LightClientOptimisticUpdate<T> {
pub fn new(
chain_spec: ChainSpec,
block: BeaconBlock<T>,
attested_state: BeaconState<T>,
chain_spec: &ChainSpec,
block: &SignedBeaconBlock<T>,
attested_state: &BeaconState<T>,
) -> Result<Self, Error> {
let altair_fork_epoch = chain_spec
.altair_fork_epoch
@@ -34,7 +34,7 @@ impl<T: EthSpec> LightClientOptimisticUpdate<T> {
return Err(Error::AltairForkNotActive);
}
let sync_aggregate = block.body().sync_aggregate()?;
let sync_aggregate = block.message().body().sync_aggregate()?;
if sync_aggregate.num_set_bits() < chain_spec.min_sync_committee_participants as usize {
return Err(Error::NotEnoughSyncCommitteeParticipants);
}

View File

@@ -261,7 +261,7 @@ impl<T: EthSpec> ExecPayload<T> for FullPayload<T> {
})
}
fn is_default_with_empty_roots<'a>(&'a self) -> bool {
fn is_default_with_empty_roots(&self) -> bool {
// For full payloads the empty/zero distinction does not exist.
self.is_default_with_zero_roots()
}
@@ -536,7 +536,7 @@ impl<T: EthSpec> ExecPayload<T> for BlindedPayload<T> {
}
}
fn is_default_with_zero_roots<'a>(&'a self) -> bool {
fn is_default_with_zero_roots(&self) -> bool {
self.to_ref().is_default_with_zero_roots()
}
@@ -643,13 +643,13 @@ impl<'b, T: EthSpec> ExecPayload<T> for BlindedPayloadRef<'b, T> {
}
macro_rules! impl_exec_payload_common {
($wrapper_type:ident,
$wrapped_type:ident,
$wrapped_type_full:ident,
$wrapped_type_header:ident,
$wrapped_field:ident,
$fork_variant:ident,
$block_type_variant:ident,
($wrapper_type:ident, // BlindedPayloadMerge | FullPayloadMerge
$wrapped_type:ident, // ExecutionPayloadHeaderMerge | ExecutionPayloadMerge
$wrapped_type_full:ident, // ExecutionPayloadMerge | ExecutionPayloadMerge
$wrapped_type_header:ident, // ExecutionPayloadHeaderMerge | ExecutionPayloadHeaderMerge
$wrapped_field:ident, // execution_payload_header | execution_payload
$fork_variant:ident, // Merge | Merge
$block_type_variant:ident, // Blinded | Full
$f:block,
$g:block) => {
impl<T: EthSpec> ExecPayload<T> for $wrapper_type<T> {
@@ -696,7 +696,15 @@ macro_rules! impl_exec_payload_common {
}
fn is_default_with_empty_roots(&self) -> bool {
self.$wrapped_field == $wrapped_type::from($wrapped_type_full::default())
// FIXME: is there a better way than ignoring this lint?
// This is necessary because the first invocation of this macro might expand to:
// self.execution_payload_header == ExecutionPayloadHeaderMerge::from(ExecutionPayloadMerge::default())
// but the second invocation might expand to:
// self.execution_payload == ExecutionPayloadMerge::from(ExecutionPayloadMerge::default())
#[allow(clippy::cmp_owned)]
{
self.$wrapped_field == $wrapped_type::from($wrapped_type_full::default())
}
}
fn transactions(&self) -> Option<&Transactions<T>> {
@@ -720,16 +728,17 @@ macro_rules! impl_exec_payload_common {
}
macro_rules! impl_exec_payload_for_fork {
// BlindedPayloadMerge, FullPayloadMerge, ExecutionPayloadHeaderMerge, ExecutionPayloadMerge, Merge
($wrapper_type_header:ident, $wrapper_type_full:ident, $wrapped_type_header:ident, $wrapped_type_full:ident, $fork_variant:ident) => {
//*************** Blinded payload implementations ******************//
impl_exec_payload_common!(
$wrapper_type_header,
$wrapped_type_header,
$wrapped_type_full,
$wrapped_type_header,
$wrapper_type_header, // BlindedPayloadMerge
$wrapped_type_header, // ExecutionPayloadHeaderMerge
$wrapped_type_full, // ExecutionPayloadMerge
$wrapped_type_header, // ExecutionPayloadHeaderMerge
execution_payload_header,
$fork_variant,
$fork_variant, // Merge
Blinded,
{ |_| { None } },
{
@@ -794,12 +803,12 @@ macro_rules! impl_exec_payload_for_fork {
//*************** Full payload implementations ******************//
impl_exec_payload_common!(
$wrapper_type_full,
$wrapped_type_full,
$wrapped_type_full,
$wrapped_type_header,
$wrapper_type_full, // FullPayloadMerge
$wrapped_type_full, // ExecutionPayloadMerge
$wrapped_type_full, // ExecutionPayloadMerge
$wrapped_type_header, // ExecutionPayloadHeaderMerge
execution_payload,
$fork_variant,
$fork_variant, // Merge
Full,
{
let c: for<'a> fn(&'a $wrapper_type_full<T>) -> Option<&'a Transactions<T>> =

View File

@@ -12,8 +12,10 @@ use tree_hash_derive::TreeHash;
pub struct Withdrawal {
#[serde(with = "eth2_serde_utils::quoted_u64")]
pub index: u64,
#[serde(with = "eth2_serde_utils::quoted_u64")]
pub validator_index: u64,
pub address: Address,
#[serde(with = "eth2_serde_utils::quoted_u64")]
pub amount: u64,
}