Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parlia: miner changes for BEP-188 of Early Broadcast #1269

Merged
merged 1 commit into from
Mar 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
unclezoro marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
delay = p.delayForRamanujanFork(snap, header)
}

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

Expand Down