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

Commit a195f76

Browse files
committed
consortium-v2: move the block timestamp calculation before IsPeriodBlock
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 d27eb42 commit a195f76

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

consensus/consortium/v2/consortium.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,14 @@ func (c *Consortium) Prepare(chain consensus.ChainHeaderReader, header *types.He
872872
return err
873873
}
874874

875+
// Ensure the timestamp has the correct delay
876+
parent := chain.GetHeader(header.ParentHash, number-1)
877+
if parent == nil {
878+
return consensus.ErrUnknownAncestor
879+
}
880+
881+
header.Time = c.computeHeaderTime(header, parent, snap)
882+
875883
// Set the correct difficulty
876884
header.Difficulty = CalcDifficulty(snap, coinbase)
877885

@@ -926,13 +934,6 @@ func (c *Consortium) Prepare(chain consensus.ChainHeaderReader, header *types.He
926934
// Mix digest is reserved for now, set to empty
927935
header.MixDigest = common.Hash{}
928936

929-
// Ensure the timestamp has the correct delay
930-
parent := chain.GetHeader(header.ParentHash, number-1)
931-
if parent == nil {
932-
return consensus.ErrUnknownAncestor
933-
}
934-
935-
header.Time = c.computeHeaderTime(header, parent, snap)
936937
return nil
937938
}
938939

0 commit comments

Comments
 (0)