ethereum.gray_glacier.blocksethereum.paris.blocks
A Block
is a single link in the chain that is Ethereum. Each Block
contains
a Header
and zero or more transactions. Each Header
contains associated
metadata like the block number, parent block hash, and how much gas was
consumed by its transactions.
Together, these blocks form a cryptographically secure journal recording the history of all state transitions that have happened since the genesis of the chain.
Header
Header portion of a block on the chain, containing metadata and cryptographic commitments to the block's contents.
29 | @slotted_freezable |
---|
30 | @dataclass |
---|
class Header:
parent_hash
37 | parent_hash: Hash32 |
---|
ommers_hash
45 | ommers_hash: Hash32 |
---|
coinbase
56 | coinbase: Address |
---|
state_root
67 | state_root: Root |
---|
transactions_root
80 | transactions_root: Root |
---|
receipt_root
92 | receipt_root: Root |
---|
bloom
103 | bloom: Bloom |
---|
difficulty
111 | difficulty: Uint |
---|
number
116 | number: Uint |
---|
gas_limit
121 | gas_limit: Uint |
---|
gas_used
135 | gas_used: Uint |
---|
timestamp
140 | timestamp: U256 |
---|
extra_data
145 | extra_data: Bytes |
---|
mix_digest
154 | mix_digest: Bytes32 |
---|
prev_randao
150 | prev_randao: Bytes32 |
---|
nonce
155 | nonce: Bytes8 |
---|
base_fee_per_gas
160 | base_fee_per_gas: Uint |
---|
Block
A complete block on Ethereum, which is composed of a block header
,
a list of transactions, and a list of ommers (also known as uncle blocks).a list of transactions, and a list of ommers (deprecated).
The block header
includes PoW-specific fields such as includes fields relevant to the Proof-of-Stake
consensus, with deprecated Proof-of-Work fields such as difficulty
,
nonce
, and ommersHash
, which relate to the mining process. The set to constants. The coinbase
field
denotes the address receiving priority fees from the block.coinbase
field denotes the address receiving mining and transaction
fees.
The header also contains commitments to the current state (stateRoot
),
the transactions (transactionsRoot
), and the transaction receipts
(receiptsRoot
). It also includes a bloom filter which summarizes log
data from the transactions.
Ommers are used to provide rewards for near-valid mined blocks that didn't
become part of the canonical chain.Ommers are deprecated and maintained only for compatibility.
170 | @slotted_freezable |
---|
171 | @dataclass |
---|
class Block:
header
192 | header: Header |
---|
transactions
200 | transactions: Tuple[Union[Bytes, LegacyTransaction], ...] |
---|
ommers
207 | ommers: Tuple[Header, ...] |
---|
Log
214 | @slotted_freezable |
---|
215 | @dataclass |
---|
class Log:
address
230 | address: Address |
---|
topics
235 | topics: Tuple[Hash32, ...] |
---|
data
240 | data: Bytes |
---|
Receipt
Result of a transaction execution. Receipts are included in the receipts trie.
246 | @slotted_freezable |
---|
247 | @dataclass |
---|
class Receipt:
succeeded
254 | succeeded: bool |
---|
cumulative_gas_used
259 | cumulative_gas_used: Uint |
---|
bloom
264 | bloom: Bloom |
---|
logs
270 | logs: Tuple[Log, ...] |
---|
encode_receipt
Encodes a transaction receipt based on the transaction type.
The encoding follows the same format as transactions encoding, where:
AccessListTransaction receipts are prefixed with
b"\x01"
.FeeMarketTransaction receipts are prefixed with
b"\x02"
.LegacyTransaction receipts are returned as is.
def encode_receipt(tx: Transaction, receipt: Receipt) -> Union[Bytes, Receipt]:
279 | r""" |
---|---|
280 | Encodes a transaction receipt based on the transaction type. |
281 |
|
282 | The encoding follows the same format as transactions encoding, where: |
283 | - AccessListTransaction receipts are prefixed with `b"\x01"`. |
284 | - FeeMarketTransaction receipts are prefixed with `b"\x02"`. |
285 | - LegacyTransaction receipts are returned as is. |
286 | """ |
287 | if isinstance(tx, AccessListTransaction): |
288 | return b"\x01" + rlp.encode(receipt) |
289 | elif isinstance(tx, FeeMarketTransaction): |
290 | return b"\x02" + rlp.encode(receipt) |
291 | else: |
292 | return receipt |
decode_receipt
Decodes a receipt from its serialized form.
The decoding follows the same format as transactions decoding, where:
Receipts prefixed with
b"\x01"
are decoded as AccessListTransaction receipts.Receipts prefixed with
b"\x02"
are decoded as FeeMarketTransaction receipts.LegacyTransaction receipts are returned as is.
def decode_receipt(receipt: Union[Bytes, Receipt]) -> Receipt:
296 | r""" |
---|---|
297 | Decodes a receipt from its serialized form. |
298 |
|
299 | The decoding follows the same format as transactions decoding, where: |
300 | - Receipts prefixed with `b"\x01"` are decoded as AccessListTransaction |
301 | receipts. |
302 | - Receipts prefixed with `b"\x02"` are decoded as FeeMarketTransaction |
303 | receipts. |
304 | - LegacyTransaction receipts are returned as is. |
305 | """ |
306 | if isinstance(receipt, Bytes): |
307 | assert receipt[0] in (1, 2) |
308 | return rlp.decode_to(Receipt, receipt[1:]) |
309 | else: |
310 | return receipt |