ethereum.muir_glacier.blocksethereum.berlin.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.

24
@slotted_freezable
25
@dataclass
class Header:

parent_hash

32
    parent_hash: Hash32

ommers_hash

40
    ommers_hash: Hash32

coinbase

49
    coinbase: Address

state_root

57
    state_root: Root

transactions_root

70
    transactions_root: Root

receipt_root

82
    receipt_root: Root

bloom

93
    bloom: Bloom

difficulty

101
    difficulty: Uint

number

112
    number: Uint

gas_limit

117
    gas_limit: Uint

gas_used

125
    gas_used: Uint

timestamp

130
    timestamp: U256

extra_data

135
    extra_data: Bytes

mix_digest

140
    mix_digest: Bytes32

nonce

149
    nonce: Bytes8

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.

159
@slotted_freezable
160
@dataclass
class Block:

header

182
    header: Header

transactions

189
    transactions: Tuple[Transaction, ...]
190
    transactions: Tuple[Union[Bytes, LegacyTransaction], ...]

ommers

196
    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.

204
@slotted_freezable
205
@dataclass
class Log:

address

220
    address: Address

topics

225
    topics: Tuple[Hash32, ...]

data

230
    data: Bytes

Receipt

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

236
@slotted_freezable
237
@dataclass
class Receipt:

succeeded

244
    succeeded: bool

cumulative_gas_used

249
    cumulative_gas_used: Uint

bloom

254
    bloom: Bloom

logs

260
    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".

  • LegacyTransaction receipts are returned as is.

def encode_receipt(tx: Transaction, ​​receipt: Receipt) -> Union[Bytes, Receipt]:
269
    r"""
270
    Encodes a transaction receipt based on the transaction type.
271
272
    The encoding follows the same format as transactions encoding, where:
273
    - AccessListTransaction receipts are prefixed with `b"\x01"`.
274
    - LegacyTransaction receipts are returned as is.
275
    """
276
    if isinstance(tx, AccessListTransaction):
277
        return b"\x01" + rlp.encode(receipt)
278
    else:
279
        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.

  • LegacyTransaction receipts are returned as is.

def decode_receipt(receipt: Union[Bytes, Receipt]) -> Receipt:
283
    r"""
284
    Decodes a receipt from its serialized form.
285
286
    The decoding follows the same format as transactions decoding, where:
287
    - Receipts prefixed with `b"\x01"` are decoded as AccessListTransaction
288
    receipts.
289
    - LegacyTransaction receipts are returned as is.
290
    """
291
    if isinstance(receipt, Bytes):
292
        assert receipt[0] == 1
293
        return rlp.decode_to(Receipt, receipt[1:])
294
    else:
295
        return receipt