ethereum.london.blocksethereum.arrow_glacier.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

54
    coinbase: Address

state_root

65
    state_root: Root

transactions_root

78
    transactions_root: Root

receipt_root

90
    receipt_root: Root

bloom

101
    bloom: Bloom

difficulty

109
    difficulty: Uint

number

120
    number: Uint

gas_limit

125
    gas_limit: Uint

gas_used

139
    gas_used: Uint

timestamp

144
    timestamp: U256

extra_data

149
    extra_data: Bytes

mix_digest

154
    mix_digest: Bytes32

nonce

163
    nonce: Bytes8

base_fee_per_gas

172
    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).

The block header includes PoW-specific fields such as difficulty, nonce, and ommersHash, which relate to the mining process. The 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.

182
@slotted_freezable
183
@dataclass
class Block:

header

205
    header: Header

transactions

213
    transactions: Tuple[Union[Bytes, LegacyTransaction], ...]

ommers

220
    ommers: Tuple[Header, ...]

Log

Data record produced during the execution of a transaction. Logs are used by smart contracts to emit events (using the EVM log opcodes (LOG0, LOG1, LOG2, LOG3 and LOG4), which can be efficiently searched using the bloom filter in the block header.

228
@slotted_freezable
229
@dataclass
class Log:

address

244
    address: Address

topics

249
    topics: Tuple[Hash32, ...]

data

254
    data: Bytes

Receipt

Result of a transaction execution. Receipts are included in the receipts trie.

260
@slotted_freezable
261
@dataclass
class Receipt:

succeeded

268
    succeeded: bool

cumulative_gas_used

273
    cumulative_gas_used: Uint

bloom

278
    bloom: Bloom

logs

284
    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]:
293
    r"""
294
    Encodes a transaction receipt based on the transaction type.
295
296
    The encoding follows the same format as transactions encoding, where:
297
    - AccessListTransaction receipts are prefixed with `b"\x01"`.
298
    - FeeMarketTransaction receipts are prefixed with `b"\x02"`.
299
    - LegacyTransaction receipts are returned as is.
300
    """
301
    if isinstance(tx, AccessListTransaction):
302
        return b"\x01" + rlp.encode(receipt)
303
    elif isinstance(tx, FeeMarketTransaction):
304
        return b"\x02" + rlp.encode(receipt)
305
    else:
306
        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:
310
    r"""
311
    Decodes a receipt from its serialized form.
312
313
    The decoding follows the same format as transactions decoding, where:
314
    - Receipts prefixed with `b"\x01"` are decoded as AccessListTransaction
315
    receipts.
316
    - Receipts prefixed with `b"\x02"` are decoded as FeeMarketTransaction
317
    receipts.
318
    - LegacyTransaction receipts are returned as is.
319
    """
320
    if isinstance(receipt, Bytes):
321
        assert receipt[0] in (1, 2)
322
        return rlp.decode_to(Receipt, receipt[1:])
323
    else:
324
        return receipt