worker: always drop on new block imported.
When new block is imported, there is no need to commit the current work, even the new imported block is offturn and itself is inturn. That is because when offturn block is received, the inturn block is already later to broadcast block, deliver the later block will cause many reorg, which is not reasonable. And also make sure all useless work can be discarded, to avoid goroutine leak.
This commit is contained in:
parent
c33f696811
commit
21b985c14b
@ -363,10 +363,6 @@ func (beacon *Beacon) SetThreads(threads int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Beacon) DropOnNewBlock(*types.Header) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsTTDReached checks if the TotalTerminalDifficulty has been surpassed on the `parentHash` block.
|
||||
// It depends on the parentHash already being stored in the database.
|
||||
// If the parentHash is not stored in the database a UnknownAncestor error is returned.
|
||||
|
@ -705,11 +705,6 @@ func (c *Clique) APIs(chain consensus.ChainHeaderReader) []rpc.API {
|
||||
}}
|
||||
}
|
||||
|
||||
func (p *Clique) DropOnNewBlock(header *types.Header) bool {
|
||||
// drop the block if it is not in turn.
|
||||
return header.Difficulty.Cmp(diffNoTurn) == 0
|
||||
}
|
||||
|
||||
// SealHash returns the hash of a block prior to it being sealed.
|
||||
func SealHash(header *types.Header) (hash common.Hash) {
|
||||
hasher := sha3.NewLegacyKeccak256()
|
||||
|
@ -130,12 +130,6 @@ type Engine interface {
|
||||
|
||||
// Close terminates any background threads maintained by the consensus engine.
|
||||
Close() error
|
||||
|
||||
// DropOnNewBlock determine the action of mining when it is interrupted by new imported block.
|
||||
// Return
|
||||
// true: the mining result will be dropped
|
||||
// false: the mining result will be kept and move on to the next mine step.
|
||||
DropOnNewBlock(header *types.Header) bool
|
||||
}
|
||||
|
||||
// PoW is a consensus engine based on proof-of-work.
|
||||
|
@ -647,10 +647,6 @@ var (
|
||||
big32 = big.NewInt(32)
|
||||
)
|
||||
|
||||
func (p *Ethash) DropOnNewBlock(*types.Header) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// AccumulateRewards credits the coinbase of the given block with the mining
|
||||
// reward. The total reward consists of the static block reward and rewards for
|
||||
// included uncles. The coinbase of each uncle block is also rewarded.
|
||||
|
@ -976,11 +976,6 @@ func (p *Parlia) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64,
|
||||
return CalcDifficulty(snap, p.val)
|
||||
}
|
||||
|
||||
func (p *Parlia) DropOnNewBlock(header *types.Header) bool {
|
||||
// drop the block if it is not in turn.
|
||||
return header.Difficulty.Cmp(diffNoTurn) == 0
|
||||
}
|
||||
|
||||
// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty
|
||||
// that a new block should have based on the previous blocks in the chain and the
|
||||
// current signer.
|
||||
|
@ -1118,17 +1118,12 @@ LOOP:
|
||||
fillDuration := time.Since(fillStart)
|
||||
switch {
|
||||
case errors.Is(err, errBlockInterruptedByNewHead):
|
||||
// For Parlia, it will drop the work on receiving new block if it is not inturn.
|
||||
if w.engine.DropOnNewBlock(work.header) {
|
||||
log.Debug("drop the block, when new block is imported")
|
||||
return
|
||||
}
|
||||
log.Debug("commitWork abort", "err", err)
|
||||
return
|
||||
case errors.Is(err, errBlockInterruptedByTimeout):
|
||||
// break the loop to get the best work
|
||||
log.Debug("commitWork timeout")
|
||||
break LOOP
|
||||
case errors.Is(err, errBlockInterruptedByOutOfGas):
|
||||
log.Debug("commitWork out of gas")
|
||||
// break the loop to get the best work
|
||||
log.Debug("commitWork finish", "reason", err)
|
||||
break LOOP
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user