ethereum.paris.blocksethereum.shanghai.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.
Withdrawal
Withdrawals represent a transfer of ETH from the consensus layer (beacon
chain) to the execution layer, as validated by the consensus layer. Each
withdrawal is listed in the block's list of withdrawals. See block
29 | @slotted_freezable |
---|
30 | @dataclass |
---|
class Withdrawal:
index
40 | index: U64 |
---|
validator_index
46 | validator_index: U64 |
---|
address
51 | address: Address |
---|
amount
56 | amount: U256 |
---|
Header
Header portion of a block on the chain, containing metadata and cryptographic commitments to the block's contents.
62 | @slotted_freezable |
---|
63 | @dataclass |
---|
class Header:
parent_hash
70 | parent_hash: Hash32 |
---|
ommers_hash
78 | ommers_hash: Hash32 |
---|
coinbase
89 | coinbase: Address |
---|
state_root
100 | state_root: Root |
---|
transactions_root
113 | transactions_root: Root |
---|
receipt_root
125 | receipt_root: Root |
---|
bloom
136 | bloom: Bloom |
---|
difficulty
144 | difficulty: Uint |
---|
number
149 | number: Uint |
---|
gas_limit
154 | gas_limit: Uint |
---|
gas_used
168 | gas_used: Uint |
---|
timestamp
173 | timestamp: U256 |
---|
extra_data
178 | extra_data: Bytes |
---|
prev_randao
183 | prev_randao: Bytes32 |
---|
nonce
188 | nonce: Bytes8 |
---|
base_fee_per_gas
193 | base_fee_per_gas: Uint |
---|
withdrawals_root
202 | withdrawals_root: Root |
---|
Block
A complete block on Ethereum, which is composed of a block header
,
a list of transactions, and a list of ommers (deprecated).a list of transactions, a list of ommers (deprecated), and a list of
validator withdrawals.
The block header
includes fields relevant to the Proof-of-Stake
consensus, with deprecated Proof-of-Work fields such as difficulty
,
nonce
, and ommersHash
set to constants. The coinbase
field
denotes the address receiving priority fees from the block.
The header also contains commitments to the current state (stateRoot
),
the transactions (transactionsRoot
), and the transaction receipts), the transaction receipts
(receiptsRoot
). It also includes a bloom filter which summarizes log), and withdrawalsRoot
committing to the validator
data from the transactions.withdrawals included in this block. It also includes a bloom filter which
summarizes log data from the transactions.
Ommers are deprecated and maintained only for compatibility.Withdrawals represent ETH transfers from validators to their recipients,
introduced by the consensus layer. Ommers remain deprecated and empty.
209 | @slotted_freezable |
---|
210 | @dataclass |
---|
class Block:
header
235 | header: Header |
---|
transactions
243 | transactions: Tuple[Union[Bytes, LegacyTransaction], ...] |
---|
ommers
250 | ommers: Tuple[Header, ...] |
---|
withdrawals
256 | withdrawals: Tuple[Withdrawal, ...] |
---|
Log
262 | @slotted_freezable |
---|
263 | @dataclass |
---|
class Log:
address
278 | address: Address |
---|
topics
283 | topics: Tuple[Hash32, ...] |
---|
data
288 | data: Bytes |
---|
Receipt
Result of a transaction execution. Receipts are included in the receipts trie.
294 | @slotted_freezable |
---|
295 | @dataclass |
---|
class Receipt:
succeeded
302 | succeeded: bool |
---|
cumulative_gas_used
307 | cumulative_gas_used: Uint |
---|
bloom
312 | bloom: Bloom |
---|
logs
318 | 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]:
327 | r""" |
---|---|
328 | Encodes a transaction receipt based on the transaction type. |
329 |
|
330 | The encoding follows the same format as transactions encoding, where: |
331 | - AccessListTransaction receipts are prefixed with `b"\x01"`. |
332 | - FeeMarketTransaction receipts are prefixed with `b"\x02"`. |
333 | - LegacyTransaction receipts are returned as is. |
334 | """ |
335 | if isinstance(tx, AccessListTransaction): |
336 | return b"\x01" + rlp.encode(receipt) |
337 | elif isinstance(tx, FeeMarketTransaction): |
338 | return b"\x02" + rlp.encode(receipt) |
339 | else: |
340 | 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:
344 | r""" |
---|---|
345 | Decodes a receipt from its serialized form. |
346 |
|
347 | The decoding follows the same format as transactions decoding, where: |
348 | - Receipts prefixed with `b"\x01"` are decoded as AccessListTransaction |
349 | receipts. |
350 | - Receipts prefixed with `b"\x02"` are decoded as FeeMarketTransaction |
351 | receipts. |
352 | - LegacyTransaction receipts are returned as is. |
353 | """ |
354 | if isinstance(receipt, Bytes): |
355 | assert receipt[0] in (1, 2) |
356 | return rlp.decode_to(Receipt, receipt[1:]) |
357 | else: |
358 | return receipt |