merge upstream, fix compile errors

This commit is contained in:
realbigsean
2023-01-11 13:52:58 -05:00
100 changed files with 1304 additions and 505 deletions
+3 -3
View File
@@ -63,15 +63,15 @@ mod test {
#[test]
fn encoding() {
let bytes = vec![0, 255];
let hex = encode(&bytes);
let hex = encode(bytes);
assert_eq!(hex.as_str(), "0x00ff");
let bytes = vec![];
let hex = encode(&bytes);
let hex = encode(bytes);
assert_eq!(hex.as_str(), "0x");
let bytes = vec![1, 2, 3];
let hex = encode(&bytes);
let hex = encode(bytes);
assert_eq!(hex.as_str(), "0x010203");
}
}
+1 -1
View File
@@ -36,7 +36,7 @@ impl<'de> Visitor<'de> for QuantityVisitor {
} else if stripped.starts_with('0') {
Err(de::Error::custom("cannot have leading zero"))
} else if stripped.len() % 2 != 0 {
hex::decode(&format!("0{}", stripped))
hex::decode(format!("0{}", stripped))
.map_err(|e| de::Error::custom(format!("invalid hex ({:?})", e)))
} else {
hex::decode(stripped).map_err(|e| de::Error::custom(format!("invalid hex ({:?})", e)))
@@ -19,7 +19,6 @@ pub use process_operations::process_operations;
pub use verify_attestation::{
verify_attestation_for_block_inclusion, verify_attestation_for_state,
};
#[cfg(feature = "withdrawals-processing")]
pub use verify_bls_to_execution_change::verify_bls_to_execution_change;
pub use verify_deposit::{
get_existing_validator_index, verify_deposit_merkle_proof, verify_deposit_signature,
@@ -36,12 +35,13 @@ pub mod signature_sets;
pub mod tests;
mod verify_attestation;
mod verify_attester_slashing;
#[cfg(feature = "withdrawals-processing")]
mod verify_bls_to_execution_change;
mod verify_deposit;
mod verify_exit;
mod verify_proposer_slashing;
use crate::common::decrease_balance;
#[cfg(feature = "arbitrary-fuzz")]
use arbitrary::Arbitrary;
@@ -162,7 +162,6 @@ pub fn per_block_processing<T: EthSpec, Payload: AbstractExecPayload<T>>(
// previous block.
if is_execution_enabled(state, block.body()) {
let payload = block.body().execution_payload()?;
#[cfg(feature = "withdrawals-processing")]
process_withdrawals::<T, Payload>(state, payload, spec)?;
process_execution_payload::<T, Payload>(state, payload, spec)?;
}
@@ -524,12 +523,14 @@ pub fn get_expected_withdrawals<T: EthSpec>(
}
/// Apply withdrawals to the state.
#[cfg(feature = "withdrawals-processing")]
pub fn process_withdrawals<'payload, T: EthSpec, Payload: AbstractExecPayload<T>>(
state: &mut BeaconState<T>,
payload: Payload::Ref<'payload>,
spec: &ChainSpec,
) -> Result<(), BlockProcessingError> {
if cfg!(not(feature = "withdrawals-processing")) {
return Ok(());
}
match state {
BeaconState::Merge(_) => Ok(()),
BeaconState::Capella(_) | BeaconState::Eip4844(_) => {
@@ -52,10 +52,10 @@ pub fn process_sync_aggregate<T: EthSpec>(
.zip(aggregate.sync_committee_bits.iter())
{
if participation_bit {
increase_balance(state, participant_index as usize, participant_reward)?;
increase_balance(state, participant_index, participant_reward)?;
increase_balance(state, proposer_index as usize, proposer_reward)?;
} else {
decrease_balance(state, participant_index as usize, participant_reward)?;
decrease_balance(state, participant_index, participant_reward)?;
}
}
@@ -109,7 +109,7 @@ fn tx_peek_blob_versioned_hashes<T: EthSpec>(
.get(next_version_hash_index..next_version_hash_index.safe_add(32)?)
.ok_or(BlockProcessingError::BlobVersionHashIndexOutOfBounds {
length: tx_len,
index: (next_version_hash_index as usize).safe_add(32)?,
index: (next_version_hash_index).safe_add(32)?,
})?;
Ok(VersionedHash::from_slice(bytes))
}))
@@ -34,7 +34,6 @@ pub fn process_operations<'a, T: EthSpec, Payload: AbstractExecPayload<T>>(
process_deposits(state, block_body.deposits(), spec)?;
process_exits(state, block_body.voluntary_exits(), verify_signatures, spec)?;
#[cfg(feature = "withdrawals-processing")]
if let Ok(bls_to_execution_changes) = block_body.bls_to_execution_changes() {
process_bls_to_execution_changes(state, bls_to_execution_changes, verify_signatures, spec)?;
}
@@ -295,13 +294,15 @@ pub fn process_exits<T: EthSpec>(
///
/// Returns `Ok(())` if the validation and state updates completed successfully. Otherwise returns
/// an `Err` describing the invalid object or cause of failure.
#[cfg(feature = "withdrawals-processing")]
pub fn process_bls_to_execution_changes<T: EthSpec>(
state: &mut BeaconState<T>,
bls_to_execution_changes: &[SignedBlsToExecutionChange],
verify_signatures: VerifySignatures,
spec: &ChainSpec,
) -> Result<(), BlockProcessingError> {
if cfg!(not(feature = "withdrawals-processing")) {
return Ok(());
}
for (i, signed_address_change) in bls_to_execution_changes.iter().enumerate() {
verify_bls_to_execution_change(state, signed_address_change, verify_signatures, spec)
.map_err(|e| e.into_with_index(i))?;
@@ -3,14 +3,16 @@
pub use epoch_processing_summary::EpochProcessingSummary;
use errors::EpochProcessingError as Error;
pub use justification_and_finalization_state::JustificationAndFinalizationState;
pub use registry_updates::process_registry_updates;
use safe_arith::SafeArith;
pub use slashings::process_slashings;
use types::{BeaconState, ChainSpec, EthSpec};
pub use registry_updates::process_registry_updates;
pub use slashings::process_slashings;
pub use weigh_justification_and_finalization::weigh_justification_and_finalization;
pub mod altair;
pub mod base;
pub mod capella;
pub mod effective_balance_updates;
pub mod epoch_processing_summary;
pub mod errors;
@@ -37,10 +39,8 @@ pub fn process_epoch<T: EthSpec>(
match state {
BeaconState::Base(_) => base::process_epoch(state, spec),
BeaconState::Altair(_)
| BeaconState::Merge(_)
| BeaconState::Capella(_)
| BeaconState::Eip4844(_) => altair::process_epoch(state, spec),
BeaconState::Altair(_) | BeaconState::Merge(_) => altair::process_epoch(state, spec),
BeaconState::Capella(_) | BeaconState::Eip4844(_) => capella::process_epoch(state, spec),
}
}
@@ -76,7 +76,7 @@ pub fn get_flag_index_deltas<T: EthSpec>(
let base_reward = get_base_reward(state, index, base_reward_per_increment, spec)?;
let mut delta = Delta::default();
if unslashed_participating_indices.contains(index as usize)? {
if unslashed_participating_indices.contains(index)? {
if !state.is_in_inactivity_leak(previous_epoch, spec) {
let reward_numerator = base_reward
.safe_mul(weight)?
@@ -89,8 +89,8 @@ pub fn get_flag_index_deltas<T: EthSpec>(
delta.penalize(base_reward.safe_mul(weight)?.safe_div(WEIGHT_DENOMINATOR)?)?;
}
deltas
.get_mut(index as usize)
.ok_or(Error::DeltaOutOfBounds(index as usize))?
.get_mut(index)
.ok_or(Error::DeltaOutOfBounds(index))?
.combine(delta)?;
}
Ok(())
@@ -235,7 +235,7 @@ fn get_inclusion_delay_delta(
let max_attester_reward = base_reward.safe_sub(proposer_reward)?;
delta.reward(max_attester_reward.safe_div(inclusion_info.delay)?)?;
let proposer_index = inclusion_info.proposer_index as usize;
let proposer_index = inclusion_info.proposer_index;
Ok((delta, Some((proposer_index, proposer_delta))))
} else {
Ok((Delta::default(), None))
@@ -0,0 +1,78 @@
use super::altair::inactivity_updates::process_inactivity_updates;
use super::altair::justification_and_finalization::process_justification_and_finalization;
use super::altair::participation_cache::ParticipationCache;
use super::altair::participation_flag_updates::process_participation_flag_updates;
use super::altair::rewards_and_penalties::process_rewards_and_penalties;
use super::altair::sync_committee_updates::process_sync_committee_updates;
use super::{process_registry_updates, process_slashings, EpochProcessingSummary, Error};
use crate::per_epoch_processing::{
effective_balance_updates::process_effective_balance_updates,
resets::{process_eth1_data_reset, process_randao_mixes_reset, process_slashings_reset},
};
use types::{BeaconState, ChainSpec, EthSpec, RelativeEpoch};
pub use historical_summaries_update::process_historical_summaries_update;
mod historical_summaries_update;
pub fn process_epoch<T: EthSpec>(
state: &mut BeaconState<T>,
spec: &ChainSpec,
) -> Result<EpochProcessingSummary<T>, Error> {
// Ensure the committee caches are built.
state.build_committee_cache(RelativeEpoch::Previous, spec)?;
state.build_committee_cache(RelativeEpoch::Current, spec)?;
state.build_committee_cache(RelativeEpoch::Next, spec)?;
// Pre-compute participating indices and total balances.
let participation_cache = ParticipationCache::new(state, spec)?;
let sync_committee = state.current_sync_committee()?.clone();
// Justification and finalization.
let justification_and_finalization_state =
process_justification_and_finalization(state, &participation_cache)?;
justification_and_finalization_state.apply_changes_to_state(state);
process_inactivity_updates(state, &participation_cache, spec)?;
// Rewards and Penalties.
process_rewards_and_penalties(state, &participation_cache, spec)?;
// Registry Updates.
process_registry_updates(state, spec)?;
// Slashings.
process_slashings(
state,
participation_cache.current_epoch_total_active_balance(),
spec,
)?;
// Reset eth1 data votes.
process_eth1_data_reset(state)?;
// Update effective balances with hysteresis (lag).
process_effective_balance_updates(state, spec)?;
// Reset slashings
process_slashings_reset(state)?;
// Set randao mix
process_randao_mixes_reset(state)?;
// Set historical summaries accumulator
process_historical_summaries_update(state)?;
// Rotate current/previous epoch participation
process_participation_flag_updates(state)?;
process_sync_committee_updates(state, spec)?;
// Rotate the epoch caches to suit the epoch transition.
state.advance_caches(spec)?;
Ok(EpochProcessingSummary::Altair {
participation_cache,
sync_committee,
})
}
@@ -0,0 +1,23 @@
use crate::EpochProcessingError;
use safe_arith::SafeArith;
use types::historical_summary::HistoricalSummary;
use types::{BeaconState, EthSpec};
pub fn process_historical_summaries_update<T: EthSpec>(
state: &mut BeaconState<T>,
) -> Result<(), EpochProcessingError> {
// Set historical block root accumulator.
let next_epoch = state.next_epoch()?;
if next_epoch
.as_u64()
.safe_rem((T::slots_per_historical_root() as u64).safe_div(T::slots_per_epoch())?)?
== 0
{
let summary = HistoricalSummary::new(state);
return state
.historical_summaries_mut()?
.push(summary)
.map_err(Into::into);
}
Ok(())
}
@@ -1,3 +1,4 @@
use ssz_types::VariableList;
use std::mem;
use types::{BeaconState, BeaconStateCapella, BeaconStateError as Error, ChainSpec, EthSpec, Fork};
@@ -55,9 +56,10 @@ pub fn upgrade_to_capella<E: EthSpec>(
next_sync_committee: pre.next_sync_committee.clone(),
// Execution
latest_execution_payload_header: pre.latest_execution_payload_header.upgrade_to_capella(),
// Withdrawals
// Capella
next_withdrawal_index: 0,
next_withdrawal_validator_index: 0,
historical_summaries: VariableList::default(),
// Caches
total_active_balance: pre.total_active_balance,
committee_caches: mem::take(&mut pre.committee_caches),
@@ -57,9 +57,10 @@ pub fn upgrade_to_eip4844<E: EthSpec>(
next_sync_committee: pre.next_sync_committee.clone(),
// Execution
latest_execution_payload_header: pre.latest_execution_payload_header.upgrade_to_eip4844(),
// Withdrawals
// Capella
next_withdrawal_index: pre.next_withdrawal_index,
next_withdrawal_validator_index: pre.next_withdrawal_validator_index,
historical_summaries: pre.historical_summaries.clone(),
// Caches
total_active_balance: pre.total_active_balance,
committee_caches: mem::take(&mut pre.committee_caches),
@@ -1,8 +1,10 @@
use crate::per_block_processing::{
errors::{
AttesterSlashingValidationError, ExitValidationError, ProposerSlashingValidationError,
AttesterSlashingValidationError, BlsExecutionChangeValidationError, ExitValidationError,
ProposerSlashingValidationError,
},
verify_attester_slashing, verify_exit, verify_proposer_slashing,
verify_attester_slashing, verify_bls_to_execution_change, verify_exit,
verify_proposer_slashing,
};
use crate::VerifySignatures;
use derivative::Derivative;
@@ -12,15 +14,7 @@ use ssz_derive::{Decode, Encode};
use std::marker::PhantomData;
use types::{
AttesterSlashing, BeaconState, ChainSpec, Epoch, EthSpec, Fork, ForkVersion, ProposerSlashing,
SignedVoluntaryExit,
};
#[cfg(feature = "withdrawals-processing")]
use {
crate::per_block_processing::{
errors::BlsExecutionChangeValidationError, verify_bls_to_execution_change,
},
types::SignedBlsToExecutionChange,
SignedBlsToExecutionChange, SignedVoluntaryExit,
};
const MAX_FORKS_VERIFIED_AGAINST: usize = 2;
@@ -202,7 +196,6 @@ impl<E: EthSpec> VerifyOperation<E> for ProposerSlashing {
}
}
#[cfg(feature = "withdrawals-processing")]
impl<E: EthSpec> VerifyOperation<E> for SignedBlsToExecutionChange {
type Error = BlsExecutionChangeValidationError;
+8 -2
View File
@@ -14,6 +14,7 @@ use ssz::{ssz_encode, Decode, DecodeError, Encode};
use ssz_derive::{Decode, Encode};
use ssz_types::{typenum::Unsigned, BitVector, FixedVector};
use std::convert::TryInto;
use std::hash::Hash;
use std::{fmt, mem, sync::Arc};
use superstruct::superstruct;
use swap_or_not_shuffle::compute_shuffled_index;
@@ -25,6 +26,7 @@ pub use self::committee_cache::{
compute_committee_index_in_epoch, compute_committee_range_in_epoch, epoch_committee_count,
CommitteeCache,
};
use crate::historical_summary::HistoricalSummary;
pub use clone_config::CloneConfig;
pub use eth_spec::*;
pub use iter::BlockRootsIter;
@@ -223,6 +225,7 @@ where
pub block_roots: FixedVector<Hash256, T::SlotsPerHistoricalRoot>,
#[compare_fields(as_slice)]
pub state_roots: FixedVector<Hash256, T::SlotsPerHistoricalRoot>,
// Frozen in Capella, replaced by historical_summaries
pub historical_roots: VariableList<Hash256, T::HistoricalRootsLimit>,
// Ethereum 1.0 chain data
@@ -296,11 +299,14 @@ where
)]
pub latest_execution_payload_header: ExecutionPayloadHeaderEip4844<T>,
// Withdrawals
// Capella
#[superstruct(only(Capella, Eip4844), partial_getter(copy))]
pub next_withdrawal_index: u64,
#[superstruct(only(Capella, Eip4844), partial_getter(copy))]
pub next_withdrawal_validator_index: u64,
// Deep history valid from Capella onwards.
#[superstruct(only(Capella, Eip4844))]
pub historical_summaries: VariableList<HistoricalSummary, T::HistoricalRootsLimit>,
// Caching (not in the spec)
#[serde(skip_serializing, skip_deserializing)]
@@ -504,7 +510,7 @@ impl<T: EthSpec> BeaconState<T> {
/// Spec v0.12.1
pub fn get_committee_count_at_slot(&self, slot: Slot) -> Result<u64, Error> {
let cache = self.committee_cache_at_slot(slot)?;
Ok(cache.committees_per_slot() as u64)
Ok(cache.committees_per_slot())
}
/// Compute the number of committees in an entire epoch.
@@ -144,7 +144,7 @@ impl CommitteeCache {
self.committees_per_slot as usize,
index as usize,
);
let committee = self.compute_committee(committee_index as usize)?;
let committee = self.compute_committee(committee_index)?;
Some(BeaconCommittee {
slot,
+5 -15
View File
@@ -344,12 +344,7 @@ mod committees {
let cache_epoch = cache_epoch.into_epoch(state_epoch);
execute_committee_consistency_test(
new_head_state,
cache_epoch,
validator_count as usize,
spec,
);
execute_committee_consistency_test(new_head_state, cache_epoch, validator_count, spec);
}
async fn committee_consistency_test_suite<T: EthSpec>(cached_epoch: RelativeEpoch) {
@@ -361,18 +356,13 @@ mod committees {
.mul(spec.target_committee_size)
.add(1);
committee_consistency_test::<T>(validator_count as usize, Epoch::new(0), cached_epoch)
committee_consistency_test::<T>(validator_count, Epoch::new(0), cached_epoch).await;
committee_consistency_test::<T>(validator_count, T::genesis_epoch() + 4, cached_epoch)
.await;
committee_consistency_test::<T>(
validator_count as usize,
T::genesis_epoch() + 4,
cached_epoch,
)
.await;
committee_consistency_test::<T>(
validator_count as usize,
validator_count,
T::genesis_epoch()
+ (T::slots_per_historical_root() as u64)
.mul(T::slots_per_epoch())
@@ -3,6 +3,7 @@
#![allow(clippy::indexing_slicing)]
use super::Error;
use crate::historical_summary::HistoricalSummaryCache;
use crate::{BeaconState, EthSpec, Hash256, ParticipationList, Slot, Unsigned, Validator};
use cached_tree_hash::{int_log, CacheArena, CachedTreeHash, TreeHashCache};
use rayon::prelude::*;
@@ -142,6 +143,7 @@ pub struct BeaconTreeHashCacheInner<T: EthSpec> {
block_roots: TreeHashCache,
state_roots: TreeHashCache,
historical_roots: TreeHashCache,
historical_summaries: OptionalTreeHashCache,
balances: TreeHashCache,
randao_mixes: TreeHashCache,
slashings: TreeHashCache,
@@ -164,6 +166,14 @@ impl<T: EthSpec> BeaconTreeHashCacheInner<T> {
let historical_roots = state
.historical_roots()
.new_tree_hash_cache(&mut fixed_arena);
let historical_summaries = OptionalTreeHashCache::new(
state
.historical_summaries()
.ok()
.map(HistoricalSummaryCache::new)
.as_ref(),
);
let randao_mixes = state.randao_mixes().new_tree_hash_cache(&mut fixed_arena);
let validators = ValidatorsListTreeHashCache::new::<T>(state.validators());
@@ -200,6 +210,7 @@ impl<T: EthSpec> BeaconTreeHashCacheInner<T> {
block_roots,
state_roots,
historical_roots,
historical_summaries,
balances,
randao_mixes,
slashings,
@@ -249,6 +260,7 @@ impl<T: EthSpec> BeaconTreeHashCacheInner<T> {
.slashings()
.recalculate_tree_hash_root(&mut self.slashings_arena, &mut self.slashings)?,
];
// Participation
if let BeaconState::Base(state) = state {
leaves.push(state.previous_epoch_attestations.tree_hash_root());
@@ -291,6 +303,24 @@ impl<T: EthSpec> BeaconTreeHashCacheInner<T> {
if let Ok(payload_header) = state.latest_execution_payload_header() {
leaves.push(payload_header.tree_hash_root());
}
// Withdrawal indices (Capella and later).
if let Ok(next_withdrawal_index) = state.next_withdrawal_index() {
leaves.push(next_withdrawal_index.tree_hash_root());
}
if let Ok(next_withdrawal_validator_index) = state.next_withdrawal_validator_index() {
leaves.push(next_withdrawal_validator_index.tree_hash_root());
}
// Historical roots/summaries (Capella and later).
if let Ok(historical_summaries) = state.historical_summaries() {
leaves.push(
self.historical_summaries.recalculate_tree_hash_root(
&HistoricalSummaryCache::new(historical_summaries),
)?,
);
}
Ok(leaves)
}
@@ -335,14 +365,6 @@ impl<T: EthSpec> BeaconTreeHashCacheInner<T> {
hasher.write(leaf.as_bytes())?;
}
// Withdrawal indices (Capella and later).
if let Ok(next_withdrawal_index) = state.next_withdrawal_index() {
hasher.write(next_withdrawal_index.tree_hash_root().as_bytes())?;
}
if let Ok(next_withdrawal_validator_index) = state.next_withdrawal_validator_index() {
hasher.write(next_withdrawal_validator_index.tree_hash_root().as_bytes())?;
}
let root = hasher.finish()?;
self.previous_state = Some((root, state.slot()));
-5
View File
@@ -253,11 +253,6 @@ pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq +
fn max_blobs_per_block() -> usize {
Self::MaxBlobsPerBlock::to_usize()
}
/// Returns the `BYTES_PER_BLOB` constant for the specification.
fn bytes_per_blob() -> usize {
Self::BytesPerBlob::to_usize()
}
}
/// Macro to inherit some type values from another EthSpec.
+88
View File
@@ -0,0 +1,88 @@
use crate::test_utils::TestRandom;
use crate::Unsigned;
use crate::{BeaconState, EthSpec, Hash256};
use cached_tree_hash::Error;
use cached_tree_hash::{int_log, CacheArena, CachedTreeHash, TreeHashCache};
use compare_fields_derive::CompareFields;
use serde_derive::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
use ssz_types::VariableList;
use test_random_derive::TestRandom;
use tree_hash::{mix_in_length, TreeHash, BYTES_PER_CHUNK};
use tree_hash_derive::TreeHash;
/// `HistoricalSummary` matches the components of the phase0 `HistoricalBatch`
/// making the two hash_tree_root-compatible. This struct is introduced into the beacon state
/// in the Capella hard fork.
///
/// https://github.com/ethereum/consensus-specs/blob/dev/specs/capella/beacon-chain.md#historicalsummary
#[derive(
Debug,
PartialEq,
Serialize,
Deserialize,
Encode,
Decode,
TreeHash,
TestRandom,
CompareFields,
Clone,
Copy,
Default,
)]
pub struct HistoricalSummary {
block_summary_root: Hash256,
state_summary_root: Hash256,
}
impl HistoricalSummary {
pub fn new<T: EthSpec>(state: &BeaconState<T>) -> Self {
Self {
block_summary_root: state.block_roots().tree_hash_root(),
state_summary_root: state.state_roots().tree_hash_root(),
}
}
}
/// Wrapper type allowing the implementation of `CachedTreeHash`.
#[derive(Debug)]
pub struct HistoricalSummaryCache<'a, N: Unsigned> {
pub inner: &'a VariableList<HistoricalSummary, N>,
}
impl<'a, N: Unsigned> HistoricalSummaryCache<'a, N> {
pub fn new(inner: &'a VariableList<HistoricalSummary, N>) -> Self {
Self { inner }
}
#[allow(clippy::len_without_is_empty)]
pub fn len(&self) -> usize {
self.inner.len()
}
}
impl<'a, N: Unsigned> CachedTreeHash<TreeHashCache> for HistoricalSummaryCache<'a, N> {
fn new_tree_hash_cache(&self, arena: &mut CacheArena) -> TreeHashCache {
TreeHashCache::new(arena, int_log(N::to_usize()), self.len())
}
fn recalculate_tree_hash_root(
&self,
arena: &mut CacheArena,
cache: &mut TreeHashCache,
) -> Result<Hash256, Error> {
Ok(mix_in_length(
&cache.recalculate_merkle_root(arena, leaf_iter(self.inner))?,
self.len(),
))
}
}
pub fn leaf_iter(
values: &[HistoricalSummary],
) -> impl Iterator<Item = [u8; BYTES_PER_CHUNK]> + ExactSizeIterator + '_ {
values
.iter()
.map(|value| value.tree_hash_root())
.map(Hash256::to_fixed_bytes)
}
+1
View File
@@ -49,6 +49,7 @@ pub mod fork_name;
pub mod free_attestation;
pub mod graffiti;
pub mod historical_batch;
pub mod historical_summary;
pub mod indexed_attestation;
pub mod light_client_bootstrap;
pub mod light_client_finality_update;
+11 -13
View File
@@ -92,7 +92,7 @@ pub trait AbstractExecPayload<T: EthSpec>:
+ From<ExecutionPayloadEip4844<T>>
+ TryFrom<ExecutionPayloadHeaderEip4844<T>>;
fn default_at_fork(fork_name: ForkName) -> Self;
fn default_at_fork(fork_name: ForkName) -> Result<Self, Error>;
}
#[superstruct(
@@ -372,13 +372,12 @@ impl<T: EthSpec> AbstractExecPayload<T> for FullPayload<T> {
type Capella = FullPayloadCapella<T>;
type Eip4844 = FullPayloadEip4844<T>;
fn default_at_fork(fork_name: ForkName) -> Self {
fn default_at_fork(fork_name: ForkName) -> Result<Self, Error> {
match fork_name {
//FIXME(sean) error handling
ForkName::Base | ForkName::Altair => panic!(),
ForkName::Merge => FullPayloadMerge::default().into(),
ForkName::Capella => FullPayloadCapella::default().into(),
ForkName::Eip4844 => FullPayloadEip4844::default().into(),
ForkName::Base | ForkName::Altair => Err(Error::IncorrectStateVariant),
ForkName::Merge => Ok(FullPayloadMerge::default().into()),
ForkName::Capella => Ok(FullPayloadCapella::default().into()),
ForkName::Eip4844 => Ok(FullPayloadEip4844::default().into()),
}
}
}
@@ -882,13 +881,12 @@ impl<T: EthSpec> AbstractExecPayload<T> for BlindedPayload<T> {
type Capella = BlindedPayloadCapella<T>;
type Eip4844 = BlindedPayloadEip4844<T>;
fn default_at_fork(fork_name: ForkName) -> Self {
fn default_at_fork(fork_name: ForkName) -> Result<Self, Error> {
match fork_name {
//FIXME(sean) error handling
ForkName::Base | ForkName::Altair => panic!(),
ForkName::Merge => BlindedPayloadMerge::default().into(),
ForkName::Capella => BlindedPayloadCapella::default().into(),
ForkName::Eip4844 => BlindedPayloadEip4844::default().into(),
ForkName::Base | ForkName::Altair => Err(Error::IncorrectStateVariant),
ForkName::Merge => Ok(BlindedPayloadMerge::default().into()),
ForkName::Capella => Ok(BlindedPayloadCapella::default().into()),
ForkName::Eip4844 => Ok(BlindedPayloadEip4844::default().into()),
}
}
}
+1 -1
View File
@@ -223,7 +223,7 @@ mod test {
}
fn preset_from_file<T: DeserializeOwned>(preset_name: &str, filename: &str) -> T {
let f = File::open(&presets_base_path().join(preset_name).join(filename))
let f = File::open(presets_base_path().join(preset_name).join(filename))
.expect("preset file exists");
serde_yaml::from_reader(f).unwrap()
}