Skip to content

Commit

Permalink
consortium-v2: move the block timestamp calculation before IsPeriodBlock
Browse files Browse the repository at this point in the history
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 committed Nov 13, 2024
1 parent d27eb42 commit a195f76
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 @@ -872,6 +872,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 @@ -926,13 +934,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 a195f76

Please sign in to comment.