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
2
1
from typing import (
3
2
List ,
4
3
Type ,
24
23
binary
25
24
)
26
25
26
+ from eth ._utils .headers import (
27
+ new_timestamp_from_parent ,
28
+ )
27
29
from eth .abc import (
28
30
BlockHeaderAPI ,
29
31
BlockHeaderSedesAPI ,
@@ -105,7 +107,11 @@ def __init__(self,
105
107
nonce : bytes = GENESIS_NONCE ,
106
108
base_fee_per_gas : int = 0 ) -> None :
107
109
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" )
109
115
super ().__init__ (
110
116
parent_hash = parent_hash ,
111
117
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):
793
793
block_number = GENESIS_BLOCK_NUMBER ,
794
794
gas_limit = GENESIS_GAS_LIMIT ,
795
795
parent_hash = b'\x0f ' * 32 ,
796
+ timestamp = 0 ,
796
797
)
797
798
with pytest .raises (ParentNotFound , match = "unknown parent" ):
798
799
headerdb .persist_header (header )
You can’t perform that action at this time.
0 commit comments