Skip to content

Commit

Permalink
consortium-v2: move the block timestamp calculation before IsPeriodBl…
Browse files Browse the repository at this point in the history
…ock (#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.
  • Loading branch information
minh-bq authored Nov 13, 2024
1 parent 3c463cb commit 8e06b07
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions consensus/consortium/v2/consortium.go
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,14 @@ func (c *Consortium) Prepare(chain consensus.ChainHeaderReader, header *types.He
return err
}

// Ensure the timestamp has the correct delay
parent := chain.GetHeader(header.ParentHash, number-1)
if parent == nil {
return consensus.ErrUnknownAncestor
}

header.Time = c.computeHeaderTime(header, parent, snap)

// Set the correct difficulty
header.Difficulty = CalcDifficulty(snap, coinbase)

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

// Ensure the timestamp has the correct delay
parent := chain.GetHeader(header.ParentHash, number-1)
if parent == nil {
return consensus.ErrUnknownAncestor
}

header.Time = c.computeHeaderTime(header, parent, snap)
return nil
}

Expand Down

0 comments on commit 8e06b07

Please sign in to comment.