[NOD-1556] Add some logs (#1110)

* [NOD-1556] Add logs regarding block status and virtual blue score

* [NOD-1556] UTXODiffAlgebra: add the offending outpoint to the text of errors

* [NOD-1556] Make checkIntersectionWithRule return ok as well
This commit is contained in:
Svarog 2020-11-19 11:17:05 +02:00 committed by GitHub
parent bb244706ea
commit 950dd0cc8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 20 deletions

View File

@ -1,6 +1,7 @@
package blockprocessor
import (
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
"github.com/kaspanet/kaspad/domain/consensus/ruleerrors"
"github.com/kaspanet/kaspad/domain/consensus/utils/consensusserialization"
@ -155,6 +156,12 @@ func (bp *blockProcessor) validateAndInsertBlock(block *externalapi.DomainBlock)
}
log.Debugf("Block %s validated and inserted", hash)
virtualGhostDAGData, err := bp.ghostdagDataStore.Get(bp.databaseContext, model.VirtualBlockHash)
if err != nil {
return err
}
log.Debugf("New virtual's blue score: %d", virtualGhostDAGData.BlueScore)
return nil
}

View File

@ -26,6 +26,9 @@ func (csm *consensusStateManager) AddBlockToVirtual(blockHash *externalapi.Domai
return err
}
}
} else {
log.Debugf("Block %s is not next virtual selected parent. Therefore leaving him with status `%s`",
blockHash, externalapi.StatusUTXOPendingVerification)
}
newTips, err := csm.addTip(blockHash)

View File

@ -42,6 +42,7 @@ func (csm *consensusStateManager) resolveBlockStatus(blockHash *externalapi.Doma
csm.blockStatusStore.Stage(unverifiedBlockHash, blockStatus)
selectedParentStatus = blockStatus
log.Debugf("Block %s status resolved to `%s`", unverifiedBlockHash, blockStatus)
}
return blockStatus, nil

View File

@ -18,18 +18,21 @@ func checkIntersection(collection1 model.UTXOCollection, collection2 model.UTXOC
}
// checkIntersectionWithRule checks if there is an intersection between two model.UTXOCollections satisfying arbitrary rule
// returns the first outpoint in the two collections' intersection satsifying the rule, and a boolean indicating whether
// such outpoint exists
func checkIntersectionWithRule(collection1 model.UTXOCollection, collection2 model.UTXOCollection,
extraRule func(*externalapi.DomainOutpoint, *externalapi.UTXOEntry, *externalapi.UTXOEntry) bool) bool {
extraRule func(*externalapi.DomainOutpoint, *externalapi.UTXOEntry, *externalapi.UTXOEntry) bool) (
*externalapi.DomainOutpoint, bool) {
for outpoint, utxoEntry := range collection1 {
if diffEntry, ok := CollectionGet(collection2, &outpoint); ok {
if extraRule(&outpoint, utxoEntry, diffEntry) {
return true
return &outpoint, true
}
}
}
return false
return nil, false
}
// minInt returns the smaller of x or y integer values
@ -143,8 +146,9 @@ func DiffFrom(this, other *model.UTXODiff) (*model.UTXODiff, error) {
collectionContainsWithBlueScore(other.ToRemove, outpoint, utxoEntry.BlockBlueScore)))
}
if checkIntersectionWithRule(this.ToRemove, other.ToAdd, isNotAddedOutputRemovedWithBlueScore) {
return nil, errors.New("diffFrom: outpoint both in this.ToAdd and in other.ToRemove")
if offendingOutpoint, ok :=
checkIntersectionWithRule(this.ToRemove, other.ToAdd, isNotAddedOutputRemovedWithBlueScore); ok {
return nil, errors.Errorf("diffFrom: outpoint %s both in this.ToAdd and in other.ToRemove", offendingOutpoint)
}
//check that NOT (entries with unequal blue score AND utxoEntry is in this.ToRemove and/or other.ToAdd) -> Error
@ -156,18 +160,19 @@ func DiffFrom(this, other *model.UTXODiff) (*model.UTXODiff, error) {
collectionContainsWithBlueScore(other.ToAdd, outpoint, utxoEntry.BlockBlueScore)))
}
if checkIntersectionWithRule(this.ToAdd, other.ToRemove, isNotRemovedOutputAddedWithBlueScore) {
return nil, errors.New("diffFrom: outpoint both in this.ToRemove and in other.ToAdd")
if offendingOutpoint, ok :=
checkIntersectionWithRule(this.ToAdd, other.ToRemove, isNotRemovedOutputAddedWithBlueScore); ok {
return nil, errors.Errorf("diffFrom: outpoint %s both in this.ToRemove and in other.ToAdd", offendingOutpoint)
}
// if have the same entry in this.ToRemove and other.ToRemove
// and existing entry is with different blue score, in this case - this is an error
if checkIntersectionWithRule(this.ToRemove, other.ToRemove,
if offendingOutpoint, ok := checkIntersectionWithRule(this.ToRemove, other.ToRemove,
func(outpoint *externalapi.DomainOutpoint, utxoEntry, diffEntry *externalapi.UTXOEntry) bool {
return utxoEntry.BlockBlueScore != diffEntry.BlockBlueScore
}) {
return nil, errors.New("diffFrom: outpoint both in this.ToRemove and other.ToRemove with different " +
"blue scores, with no corresponding entry in this.ToAdd")
}); ok {
return nil, errors.Errorf("diffFrom: outpoint %s both in this.ToRemove and other.ToRemove with different "+
"blue scores, with no corresponding entry in this.ToAdd", offendingOutpoint)
}
result := model.UTXODiff{
@ -203,21 +208,20 @@ func DiffFrom(this, other *model.UTXODiff) (*model.UTXODiff, error) {
// WithDiffInPlace applies provided diff to this diff in-place, that would be the result if
// first d, and than diff were applied to the same base
func WithDiffInPlace(this *model.UTXODiff, diff *model.UTXODiff) error {
if checkIntersectionWithRule(diff.ToRemove, this.ToRemove,
if offendingOutpoint, ok := checkIntersectionWithRule(diff.ToRemove, this.ToRemove,
func(outpoint *externalapi.DomainOutpoint, entryToAdd, existingEntry *externalapi.UTXOEntry) bool {
return !collectionContainsWithBlueScore(this.ToAdd, outpoint, entryToAdd.BlockBlueScore)
}) {
return errors.New(
"withDiffInPlace: outpoint both in this.ToRemove and in diff.ToRemove")
}); ok {
return errors.Errorf(
"withDiffInPlace: outpoint %s both in this.ToRemove and in diff.ToRemove", offendingOutpoint)
}
if checkIntersectionWithRule(diff.ToAdd, this.ToAdd,
if offendingOutpoint, ok := checkIntersectionWithRule(diff.ToAdd, this.ToAdd,
func(outpoint *externalapi.DomainOutpoint, entryToAdd, existingEntry *externalapi.UTXOEntry) bool {
return !collectionContainsWithBlueScore(diff.ToRemove, outpoint, existingEntry.BlockBlueScore)
}) {
return errors.New(
"withDiffInPlace: outpoint both in this.ToAdd and in diff.ToAdd")
}); ok {
return errors.Errorf(
"withDiffInPlace: outpoint %s both in this.ToAdd and in diff.ToAdd", offendingOutpoint)
}
intersection := make(model.UTXOCollection, minInt(len(diff.ToRemove), len(this.ToAdd)))