Skip to content
This repository was archived by the owner on Jun 6, 2025. It is now read-only.

Commit 8e06b07

Browse files
authored
consortium-v2: move the block timestamp calculation before IsPeriodBlock (#629)
IsPeriodBlock uses the block header's timestamp to determine if the block is in new period. So we need to move the block header's timestamp calculation before the logic that calls IsPeriodBlock.
1 parent 3c463cb commit 8e06b07

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

consensus/consortium/v2/consortium.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,14 @@ func (c *Consortium) Prepare(chain consensus.ChainHeaderReader, header *types.He
10211021
return err
10221022
}
10231023

1024+
// Ensure the timestamp has the correct delay
1025+
parent := chain.GetHeader(header.ParentHash, number-1)
1026+
if parent == nil {
1027+
return consensus.ErrUnknownAncestor
1028+
}
1029+
1030+
header.Time = c.computeHeaderTime(header, parent, snap)
1031+
10241032
// Set the correct difficulty
10251033
header.Difficulty = CalcDifficulty(snap, coinbase)
10261034

@@ -1075,13 +1083,6 @@ func (c *Consortium) Prepare(chain consensus.ChainHeaderReader, header *types.He
10751083
// Mix digest is reserved for now, set to empty
10761084
header.MixDigest = common.Hash{}
10771085

1078-
// Ensure the timestamp has the correct delay
1079-
parent := chain.GetHeader(header.ParentHash, number-1)
1080-
if parent == nil {
1081-
return consensus.ErrUnknownAncestor
1082-
}
1083-
1084-
header.Time = c.computeHeaderTime(header, parent, snap)
10851086
return nil
10861087
}
10871088

0 commit comments

Comments
 (0)