This repository was archived by the owner on Sep 8, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change 1- import time
21from typing import (
32 List ,
43 Type ,
2423 binary
2524)
2625
26+ from eth ._utils .headers import (
27+ new_timestamp_from_parent ,
28+ )
2729from 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 ,
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments