Skip to content

Commit 7c53070

Browse files
committed
Fixup for: Choose better header timestamp, if none supplied
1 parent 046a9eb commit 7c53070

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

eth/vm/forks/london/blocks.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import time
21
from typing import (
32
List,
43
Type,
@@ -24,6 +23,9 @@
2423
binary
2524
)
2625

26+
from eth._utils.headers import (
27+
new_timestamp_from_parent,
28+
)
2729
from eth.abc import (
2830
BlockHeaderAPI,
2931
BlockHeaderSedesAPI,
@@ -105,7 +107,11 @@ def __init__(self,
105107
nonce: bytes = GENESIS_NONCE,
106108
base_fee_per_gas: int = 0) -> None:
107109
if timestamp is None:
108-
timestamp = int(time.time())
110+
if parent_hash == ZERO_HASH32:
111+
timestamp = new_timestamp_from_parent(None)
112+
else:
113+
# without access to the parent header, we cannot select a new timestamp correctly
114+
raise ValueError("Must set timestamp explicitly if this is not a genesis header")
109115
super().__init__(
110116
parent_hash=parent_hash,
111117
uncles_hash=uncles_hash,

tests/database/test_header_db.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ def test_headerdb_persist_header_disallows_unknown_parent(headerdb):
793793
block_number=GENESIS_BLOCK_NUMBER,
794794
gas_limit=GENESIS_GAS_LIMIT,
795795
parent_hash=b'\x0f' * 32,
796+
timestamp=0,
796797
)
797798
with pytest.raises(ParentNotFound, match="unknown parent"):
798799
headerdb.persist_header(header)

0 commit comments

Comments
 (0)