mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-23 15:26:42 +00:00

* [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
87 lines
2.0 KiB
Go
87 lines
2.0 KiB
Go
package hashset
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
)
|
|
|
|
// HashSet is an unsorted unique collection of DomainHashes
|
|
type HashSet map[externalapi.DomainHash]struct{}
|
|
|
|
// New creates and returns an empty HashSet
|
|
func New() HashSet {
|
|
return HashSet{}
|
|
}
|
|
|
|
// NewFromSlice creates and returns a HashSet with contents according to provided slice
|
|
func NewFromSlice(hashes ...*externalapi.DomainHash) HashSet {
|
|
set := New()
|
|
|
|
for _, hash := range hashes {
|
|
set.Add(hash)
|
|
}
|
|
|
|
return set
|
|
}
|
|
|
|
// String returns a string representation of this hash set
|
|
func (hs HashSet) String() string {
|
|
hashStrings := make([]string, 0, len(hs))
|
|
for hash := range hs {
|
|
hashStrings = append(hashStrings, hash.String())
|
|
}
|
|
return strings.Join(hashStrings, ", ")
|
|
}
|
|
|
|
// Add appends a hash to this HashSet. If given hash already exists - does nothing
|
|
func (hs HashSet) Add(hash *externalapi.DomainHash) {
|
|
hs[*hash] = struct{}{}
|
|
}
|
|
|
|
// Remove removes a hash from this HashSet. If given hash does not exist in HashSet - does nothing.
|
|
func (hs HashSet) Remove(hash *externalapi.DomainHash) {
|
|
delete(hs, *hash)
|
|
}
|
|
|
|
// Contains returns true if this HashSet contains the given hash.
|
|
func (hs HashSet) Contains(hash *externalapi.DomainHash) bool {
|
|
_, ok := hs[*hash]
|
|
return ok
|
|
}
|
|
|
|
// Subtract creates and returns a new HashSet that contains all hashes in this HashSet minus the ones in `other`
|
|
func (hs HashSet) Subtract(other HashSet) HashSet {
|
|
diff := New()
|
|
|
|
for hash := range hs {
|
|
if !other.Contains(&hash) {
|
|
diff.Add(&hash)
|
|
}
|
|
}
|
|
|
|
return diff
|
|
}
|
|
|
|
// ContainsAllInSlice returns true if this HashSet contains all hashes in given slice
|
|
func (hs HashSet) ContainsAllInSlice(slice []*externalapi.DomainHash) bool {
|
|
for _, hash := range slice {
|
|
if !hs.Contains(hash) {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// ToSlice converts this HashSet into a slice of hashes
|
|
func (hs HashSet) ToSlice() []*externalapi.DomainHash {
|
|
slice := make([]*externalapi.DomainHash, 0, len(hs))
|
|
|
|
for hash := range hs {
|
|
slice = append(slice, &hash)
|
|
}
|
|
|
|
return slice
|
|
}
|