Skip to content

Commit

Permalink
parlia: miner changes for BEP-188 of Early Broadcast
Browse files Browse the repository at this point in the history
Signed-off-by: cryyl <[email protected]>
  • Loading branch information
kyrie-yl committed Feb 28, 2023
1 parent f5cb137 commit 9ca734f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,20 @@ func (p *Parlia) Seal(chain consensus.ChainHeaderReader, block *types.Block, res
}
}

// Sweet, the protocol permits us to sign the block, wait for our time
delay := p.delayForRamanujanFork(snap, header)
// BEP-188 allows an in-turn validator to broadcast the mined block earlier
// but not earlier than its parent's timestamp after Bohr fork.
delay := time.Duration(0)
if p.chainConfig.IsBohr(header.Number) && header.Difficulty.Cmp(diffInTurn) == 0 {
parent := chain.GetHeader(header.ParentHash, number-1)
if parent == nil || parent.Number.Uint64() != number-1 || parent.Hash() != header.ParentHash {
return consensus.ErrUnknownAncestor
}
if parent.Time > uint64(time.Now().Unix()) {
delay = time.Until(time.Unix(int64(parent.Time), 0))
}
} else {
delay = p.delayForRamanujanFork(snap, header)
}

log.Info("Sealing block with", "number", number, "delay", delay, "headerDifficulty", header.Difficulty, "val", val.Hex())

Expand Down

0 comments on commit 9ca734f

Please sign in to comment.