diff --git a/domain/consensus/processes/blockprocessor/validateandinsertblock.go b/domain/consensus/processes/blockprocessor/validateandinsertblock.go index 01971331e..d7c4c5c00 100644 --- a/domain/consensus/processes/blockprocessor/validateandinsertblock.go +++ b/domain/consensus/processes/blockprocessor/validateandinsertblock.go @@ -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 } diff --git a/domain/consensus/processes/consensusstatemanager/add_block_to_virtual.go b/domain/consensus/processes/consensusstatemanager/add_block_to_virtual.go index 3f9c80269..b55d04f3e 100644 --- a/domain/consensus/processes/consensusstatemanager/add_block_to_virtual.go +++ b/domain/consensus/processes/consensusstatemanager/add_block_to_virtual.go @@ -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) diff --git a/domain/consensus/processes/consensusstatemanager/resolve_block_status.go b/domain/consensus/processes/consensusstatemanager/resolve_block_status.go index ea2a8152d..2b5d993e4 100644 --- a/domain/consensus/processes/consensusstatemanager/resolve_block_status.go +++ b/domain/consensus/processes/consensusstatemanager/resolve_block_status.go @@ -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 diff --git a/domain/consensus/processes/consensusstatemanager/utxoalgebra/diff_algebra.go b/domain/consensus/processes/consensusstatemanager/utxoalgebra/diff_algebra.go index bf534c3cb..58bb13f81 100644 --- a/domain/consensus/processes/consensusstatemanager/utxoalgebra/diff_algebra.go +++ b/domain/consensus/processes/consensusstatemanager/utxoalgebra/diff_algebra.go @@ -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)))