mining: No error log on expected head reorg errors.
This changes the log for head reorg failures to a debug log instead of an error log since it is actually expected to fail reorgs from time to time due to the fact mining is a race to find blocks. It also cleans up the code slightly while here and adds an additional check to avoid additional work in the case reorgs to other tips fail and the current tip then becomes the best candidate among the eligible parents.
This commit is contained in:
parent
cecfb5a0b4
commit
fffe1f09c0
@ -1082,32 +1082,32 @@ func (g *BlkTmplGenerator) NewBlockTemplate(payToAddress dcrutil.Address) (*Bloc
|
||||
"block on, proceeding to create a new block template",
|
||||
eligibleParents[0])
|
||||
|
||||
// Force a reorganization to the parent with the most votes if we need
|
||||
// to.
|
||||
if eligibleParents[0] != prevHash {
|
||||
for i := range eligibleParents {
|
||||
newHead := &eligibleParents[i]
|
||||
err := g.cfg.ForceHeadReorganization(prevHash, *newHead)
|
||||
if err != nil {
|
||||
log.Errorf("failed to reorganize to new parent: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Check to make sure we actually have the transactions
|
||||
// (votes) we need in the mempool.
|
||||
voteHashes := g.cfg.TxSource.VoteHashesForBlock(newHead)
|
||||
if len(voteHashes) == 0 {
|
||||
return nil, fmt.Errorf("no vote metadata for block %v",
|
||||
newHead)
|
||||
}
|
||||
|
||||
if exist := g.cfg.TxSource.HaveAllTransactions(voteHashes); !exist {
|
||||
continue
|
||||
} else {
|
||||
prevHash = *newHead
|
||||
break
|
||||
}
|
||||
// Force a reorganization to the parent with the most votes if needed.
|
||||
for i := range eligibleParents {
|
||||
newHead := &eligibleParents[i]
|
||||
if *newHead == prevHash {
|
||||
break
|
||||
}
|
||||
|
||||
err := g.cfg.ForceHeadReorganization(prevHash, *newHead)
|
||||
if err != nil {
|
||||
log.Debugf("failed to reorganize to new parent: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Ensure the needed votes are actually in the mempool.
|
||||
voteHashes := g.cfg.TxSource.VoteHashesForBlock(newHead)
|
||||
if len(voteHashes) == 0 {
|
||||
return nil, fmt.Errorf("no vote metadata for block %v",
|
||||
newHead)
|
||||
}
|
||||
haveAllVotes := g.cfg.TxSource.HaveAllTransactions(voteHashes)
|
||||
if !haveAllVotes {
|
||||
continue
|
||||
}
|
||||
|
||||
prevHash = *newHead
|
||||
break
|
||||
}
|
||||
|
||||
// Obtain the maximum allowed treasury expenditure.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user