Skip to content

Commit

Permalink
Fix: block header times not being recorded correctly (#1605)
Browse files Browse the repository at this point in the history
Whilst the delay was be calculated correctly the block time
that was recorded in the block header was not. This was leading to
problems with the time difference between blocks when using the timestamp
in the block header.
  • Loading branch information
antonydenyer authored Feb 22, 2023
1 parent e5e1d20 commit a7817ea
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions consensus/istanbul/qbft/core/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,18 @@ func (c *core) handleRequest(request *Request) error {
delay := time.Duration(0)

block, ok := request.Proposal.(*types.Block)

if ok && len(block.Transactions()) == 0 { // if empty block
config := c.config.GetConfig(c.current.Sequence())

if config.EmptyBlockPeriod > config.BlockPeriod {
log.Info("EmptyBlockPeriod detected adding delay to request", "EmptyBlockPeriod", config.EmptyBlockPeriod, "BlockTime", block.Time())
// Because the seal has an additional delay on the block period you need to subtract it from the delay
delay = time.Duration(config.EmptyBlockPeriod-config.BlockPeriod) * time.Second
header := block.Header()
// Because the block period has already been added to the time we subtract it here
header.Time = header.Time + config.EmptyBlockPeriod - config.BlockPeriod
request.Proposal = block.WithSeal(header)
}
}

Expand Down

0 comments on commit a7817ea

Please sign in to comment.