Merge remote-tracking branch 'origin/unstable' into capella

Fixing the conflicts involved patching up some of the `block_hash` verification,
the rest will be done as part of https://github.com/sigp/lighthouse/issues/3870
This commit is contained in:
Michael Sproul
2023-01-12 16:20:44 +11:00
59 changed files with 2994 additions and 1748 deletions

View File

@@ -0,0 +1,74 @@
// Copyright (c) 2022 Reth Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
use crate::{Address, EthSpec, ExecutionPayloadRef, Hash256, Hash64, Uint256};
use metastruct::metastruct;
/// Execution block header as used for RLP encoding and Keccak hashing.
///
/// Credit to Reth for the type definition.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[metastruct(mappings(map_execution_block_header_fields()))]
pub struct ExecutionBlockHeader {
pub parent_hash: Hash256,
pub ommers_hash: Hash256,
pub beneficiary: Address,
pub state_root: Hash256,
pub transactions_root: Hash256,
pub receipts_root: Hash256,
pub logs_bloom: Vec<u8>,
pub difficulty: Uint256,
pub number: Uint256,
pub gas_limit: Uint256,
pub gas_used: Uint256,
pub timestamp: u64,
pub extra_data: Vec<u8>,
pub mix_hash: Hash256,
pub nonce: Hash64,
pub base_fee_per_gas: Uint256,
}
impl ExecutionBlockHeader {
pub fn from_payload<E: EthSpec>(
payload: ExecutionPayloadRef<E>,
rlp_empty_list_root: Hash256,
rlp_transactions_root: Hash256,
) -> Self {
// Most of these field mappings are defined in EIP-3675 except for `mixHash`, which is
// defined in EIP-4399.
ExecutionBlockHeader {
parent_hash: payload.parent_hash().into_root(),
ommers_hash: rlp_empty_list_root,
beneficiary: payload.fee_recipient(),
state_root: payload.state_root(),
transactions_root: rlp_transactions_root,
receipts_root: payload.receipts_root(),
logs_bloom: payload.logs_bloom().clone().into(),
difficulty: Uint256::zero(),
number: payload.block_number().into(),
gas_limit: payload.gas_limit().into(),
gas_used: payload.gas_used().into(),
timestamp: payload.timestamp(),
extra_data: payload.extra_data().clone().into(),
mix_hash: payload.prev_randao(),
nonce: Hash64::zero(),
base_fee_per_gas: payload.base_fee_per_gas(),
}
}
}

View File

@@ -29,6 +29,7 @@ use tree_hash_derive::TreeHash;
Clone,
Copy,
Default,
arbitrary::Arbitrary,
)]
pub struct HistoricalSummary {
block_summary_root: Hash256,

View File

@@ -76,6 +76,7 @@ pub mod voluntary_exit;
#[macro_use]
pub mod slot_epoch_macros;
pub mod config_and_preset;
pub mod execution_block_header;
pub mod fork_context;
pub mod participation_flags;
pub mod participation_list;
@@ -136,6 +137,7 @@ pub use crate::enr_fork_id::EnrForkId;
pub use crate::eth1_data::Eth1Data;
pub use crate::eth_spec::EthSpecId;
pub use crate::execution_block_hash::ExecutionBlockHash;
pub use crate::execution_block_header::ExecutionBlockHeader;
pub use crate::execution_payload::{
ExecutionPayload, ExecutionPayloadCapella, ExecutionPayloadEip4844, ExecutionPayloadMerge,
ExecutionPayloadRef, Transaction, Transactions, Withdrawals,
@@ -207,6 +209,7 @@ pub type ForkVersion = [u8; 4];
pub type BLSFieldElement = Uint256;
pub type Blob<T> = FixedVector<BLSFieldElement, <T as EthSpec>::FieldElementsPerBlob>;
pub type VersionedHash = Hash256;
pub type Hash64 = ethereum_types::H64;
pub use bls::{
AggregatePublicKey, AggregateSignature, Keypair, PublicKey, PublicKeyBytes, SecretKey,

View File

@@ -130,6 +130,7 @@ pub trait AbstractExecPayload<T: EthSpec>:
tree_hash(enum_behaviour = "transparent"),
),
map_into(ExecutionPayload),
map_ref_into(ExecutionPayloadRef),
cast_error(ty = "Error", expr = "BeaconStateError::IncorrectStateVariant"),
partial_getter_error(ty = "Error", expr = "BeaconStateError::IncorrectStateVariant")
)]
@@ -277,13 +278,21 @@ impl<T: EthSpec> ExecPayload<T> for FullPayload<T> {
}
impl<T: EthSpec> FullPayload<T> {
pub fn execution_payload(&self) -> ExecutionPayload<T> {
map_full_payload_into_execution_payload!(self.clone(), |inner, cons| {
pub fn execution_payload(self) -> ExecutionPayload<T> {
map_full_payload_into_execution_payload!(self, |inner, cons| {
cons(inner.execution_payload)
})
}
}
impl<'a, T: EthSpec> FullPayloadRef<'a, T> {
pub fn execution_payload_ref(self) -> ExecutionPayloadRef<'a, T> {
map_full_payload_ref_into_execution_payload_ref!(&'a _, self, |inner, cons| {
cons(&inner.execution_payload)
})
}
}
impl<'b, T: EthSpec> ExecPayload<T> for FullPayloadRef<'b, T> {
fn block_type() -> BlockType {
BlockType::Full