Skip to content

Commit

Permalink
Drop the concept of pre-mining header post merge
Browse files Browse the repository at this point in the history
  • Loading branch information
fselmo committed Jan 23, 2024
1 parent b5c9fd9 commit d625109
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 41 deletions.
12 changes: 7 additions & 5 deletions eth/vm/forks/paris/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
Type,
)

from eth_typing import (
Hash32,
)
from eth_utils import (
encode_hex,
)
Expand All @@ -18,7 +21,6 @@
from eth.vm.forks.gray_glacier.blocks import (
GrayGlacierBlock,
GrayGlacierBlockHeader,
GrayGlacierMiningHeader,
)

from ..london.blocks import (
Expand All @@ -29,14 +31,14 @@
)


class ParisMiningHeader(GrayGlacierMiningHeader, ABC):
pass


class ParisBlockHeader(GrayGlacierBlockHeader, ABC):
def __str__(self) -> str:
return f"<ParisBlockHeader #{self.block_number} {encode_hex(self.hash)[2:10]}>"

@property
def mining_hash(self) -> Hash32:
raise ValueError("Mining hash is not available post merge.")


class ParisBlock(GrayGlacierBlock):
transaction_builder: Type[TransactionBuilderAPI] = ParisTransactionBuilder
Expand Down
56 changes: 20 additions & 36 deletions eth/vm/forks/shanghai/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
BlockHeaderAPI,
BlockHeaderSedesAPI,
ChainDatabaseAPI,
MiningHeaderAPI,
ReceiptAPI,
ReceiptBuilderAPI,
SignedTransactionAPI,
Expand Down Expand Up @@ -84,40 +83,27 @@
Withdrawal,
)

UNMINED_SHANGHAI_HEADER_FIELDS = [
("parent_hash", hash32),
("uncles_hash", hash32),
("coinbase", address),
("state_root", trie_root),
("transaction_root", trie_root),
("receipt_root", trie_root),
("bloom", uint256),
("difficulty", big_endian_int),
("block_number", big_endian_int),
("gas_limit", big_endian_int),
("gas_used", big_endian_int),
("timestamp", big_endian_int),
("extra_data", binary),
("base_fee_per_gas", big_endian_int),
("withdrawals_root", trie_root),
]


class ShanghaiMiningHeader(rlp.Serializable, MiningHeaderAPI, ABC):
fields = UNMINED_SHANGHAI_HEADER_FIELDS


class ShanghaiBlockHeader(rlp.Serializable, BlockHeaderAPI, ABC):
# `mix_hash` and `nonce` were fields before `base_fee_per_gas` and
# `withdrawals_root` and, thus, appear in the block header before them.
fields = (
UNMINED_SHANGHAI_HEADER_FIELDS[:13]
+ [
("mix_hash", binary),
("nonce", Binary(8, allow_empty=True)),
]
+ UNMINED_SHANGHAI_HEADER_FIELDS[13:]
)
fields = [
("parent_hash", hash32),
("uncles_hash", hash32),
("coinbase", address),
("state_root", trie_root),
("transaction_root", trie_root),
("receipt_root", trie_root),
("bloom", uint256),
("difficulty", big_endian_int),
("block_number", big_endian_int),
("gas_limit", big_endian_int),
("gas_used", big_endian_int),
("timestamp", big_endian_int),
("extra_data", binary),
("mix_hash", binary),
("nonce", Binary(8, allow_empty=True)),
("base_fee_per_gas", big_endian_int),
("withdrawals_root", trie_root),
]

def __init__(
self,
Expand Down Expand Up @@ -185,9 +171,7 @@ def hash(self) -> Hash32:

@property
def mining_hash(self) -> Hash32:
non_pow_fields = self[:-3] + self[-1:]
result = keccak(rlp.encode(non_pow_fields, ShanghaiMiningHeader))
return cast(Hash32, result)
raise ValueError("Mining hash is not available post merge.")

@property
def hex_hash(self) -> str:
Expand Down

0 comments on commit d625109

Please sign in to comment.