@@ -30,32 +30,28 @@ var (
30
30
31
31
// GetNextTimestamp calculates the timestamp (in seconds and milliseconds) for the header based on the parent's timestamp and the current time.
32
32
// First return value is the timestamp in seconds, second return value is the timestamp in milliseconds.
33
- func GetNextTimestamp (parent * types. Header , config * extras. ChainConfig , now time.Time ) (uint64 , uint64 , error ) {
33
+ func GetNextTimestamp (config * extras. ChainConfig , parent * types. Header , now time.Time ) (uint64 , uint64 , error ) {
34
34
var (
35
35
timestamp = uint64 (now .Unix ())
36
36
timestampMS = uint64 (now .UnixMilli ())
37
37
)
38
- // Note: in order to support asynchronous block production, blocks are allowed to have
39
- // the same timestamp as their parent. This allows more than one block to be produced
40
- // per second.
41
- parentExtra := customtypes .GetHeaderExtra (parent )
42
- if parent .Time >= timestamp || (parentExtra .TimeMilliseconds != nil && * parentExtra .TimeMilliseconds >= timestampMS ) {
43
- // In pre-Granite, blocks are allowed to have the same timestamp as their parent.
44
- // In Granite, there is a minimum delay enforced, and if the timestamp is the same as the parent,
45
- // the block will be rejected.
46
- // The block builder should have already waited enough time to meet the minimum delay.
47
- // This is to early-exit from the block building.
48
- if config .IsGranite (timestamp ) {
38
+ if parent .Time < timestamp {
39
+ return timestamp , timestampMS , nil
40
+ }
41
+ // In Granite, there is a minimum delay enforced, and if the timestamp is the same as the parent,
42
+ // the block will be rejected.
43
+ // The block builder should have already waited enough time to meet the minimum delay.
44
+ // This is to early-exit from the block building.
45
+ if config .IsGranite (timestamp ) {
46
+ if uint64 (customtypes .BlockTime (parent ).UnixMilli ()) >= timestampMS {
49
47
return 0 , 0 , ErrGraniteClockBehindParent
50
48
}
51
- // Add the delay to the parent timestamp with seconds precision.
52
- timestamp = parent .Time
53
- // Actually we don't need to set timestampMS, because it will be not be set if this is not
54
- // Granite, but setting here for consistency.
55
- timestampMS = parent .Time * 1000
49
+ return timestamp , timestampMS , nil
56
50
}
57
-
58
- return timestamp , timestampMS , nil
51
+ // In pre-Granite, blocks are allowed to have the same timestamp as their parent
52
+ // Actually we don't need to return modified timestampMS, because it will be not be set if this is not
53
+ // Granite, but setting here for consistency.
54
+ return parent .Time , parent .Time * 1000 , nil
59
55
}
60
56
61
57
// VerifyTime verifies that the header's Time and TimeMilliseconds fields are
0 commit comments