Skip to content

Commit a7817ea

Browse files
authored
Fix: block header times not being recorded correctly (#1605)
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.
1 parent e5e1d20 commit a7817ea

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

consensus/istanbul/qbft/core/request.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,18 @@ func (c *core) handleRequest(request *Request) error {
5757
delay := time.Duration(0)
5858

5959
block, ok := request.Proposal.(*types.Block)
60+
6061
if ok && len(block.Transactions()) == 0 { // if empty block
6162
config := c.config.GetConfig(c.current.Sequence())
63+
6264
if config.EmptyBlockPeriod > config.BlockPeriod {
6365
log.Info("EmptyBlockPeriod detected adding delay to request", "EmptyBlockPeriod", config.EmptyBlockPeriod, "BlockTime", block.Time())
66+
// Because the seal has an additional delay on the block period you need to subtract it from the delay
6467
delay = time.Duration(config.EmptyBlockPeriod-config.BlockPeriod) * time.Second
68+
header := block.Header()
69+
// Because the block period has already been added to the time we subtract it here
70+
header.Time = header.Time + config.EmptyBlockPeriod - config.BlockPeriod
71+
request.Proposal = block.WithSeal(header)
6572
}
6673
}
6774

0 commit comments

Comments
 (0)