Skip to content

Commit

Permalink
parlia: miner changes for BEP-188 of Early Broadcast (bnb-chain#1269)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrie-yl authored Mar 1, 2023
1 parent 2a76eb4 commit c8a1535
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const (

systemRewardPercent = 4 // it means 1/2^4 = 1/16 percentage of gas fee incoming will be distributed to system

gasUsedRateDemarcation = 75 // Demarcation point of low and high gas used rate
)

var (
Expand Down Expand Up @@ -881,8 +882,26 @@ 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.
// At the same time, small block which means gas used rate is less than
// gasUsedRateDemarcation does not broadcast early to avoid an upcoming fat block.
delay := time.Duration(0)
gasUsedRate := uint64(0)
if header.GasLimit != 0 {
gasUsedRate = header.GasUsed * 100 / header.GasLimit
}
if p.chainConfig.IsBohr(header.Number) && header.Difficulty.Cmp(diffInTurn) == 0 && gasUsedRate >= gasUsedRateDemarcation {
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 c8a1535

Please sign in to comment.