Making a workaround for the UTXO diff child bug (#2020)

* Making a workaround for the UTXO diff child bug

* Fix error message

* Fix error message
This commit is contained in:
Ori Newman 2022-04-14 12:55:20 +03:00 committed by GitHub
parent 57c6118be8
commit 35a959b56f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 12 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt"
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
"github.com/kaspanet/kaspad/domain/consensus/processes/consensusstatemanager"
"github.com/kaspanet/kaspad/domain/consensus/ruleerrors"
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
"github.com/kaspanet/kaspad/domain/consensus/utils/multiset"
@ -164,7 +165,12 @@ func (bp *blockProcessor) validateAndInsertBlock(stagingArea *model.StagingArea,
if reversalData != nil {
err = bp.consensusStateManager.ReverseUTXODiffs(blockHash, reversalData)
if err != nil {
// It's still not known what causes this error, but we can ignore it and not reverse the UTXO diffs
// and harm performance in some cases.
// TODO: Investigate why this error happens in the first place, and remove the workaround.
if errors.Is(err, consensusstatemanager.ErrReverseUTXODiffsUTXODiffChildNotFound) {
log.Errorf("Could not reverse UTXO diffs while resolving virtual: %s", err)
} else if err != nil {
return nil, err
}
}

View File

@ -5,6 +5,7 @@ import (
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
"github.com/kaspanet/kaspad/infrastructure/logger"
"github.com/kaspanet/kaspad/util/staging"
"github.com/pkg/errors"
"sort"
)
@ -65,7 +66,12 @@ func (csm *consensusStateManager) ResolveVirtual(maxBlocksToResolve uint64) (*ex
if reversalData != nil {
err = csm.ReverseUTXODiffs(resolveTip, reversalData)
if err != nil {
// It's still not known what causes this error, but we can ignore it and not reverse the UTXO diffs
// and harm performance in some cases.
// TODO: Investigate why this error happens in the first place, and remove the workaround.
if errors.Is(err, ErrReverseUTXODiffsUTXODiffChildNotFound) {
log.Errorf("Could not reverse UTXO diffs while resolving virtual: %s", err)
} else if err != nil {
return nil, false, err
}
}

View File

@ -162,18 +162,18 @@ func (csm *consensusStateManager) getUnverifiedChainBlocks(stagingArea *model.St
var unverifiedBlocks []*externalapi.DomainHash
currentHash := blockHash
for {
log.Debugf("Getting status for block %s", currentHash)
log.Tracef("Getting status for block %s", currentHash)
currentBlockStatus, err := csm.blockStatusStore.Get(csm.databaseContext, stagingArea, currentHash)
if err != nil {
return nil, err
}
if currentBlockStatus != externalapi.StatusUTXOPendingVerification {
log.Debugf("Block %s has status %s. Returning all the "+
log.Tracef("Block %s has status %s. Returning all the "+
"unverified blocks prior to it: %s", currentHash, currentBlockStatus, unverifiedBlocks)
return unverifiedBlocks, nil
}
log.Debugf("Block %s is unverified. Adding it to the unverified block collection", currentHash)
log.Tracef("Block %s is unverified. Adding it to the unverified block collection", currentHash)
unverifiedBlocks = append(unverifiedBlocks, currentHash)
currentBlockGHOSTDAGData, err := csm.ghostdagDataStore.Get(csm.databaseContext, stagingArea, currentHash, false)
@ -182,7 +182,7 @@ func (csm *consensusStateManager) getUnverifiedChainBlocks(stagingArea *model.St
}
if currentBlockGHOSTDAGData.SelectedParent() == nil {
log.Debugf("Genesis block reached. Returning all the "+
log.Tracef("Genesis block reached. Returning all the "+
"unverified blocks prior to it: %s", unverifiedBlocks)
return unverifiedBlocks, nil
}

View File

@ -3,10 +3,18 @@ package consensusstatemanager
import (
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
"github.com/kaspanet/kaspad/infrastructure/db/database"
"github.com/kaspanet/kaspad/infrastructure/logger"
"github.com/kaspanet/kaspad/util/staging"
"github.com/pkg/errors"
)
// ErrReverseUTXODiffsUTXODiffChildNotFound indicates a UTXO diff child was not found while calling ReverseUTXODiffs.
// It's still not known what causes this error, but we can ignore it and not reverse the UTXO diffs
// and harm performance in some cases.
// TODO: Investigate why this error happens in the first place, and remove the workaround.
var ErrReverseUTXODiffsUTXODiffChildNotFound = errors.New("ErrReverseUTXODiffsUTXODiffChildNotFound")
func (csm *consensusStateManager) ReverseUTXODiffs(tipHash *externalapi.DomainHash,
reversalData *model.UTXODiffReversalData) error {
@ -49,6 +57,9 @@ func (csm *consensusStateManager) ReverseUTXODiffs(tipHash *externalapi.DomainHa
currentBlockUTXODiffChild, err := csm.utxoDiffStore.UTXODiffChild(csm.databaseContext, readStagingArea, currentBlock)
if err != nil {
if database.IsNotFoundError(err) {
return errors.Wrapf(ErrReverseUTXODiffsUTXODiffChildNotFound, "UTXO diff child was not found for block %s", currentBlock)
}
return err
}
currentBlockGHOSTDAGData, err := csm.ghostdagDataStore.Get(csm.databaseContext, readStagingArea, currentBlock, false)

View File

@ -184,8 +184,6 @@ type Params struct {
DisallowDirectBlocksOnTopOfGenesis bool
IgnoreHeaderMass bool
// MaxBlockLevel is the maximum possible block level.
MaxBlockLevel int
@ -290,7 +288,7 @@ var MainnetParams = Params{
// This means that any block that has a level lower or equal to genesis will be level 0.
MaxBlockLevel: 225,
MergeDepth: defaultMergeDepth,
HF1DAAScore: 14360917,
HF1DAAScore: 14687583,
}
// TestnetParams defines the network parameters for the test Kaspa network.
@ -350,7 +348,6 @@ var TestnetParams = Params{
CoinbasePayloadScriptPublicKeyMaxLength: defaultCoinbasePayloadScriptPublicKeyMaxLength,
PruningProofM: defaultPruningProofM,
DeflationaryPhaseDaaScore: defaultDeflationaryPhaseDaaScore,
IgnoreHeaderMass: true,
MaxBlockLevel: 250,
MergeDepth: defaultMergeDepth,
@ -480,7 +477,6 @@ var DevnetParams = Params{
CoinbasePayloadScriptPublicKeyMaxLength: defaultCoinbasePayloadScriptPublicKeyMaxLength,
PruningProofM: defaultPruningProofM,
DeflationaryPhaseDaaScore: defaultDeflationaryPhaseDaaScore,
IgnoreHeaderMass: true,
MaxBlockLevel: 250,
MergeDepth: defaultMergeDepth,

View File

@ -12,7 +12,7 @@ import (
const (
// DefaultMaxMessages is the default capacity for a route with a capacity defined
DefaultMaxMessages = 100
DefaultMaxMessages = 200
)
var (