1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//! Block related types and functions.
//!
//! [`Block`] trait is used to retrieve block information required for execution.
pub mod blob;
pub use blob::{calc_blob_gasprice, BlobExcessGasAndPrice};
use auto_impl::auto_impl;
use primitives::{Address, B256, U256};
/// Trait for retrieving block information required for execution.
#[auto_impl(&, &mut, Box, Arc)]
pub trait Block {
/// The number of ancestor blocks of this block (block height).
fn number(&self) -> U256;
/// Beneficiary (Coinbase, miner) is an address that has signed the block.
///
/// This is the receiver address of priority gas rewards.
fn beneficiary(&self) -> Address;
/// The timestamp of the block in seconds since the UNIX epoch.
fn timestamp(&self) -> U256;
/// The gas limit of the block.
fn gas_limit(&self) -> u64;
/// The base fee per gas, added in the London upgrade with [EIP-1559].
///
/// [EIP-1559]: https://eips.ethereum.org/EIPS/eip-1559
fn basefee(&self) -> u64;
/// The difficulty of the block.
///
/// Unused after the Paris (AKA the merge) upgrade, and replaced by `prevrandao`.
fn difficulty(&self) -> U256;
/// The output of the randomness beacon provided by the beacon chain.
///
/// Replaces `difficulty` after the Paris (AKA the merge) upgrade with [EIP-4399].
///
/// Note: `prevrandao` can be found in a block in place of `mix_hash`.
///
/// [EIP-4399]: https://eips.ethereum.org/EIPS/eip-4399
fn prevrandao(&self) -> Option<B256>;
/// Excess blob gas and blob gasprice.
///
/// Incorporated as part of the Cancun upgrade via [EIP-4844].
///
/// [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844
fn blob_excess_gas_and_price(&self) -> Option<BlobExcessGasAndPrice>;
/// See [EIP-4844] and [`calc_blob_gasprice`].
///
/// Returns `None` if `Cancun` is not enabled.
///
/// [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844
fn blob_gasprice(&self) -> Option<u128> {
self.blob_excess_gas_and_price().map(|a| a.blob_gasprice)
}
/// Return `blob_excess_gas` header field. See [EIP-4844].
///
/// Returns `None` if `Cancun` is not enabled.
///
/// [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844
fn blob_excess_gas(&self) -> Option<u64> {
self.blob_excess_gas_and_price().map(|a| a.excess_blob_gas)
}
/// Return the slot number of the block. See [EIP-7843].
///
/// Defaults to zero if not set.
///
/// [EIP-7843]: https://eips.ethereum.org/EIPS/eip-7843
fn slot_num(&self) -> u64 {
0
}
}