alloy_consensus

Struct Header

Source
pub struct Header {
Show 21 fields pub parent_hash: B256, pub ommers_hash: B256, pub beneficiary: Address, pub state_root: B256, pub transactions_root: B256, pub receipts_root: B256, pub logs_bloom: Bloom, pub difficulty: U256, pub number: BlockNumber, pub gas_limit: u64, pub gas_used: u64, pub timestamp: u64, pub extra_data: Bytes, pub mix_hash: B256, pub nonce: B64, pub base_fee_per_gas: Option<u64>, pub withdrawals_root: Option<B256>, pub blob_gas_used: Option<u64>, pub excess_blob_gas: Option<u64>, pub parent_beacon_block_root: Option<B256>, pub requests_hash: Option<B256>,
}
Expand description

Ethereum Block header

Fields§

§parent_hash: B256

The Keccak 256-bit hash of the parent block’s header, in its entirety; formally Hp.

§ommers_hash: B256

The Keccak 256-bit hash of the ommers list portion of this block; formally Ho.

§beneficiary: Address

The 160-bit address to which all fees collected from the successful mining of this block be transferred; formally Hc.

§state_root: B256

The Keccak 256-bit hash of the root node of the state trie, after all transactions are executed and finalisations applied; formally Hr.

§transactions_root: B256

The Keccak 256-bit hash of the root node of the trie structure populated with each transaction in the transactions list portion of the block; formally Ht.

§receipts_root: B256

The Keccak 256-bit hash of the root node of the trie structure populated with the receipts of each transaction in the transactions list portion of the block; formally He.

§logs_bloom: Bloom

The Bloom filter composed from indexable information (logger address and log topics) contained in each log entry from the receipt of each transaction in the transactions list; formally Hb.

§difficulty: U256

A scalar value corresponding to the difficulty level of this block. This can be calculated from the previous block’s difficulty level and the timestamp; formally Hd.

§number: BlockNumber

A scalar value equal to the number of ancestor blocks. The genesis block has a number of zero; formally Hi.

§gas_limit: u64

A scalar value equal to the current limit of gas expenditure per block; formally Hl.

§gas_used: u64

A scalar value equal to the total gas used in transactions in this block; formally Hg.

§timestamp: u64

A scalar value equal to the reasonable output of Unix’s time() at this block’s inception; formally Hs.

§extra_data: Bytes

An arbitrary byte array containing data relevant to this block. This must be 32 bytes or fewer; formally Hx.

§mix_hash: B256

A 256-bit hash which, combined with the nonce, proves that a sufficient amount of computation has been carried out on this block; formally Hm.

§nonce: B64

A 64-bit value which, combined with the mixhash, proves that a sufficient amount of computation has been carried out on this block; formally Hn.

§base_fee_per_gas: Option<u64>

A scalar representing EIP1559 base fee which can move up or down each block according to a formula which is a function of gas used in parent block and gas target (block gas limit divided by elasticity multiplier) of parent block. The algorithm results in the base fee per gas increasing when blocks are above the gas target, and decreasing when blocks are below the gas target. The base fee per gas is burned.

§withdrawals_root: Option<B256>

The Keccak 256-bit hash of the withdrawals list portion of this block. https://eips.ethereum.org/EIPS/eip-4895

§blob_gas_used: Option<u64>

The total amount of blob gas consumed by the transactions within the block, added in EIP-4844.

§excess_blob_gas: Option<u64>

A running total of blob gas consumed in excess of the target, prior to the block. Blocks with above-target blob gas consumption increase this value, blocks with below-target blob gas consumption decrease it (bounded at 0). This was added in EIP-4844.

§parent_beacon_block_root: Option<B256>

The hash of the parent beacon block’s root is included in execution blocks, as proposed by EIP-4788.

This enables trust-minimized access to consensus state, supporting staking pools, bridges, and more.

The beacon roots contract handles root storage, enhancing Ethereum’s functionalities.

§requests_hash: Option<B256>

The Keccak 256-bit hash of the an RLP encoded list with each EIP-7685 request in the block body.

Implementations§

Source§

impl Header

Source

pub fn hash_slow(&self) -> B256

Heavy function that will calculate hash of data and will not save the change to metadata.

Use Header::seal_slow and unlock if you need the hash to be persistent.

Source

pub fn is_empty(&self) -> bool

Checks if the header is empty - has no transactions and no ommers

Source

pub fn ommers_hash_is_empty(&self) -> bool

Check if the ommers hash equals to empty hash list.

Source

pub fn transaction_root_is_empty(&self) -> bool

Check if the transaction root equals to empty root.

Source

pub fn blob_fee(&self) -> Option<u128>

Returns the blob fee for this block according to the EIP-4844 spec.

Returns None if excess_blob_gas is None

Source

pub fn next_block_blob_fee(&self) -> Option<u128>

Returns the blob fee for the next block according to the EIP-4844 spec.

Returns None if excess_blob_gas is None.

See also Self::next_block_excess_blob_gas

Source

pub fn next_block_base_fee(&self, base_fee_params: BaseFeeParams) -> Option<u64>

Calculate base fee for next block according to the EIP-1559 spec.

Returns a None if no base fee is set, no EIP-1559 support

Source

pub fn next_block_excess_blob_gas(&self) -> Option<u64>

Calculate excess blob gas for the next block according to the EIP-4844 spec.

Returns a None if no excess blob gas is set, no EIP-4844 support

Source

pub fn size(&self) -> usize

Calculate a heuristic for the in-memory size of the Header.

Source

pub const fn parent_num_hash(&self) -> BlockNumHash

Returns the parent block’s number and hash

Note: for the genesis block the parent number is 0 and the parent hash is the zero hash.

Source

pub fn num_hash_slow(&self) -> BlockNumHash

Returns the block’s number and hash.

Note: this hashes the header.

Source

pub fn is_zero_difficulty(&self) -> bool

Checks if the block’s difficulty is set to zero, indicating a Proof-of-Stake header.

This function is linked to EIP-3675, proposing the consensus upgrade to Proof-of-Stake: EIP-3675

Verifies whether, as per the EIP, the block’s difficulty is updated to zero, signifying the transition to a Proof-of-Stake mechanism.

Returns true if the block’s difficulty matches the constant zero set by the EIP.

Source

pub const fn exceeds_allowed_future_timestamp( &self, present_timestamp: u64, ) -> bool

Checks if the block’s timestamp is in the future based on the present timestamp.

Clock can drift but this can be consensus issue.

Note: This check is relevant only pre-merge.

Source

pub const fn seal(self, hash: B256) -> Sealed<Self>

Seal the header with a known hash.

WARNING: This method does not perform validation whether the hash is correct.

Trait Implementations§

Source§

impl<'a> Arbitrary<'a> for Header

Available on crate feature arbitrary only.
Source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>

Generate an arbitrary value of Self from the given unstructured data. Read more
Source§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

impl AsRef<Header> for Header

Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl BlockHeader for Header

Source§

fn parent_hash(&self) -> B256

Retrieves the parent hash of the block
Source§

fn ommers_hash(&self) -> B256

Retrieves the ommers hash of the block
Source§

fn beneficiary(&self) -> Address

Retrieves the beneficiary (miner) of the block
Source§

fn state_root(&self) -> B256

Retrieves the state root hash of the block
Source§

fn transactions_root(&self) -> B256

Retrieves the transactions root hash of the block
Source§

fn receipts_root(&self) -> B256

Retrieves the receipts root hash of the block
Source§

fn withdrawals_root(&self) -> Option<B256>

Retrieves the withdrawals root hash of the block, if available
Source§

fn logs_bloom(&self) -> Bloom

Retrieves the logs bloom filter of the block
Source§

fn difficulty(&self) -> U256

Retrieves the difficulty of the block
Source§

fn number(&self) -> BlockNumber

Retrieves the block number
Source§

fn gas_limit(&self) -> u64

Retrieves the gas limit of the block
Source§

fn gas_used(&self) -> u64

Retrieves the gas used by the block
Source§

fn timestamp(&self) -> u64

Retrieves the timestamp of the block
Source§

fn mix_hash(&self) -> Option<B256>

Retrieves the mix hash of the block, if available
Source§

fn nonce(&self) -> Option<B64>

Retrieves the nonce of the block, if avaialble
Source§

fn base_fee_per_gas(&self) -> Option<u64>

Retrieves the base fee per gas of the block, if available
Source§

fn blob_gas_used(&self) -> Option<u64>

Retrieves the blob gas used by the block, if available
Source§

fn excess_blob_gas(&self) -> Option<u64>

Retrieves the excess blob gas of the block, if available
Source§

fn parent_beacon_block_root(&self) -> Option<B256>

Retrieves the parent beacon block root of the block, if available
Source§

fn requests_hash(&self) -> Option<B256>

Retrieves the requests hash of the block, if available
Source§

fn extra_data(&self) -> &Bytes

Retrieves the block’s extra data field
Source§

fn next_block_excess_blob_gas(&self) -> Option<u64>

Calculate excess blob gas for the next block according to the EIP-4844 spec. Read more
Source§

fn next_block_blob_fee(&self) -> Option<u128>

Returns the blob fee for the next block according to the EIP-4844 spec. Read more
Source§

impl Clone for Header

Source§

fn clone(&self) -> Header

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Header

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Decodable for Header

Source§

fn decode(buf: &mut &[u8]) -> Result<Self>

Decodes the blob into the appropriate type. buf must be advanced past the decoded object.
Source§

impl Default for Header

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Header

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'de> DeserializeAs<'de, Header> for Header<'de>

Available on crate features serde and serde-bincode-compat only.
Source§

fn deserialize_as<D>(deserializer: D) -> Result<Header, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer.
Source§

impl Encodable for Header

Source§

fn encode(&self, out: &mut dyn BufMut)

Encodes the type into the out buffer.
Source§

fn length(&self) -> usize

Returns the length of the encoding of this type in bytes. Read more
Source§

impl<'a> From<&'a Header> for Header<'a>

Available on crate features serde and serde-bincode-compat only.
Source§

fn from(value: &'a Header) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Header<'a>> for Header

Available on crate features serde and serde-bincode-compat only.
Source§

fn from(value: Header<'a>) -> Self

Converts to this type from the input type.
Source§

impl From<Header> for AnyHeader

Source§

fn from(value: Header) -> Self

Converts to this type from the input type.
Source§

impl Hash for Header

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Header

Source§

fn eq(&self, other: &Header) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sealable for Header

Source§

fn hash_slow(&self) -> B256

Calculate the seal hash, this may be slow.
Source§

fn seal_slow(self) -> Sealed<Self>

Seal the object by calculating the hash. This may be slow.
Source§

fn seal_ref_slow(&self) -> Sealed<&Self>

Seal a borrowed object by calculating the hash. This may be slow.
Source§

fn seal_unchecked(self, seal: FixedBytes<32>) -> Sealed<Self>

Instantiate an unchecked seal. This should be used with caution.
Source§

fn seal_ref_unchecked(&self, seal: FixedBytes<32>) -> Sealed<&Self>

Instantiate an unchecked seal. This should be used with caution.
Source§

impl Serialize for Header

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl SerializeAs<Header> for Header<'_>

Available on crate features serde and serde-bincode-compat only.
Source§

fn serialize_as<S>(source: &Header, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer.
Source§

impl Eq for Header

Source§

impl StructuralPartialEq for Header

Auto Trait Implementations§

§

impl !Freeze for Header

§

impl RefUnwindSafe for Header

§

impl Send for Header

§

impl Sync for Header

§

impl Unpin for Header

§

impl UnwindSafe for Header

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,