mirror of
https://github.com/kaspanet/kaspad.git
synced 2026-03-21 15:49:23 +00:00
[NOD-1532] Update VirtualUTXODiffParents diffs even if list didn't change
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
package consensusstatemanager
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/utils/multiset"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/kaspanet/kaspad/domain/consensus/model"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||
@@ -186,7 +185,7 @@ func (csm *consensusStateManager) checkTransactionMass(
|
||||
}
|
||||
|
||||
func (csm *consensusStateManager) RestorePastUTXOSetIterator(blockHash *externalapi.DomainHash) (model.ReadOnlyUTXOSetIterator, error) {
|
||||
diff, _, _, err := csm.CalculatePastUTXOAndAcceptanceData(blockHash)
|
||||
blockDiff, _, _, err := csm.CalculatePastUTXOAndAcceptanceData(blockHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -196,25 +195,25 @@ func (csm *consensusStateManager) RestorePastUTXOSetIterator(blockHash *external
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pastUTXO := model.NewUTXODiff()
|
||||
virtualUTXO := model.NewUTXODiff()
|
||||
for virtualUTXOSetIterator.Next() {
|
||||
outpoint, utxoEntry, err := virtualUTXOSetIterator.Get()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pastUTXO.ToAdd[*outpoint] = utxoEntry
|
||||
virtualUTXO.ToAdd[*outpoint] = utxoEntry
|
||||
}
|
||||
|
||||
diff, err = utxoalgebra.WithDiff(pastUTXO, diff)
|
||||
blockUTXO, err := utxoalgebra.WithDiff(virtualUTXO, blockDiff)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(diff.ToRemove) > 0 {
|
||||
return nil, errors.New("diff.ToRemove is expected to be empty")
|
||||
if len(blockUTXO.ToRemove) > 0 {
|
||||
return nil, errors.New("blockUTXO.ToRemove is expected to be empty")
|
||||
}
|
||||
|
||||
return newUTXOSetIterator(diff.ToAdd), nil
|
||||
return newUTXOSetIterator(blockUTXO.ToAdd), nil
|
||||
}
|
||||
|
||||
type utxoOutpointEntryPair struct {
|
||||
|
||||
@@ -51,34 +51,34 @@ func (csm *consensusStateManager) updateVirtual(newBlockHash *externalapi.Domain
|
||||
func (csm *consensusStateManager) updateVirtualDiffParents(
|
||||
newBlockHash *externalapi.DomainHash, virtualUTXODiff *model.UTXODiff) error {
|
||||
|
||||
// If the status of the new block is not `Valid` - virtualDiffParents didn't change
|
||||
status, err := csm.blockStatusStore.Get(csm.databaseContext, newBlockHash)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if status != externalapi.StatusValid {
|
||||
return nil
|
||||
}
|
||||
|
||||
var newVirtualDiffParents []*externalapi.DomainHash
|
||||
if *newBlockHash == *csm.genesisHash {
|
||||
newVirtualDiffParents = []*externalapi.DomainHash{newBlockHash}
|
||||
} else {
|
||||
virtualDiffParents, err := csm.consensusStateStore.VirtualDiffParents(csm.databaseContext)
|
||||
oldVirtualDiffParents, err := csm.consensusStateStore.VirtualDiffParents(csm.databaseContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
newBlockParentsSlice, err := csm.dagTopologyManager.Parents(newBlockHash)
|
||||
// If the status of the new block is not `Valid` - virtualDiffParents didn't change
|
||||
status, err := csm.blockStatusStore.Get(csm.databaseContext, newBlockHash)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
newBlockParents := hashset.NewFromSlice(newBlockParentsSlice...)
|
||||
if status != externalapi.StatusValid {
|
||||
newVirtualDiffParents = oldVirtualDiffParents
|
||||
} else {
|
||||
newBlockParentsSlice, err := csm.dagTopologyManager.Parents(newBlockHash)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
newBlockParents := hashset.NewFromSlice(newBlockParentsSlice...)
|
||||
|
||||
newVirtualDiffParents = []*externalapi.DomainHash{newBlockHash}
|
||||
for _, virtualDiffParent := range virtualDiffParents {
|
||||
if !newBlockParents.Contains(virtualDiffParent) {
|
||||
newVirtualDiffParents = append(newVirtualDiffParents, virtualDiffParent)
|
||||
newVirtualDiffParents = []*externalapi.DomainHash{newBlockHash}
|
||||
for _, virtualDiffParent := range oldVirtualDiffParents {
|
||||
if !newBlockParents.Contains(virtualDiffParent) {
|
||||
newVirtualDiffParents = append(newVirtualDiffParents, virtualDiffParent)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user