blockchain: remove unknown block version warning

This commit is contained in:
Rjected 2019-08-26 22:09:13 -04:00 committed by Jake Sylvestre
parent 56cc42fe07
commit 70a0132485
3 changed files with 4 additions and 65 deletions

View file

@ -174,11 +174,7 @@ type BlockChain struct {
// //
// unknownRulesWarned refers to warnings due to unknown rules being // unknownRulesWarned refers to warnings due to unknown rules being
// activated. // activated.
// unknownRulesWarned bool
// unknownVersionsWarned refers to warnings due to unknown versions
// being mined.
unknownRulesWarned bool
unknownVersionsWarned bool
// The notifications field stores a slice of callbacks to be executed on // The notifications field stores a slice of callbacks to be executed on
// certain blockchain events. // certain blockchain events.
@ -574,20 +570,13 @@ func (b *BlockChain) connectBlock(node *blockNode, block *btcutil.Block,
"spent transaction out information") "spent transaction out information")
} }
// No warnings about unknown rules or versions until the chain is // No warnings about unknown rules until the chain is current.
// current.
if b.isCurrent() { if b.isCurrent() {
// Warn if any unknown new rules are either about to activate or // Warn if any unknown new rules are either about to activate or
// have already been activated. // have already been activated.
if err := b.warnUnknownRuleActivations(node); err != nil { if err := b.warnUnknownRuleActivations(node); err != nil {
return err return err
} }
// Warn if a high enough percentage of the last blocks have
// unexpected versions.
if err := b.warnUnknownVersions(node); err != nil {
return err
}
} }
// Write any block status changes to DB before updating best state. // Write any block status changes to DB before updating best state.

View file

@ -310,7 +310,7 @@ func (b *BlockChain) deploymentState(prevNode *blockNode, deploymentID uint32) (
// initThresholdCaches initializes the threshold state caches for each warning // initThresholdCaches initializes the threshold state caches for each warning
// bit and defined deployment and provides warnings if the chain is current per // bit and defined deployment and provides warnings if the chain is current per
// the warnUnknownVersions and warnUnknownRuleActivations functions. // the warnUnknownRuleActivations function.
func (b *BlockChain) initThresholdCaches() error { func (b *BlockChain) initThresholdCaches() error {
// Initialize the warning and deployment caches by calculating the // Initialize the warning and deployment caches by calculating the
// threshold state for each of them. This will ensure the caches are // threshold state for each of them. This will ensure the caches are
@ -335,15 +335,9 @@ func (b *BlockChain) initThresholdCaches() error {
} }
} }
// No warnings about unknown rules or versions until the chain is // No warnings about unknown rules until the chain is current.
// current.
if b.isCurrent() { if b.isCurrent() {
// Warn if a high enough percentage of the last blocks have
// unexpected versions.
bestNode := b.bestChain.Tip() bestNode := b.bestChain.Tip()
if err := b.warnUnknownVersions(bestNode); err != nil {
return err
}
// Warn if any unknown new rules are either about to activate or // Warn if any unknown new rules are either about to activate or
// have already been activated. // have already been activated.

View file

@ -26,15 +26,6 @@ const (
// vbNumBits is the total number of bits available for use with the // vbNumBits is the total number of bits available for use with the
// version bits scheme. // version bits scheme.
vbNumBits = 29 vbNumBits = 29
// unknownVerNumToCheck is the number of previous blocks to consider
// when checking for a threshold of unknown block versions for the
// purposes of warning the user.
unknownVerNumToCheck = 100
// unknownVerWarnNum is the threshold of previous blocks that have an
// unknown version to use for the purposes of warning the user.
unknownVerWarnNum = unknownVerNumToCheck / 2
) )
// bitConditionChecker provides a thresholdConditionChecker which can be used to // bitConditionChecker provides a thresholdConditionChecker which can be used to
@ -264,38 +255,3 @@ func (b *BlockChain) warnUnknownRuleActivations(node *blockNode) error {
return nil return nil
} }
// warnUnknownVersions logs a warning if a high enough percentage of the last
// blocks have unexpected versions.
//
// This function MUST be called with the chain state lock held (for writes)
func (b *BlockChain) warnUnknownVersions(node *blockNode) error {
// Nothing to do if already warned.
if b.unknownVersionsWarned {
return nil
}
// Warn if enough previous blocks have unexpected versions.
numUpgraded := uint32(0)
for i := uint32(0); i < unknownVerNumToCheck && node != nil; i++ {
expectedVersion, err := b.calcNextBlockVersion(node.parent)
if err != nil {
return err
}
if expectedVersion > vbLegacyBlockVersion &&
(node.version & ^expectedVersion) != 0 {
numUpgraded++
}
node = node.parent
}
if numUpgraded > unknownVerWarnNum {
log.Warn("Unknown block versions are being mined, so new " +
"rules might be in effect. Are you running the " +
"latest version of the software?")
b.unknownVersionsWarned = true
}
return nil
}