Svarog c5707f64dc
[NOD-1420] Implement consensusStateManager (#985)
* [NOD-1420] Start working on ConsensusStateManager. Might be redundant due to recent changes

* [NOD-1420] Convert model to externalapi in utxo_algerbra helpers

* [NOD-1420] Add UTXO-diff algebra

* [NOD-1420] Prepare skeleton of calculateAcceptanceDataAndMultiset

* [NOD-1420] Added skeleton for AddBlockToVirtual

* [NOD-1420] Implement PopulateTransactionWithUTXOEntries

* [NOD-1420] Implement restorePastUTXO

* [NOD-1420] Implement finality check

* [NOD-1420] Move handling of tips to consensusStateManager

* [NOD-1420] Implement calculateAcceptanceDataAndMultiset

* [NOD-1420] Start implementing resolveBlockStatus

* [NOD-1420] Implement resolveBlockStatus

* [NOD-1420] Update related fields in end of resolveSingleBlockStatus

* [NOD-1420] Start working on selectVirtualParents

* [NOD-1420] Implemented BlockHeap

* [NOD-1420] Implement selectVirtualParents

* [NOD-1420] Implement updateVirtual

* [NOD-1420] Added comments where they were missing

* [NOD-1420] Place all consensusStateManager functions in correct files

* [NOD-1420] Return the missing outpoints from populateTransactionWithUTXOEntriesFromVirtualOrDiff

* [NOD-1420] Outpoint.ID -> TransactionID

* [NOD-1420] Fix Stringer tests

* [NOD-1420] Copy hash.FromString into utils

* [NOD-1420] SetParents should return an error

* [NOD-1420] Remove all reachabilityManager references from consensusStateManager

* [NOD-1420] Remove VirtualData. Get the info from the stores where needed

* [NOD-1420] Invert parameters to IsAncestorOf

* [NOD-1420] Use model.AcceptanceData

* [NOD-1420] Don't return accumulatedMassBefore in error cases

* [NOD-1420] Don't expect store functions to return nil when the requested data was found - instead add HasXXX functions

* [NOD-1420] addTransactionToMultiset sets isCoinbase properly

* [NOD-1420] expected hash string length is externalapi.DomainHashSize * 2

* [NOD-1420] Rename reachabilityTree -> reachabilityManager + updateReindexRoot if isNextVirtualSelectedParent

* [NOD-1420] ValidateCoinbaseTransaction in csm.verifyAndBuildUTXO

* [NOD-1420] Re-write HAsUTXODiffChild

* [NOD-1420] delete past_utxo.go.bak

* [NOD-1420] Implement validateCoinbaseTransaction in CSM

* [NOD-1420] Imlemented missing functionality in ValidateTransactionAndPopulateWithConsensusData

* [NOD-1420] Moved merge depth logic to MergeDepthManager

* [NOD-1420] Add logs
2020-11-02 16:18:53 +02:00

61 lines
2.3 KiB
Go

package utxoalgebra
import (
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
)
// add adds a new UTXO entry to this collection
func collectionAdd(collection model.UTXOCollection, outpoint *externalapi.DomainOutpoint, entry *externalapi.UTXOEntry) {
collection[*outpoint] = entry
}
// addMultiple adds multiple UTXO entries to this collection
func collectionAddMultiple(collection model.UTXOCollection, collectionToAdd model.UTXOCollection) {
for outpoint, entry := range collectionToAdd {
collection[outpoint] = entry
}
}
// remove removes a UTXO entry from this collection if it exists
func collectionRemove(collection model.UTXOCollection, outpoint *externalapi.DomainOutpoint) {
delete(collection, *outpoint)
}
// removeMultiple removes multiple UTXO entries from this collection if it exists
func collectionRemoveMultiple(collection model.UTXOCollection, collectionToRemove model.UTXOCollection) {
for outpoint := range collectionToRemove {
delete(collection, outpoint)
}
}
// CollectionGet returns the model.UTXOEntry represented by provided outpoint,
// and a boolean value indicating if said model.UTXOEntry is in the set or not
func CollectionGet(collection model.UTXOCollection, outpoint *externalapi.DomainOutpoint) (*externalapi.UTXOEntry, bool) {
entry, ok := collection[*outpoint]
return entry, ok
}
// CollectionContains returns a boolean value indicating whether a UTXO entry is in the set
func CollectionContains(collection model.UTXOCollection, outpoint *externalapi.DomainOutpoint) bool {
_, ok := collection[*outpoint]
return ok
}
// containsWithBlueScore returns a boolean value indicating whether a model.UTXOEntry
// is in the set and its blue score is equal to the given blue score.
func collectionContainsWithBlueScore(collection model.UTXOCollection, outpoint *externalapi.DomainOutpoint, blueScore uint64) bool {
entry, ok := CollectionGet(collection, outpoint)
return ok && entry.BlockBlueScore == blueScore
}
// clone returns a clone of this collection
func collectionClone(collection model.UTXOCollection) model.UTXOCollection {
clone := make(model.UTXOCollection, len(collection))
for outpoint, entry := range collection {
collectionAdd(clone, &outpoint, entry)
}
return clone
}