Skip to content

Commit 76f6ac5

Browse files
committed
consensus/bor,internal/cli,params: add header timestamp fix when in past
1 parent c31360e commit 76f6ac5

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

consensus/bor/bor.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,11 @@ func (c *Bor) Prepare(chain consensus.ChainHeaderReader, header *types.Header) e
932932

933933
header.Time = parent.Time + CalcProducerDelay(number, succession, c.config)
934934
if header.Time < uint64(time.Now().Unix()) {
935-
header.Time = uint64(time.Now().Unix()) + CalcProducerDelay(number, succession, c.config)
935+
if c.config.IsTimestampHF(big.NewInt(int64(number))) {
936+
header.Time = uint64(time.Now().Unix()) + CalcProducerDelay(number, succession, c.config)
937+
} else {
938+
header.Time = uint64(time.Now().Unix())
939+
}
936940
} else {
937941
// For primary validators, wait until the current block production window
938942
// starts. This prevents bor from starting to build next block before time

internal/cli/server/chains/amoy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ var amoyTestnet = &Chain{
3434
DelhiBlock: big.NewInt(73100),
3535
IndoreBlock: big.NewInt(73100),
3636
AhmedabadBlock: big.NewInt(11865856),
37-
BhilaiBlock: big.NewInt(22765056),
37+
BhilaiBlock: big.NewInt(22765056),
38+
TimestampHFBlock: big.NewInt(999999999999),
3839
StateSyncConfirmationDelay: map[string]uint64{
3940
"0": 128,
4041
},

internal/cli/server/chains/mainnet.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ var mainnetBor = &Chain{
3535
DelhiBlock: big.NewInt(38189056),
3636
IndoreBlock: big.NewInt(44934656),
3737
AhmedabadBlock: big.NewInt(62278656),
38-
BhilaiBlock: big.NewInt(73440256),
38+
BhilaiBlock: big.NewInt(73440256),
39+
TimestampHFBlock: big.NewInt(999999999999),
3940
StateSyncConfirmationDelay: map[string]uint64{
4041
"44934656": 128,
4142
},

internal/cli/server/chains/mumbai.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ var mumbaiTestnet = &Chain{
3535
DelhiBlock: big.NewInt(29638656),
3636
IndoreBlock: big.NewInt(37075456),
3737
AhmedabadBlock: big.NewInt(48467456),
38-
BhilaiBlock: big.NewInt(48467456),
39-
RioBlock: big.NewInt(48473856),
38+
BhilaiBlock: big.NewInt(48467456),
39+
RioBlock: big.NewInt(48473856),
40+
TimestampHFBlock: big.NewInt(999999999999),
4041
StateSyncConfirmationDelay: map[string]uint64{
4142
"37075456": 128,
4243
},

params/config.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,9 @@ var (
261261
DelhiBlock: big.NewInt(29638656),
262262
IndoreBlock: big.NewInt(37075456),
263263
AhmedabadBlock: big.NewInt(48467456),
264-
BhilaiBlock: big.NewInt(48467456),
265-
RioBlock: big.NewInt(48473856),
264+
BhilaiBlock: big.NewInt(48467456),
265+
RioBlock: big.NewInt(48473856),
266+
TimestampHFBlock: big.NewInt(999999999999),
266267
StateSyncConfirmationDelay: map[string]uint64{
267268
"37075456": 128,
268269
},
@@ -336,7 +337,8 @@ var (
336337
DelhiBlock: big.NewInt(73100),
337338
IndoreBlock: big.NewInt(73100),
338339
AhmedabadBlock: big.NewInt(11865856),
339-
BhilaiBlock: big.NewInt(22765056),
340+
BhilaiBlock: big.NewInt(22765056),
341+
TimestampHFBlock: big.NewInt(999999999999),
340342
StateSyncConfirmationDelay: map[string]uint64{
341343
"0": 128,
342344
},
@@ -414,7 +416,8 @@ var (
414416
DelhiBlock: big.NewInt(38189056),
415417
IndoreBlock: big.NewInt(44934656),
416418
AhmedabadBlock: big.NewInt(62278656),
417-
BhilaiBlock: big.NewInt(73440256),
419+
BhilaiBlock: big.NewInt(73440256),
420+
TimestampHFBlock: big.NewInt(999999999999),
418421
StateSyncConfirmationDelay: map[string]uint64{
419422
"44934656": 128,
420423
},
@@ -871,6 +874,7 @@ type BorConfig struct {
871874
AhmedabadBlock *big.Int `json:"ahmedabadBlock"` // Ahmedabad switch block (nil = no fork, 0 = already on ahmedabad)
872875
BhilaiBlock *big.Int `json:"bhilaiBlock"` // Bhilai switch block (nil = no fork, 0 = already on bhilai)
873876
RioBlock *big.Int `json:"rioBlock"` // Rio switch block (nil = no fork, 0 = already on rio)
877+
TimestampHFBlock *big.Int `json:"timestampHFBlock"` // Timestamp hardfork switch block (nil = no fork, 0 = already active)
874878
}
875879

876880
// String implements the stringer interface, returning the consensus engine details.
@@ -922,6 +926,10 @@ func (c *BorConfig) IsRio(number *big.Int) bool {
922926
return isBlockForked(c.RioBlock, number)
923927
}
924928

929+
func (c *BorConfig) IsTimestampHF(number *big.Int) bool {
930+
return isBlockForked(c.TimestampHFBlock, number)
931+
}
932+
925933
// // TODO: modify this function once the block number is finalized
926934
// func (c *BorConfig) IsNapoli(number *big.Int) bool {
927935
// if c.NapoliBlock != nil {

0 commit comments

Comments
 (0)