mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-23 23:36:56 +00:00

* [NOD-1551] Make UTXO-Diff implemented fully in utils/utxo * [NOD-1551] Fixes everywhere except database * [NOD-1551] Fix database * [NOD-1551] Add comments * [NOD-1551] Partial commit * [NOD-1551] Comlete making UTXOEntry immutable + don't clone it in UTXOCollectionClone * [NOD-1551] Rename ToUnmutable -> ToImmutable * [NOD-1551] Track immutable references generated from mutable UTXODiff, and invalidate them if the mutable one changed * [NOD-1551] Clone scriptPubKey in NewUTXOEntry * [NOD-1551] Remove redundant code * [NOD-1551] Remove redundant call for .CloneMutable and then .ToImmutable * [NOD-1551] Make utxoEntry pointert-receiver + clone ScriptPubKey in getter
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package consensusstatestore
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/domain/consensus/model"
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
)
|
|
|
|
// consensusStateStore represents a store for the current consensus state
|
|
type consensusStateStore struct {
|
|
tipsStaging []*externalapi.DomainHash
|
|
virtualDiffParentsStaging []*externalapi.DomainHash
|
|
virtualUTXODiffStaging model.UTXODiff
|
|
virtualUTXOSetStaging model.UTXOCollection
|
|
|
|
tipsCache []*externalapi.DomainHash
|
|
virtualDiffParentsCache []*externalapi.DomainHash
|
|
}
|
|
|
|
// New instantiates a new ConsensusStateStore
|
|
func New() model.ConsensusStateStore {
|
|
return &consensusStateStore{}
|
|
}
|
|
|
|
func (css *consensusStateStore) Discard() {
|
|
css.tipsStaging = nil
|
|
css.virtualUTXODiffStaging = nil
|
|
css.virtualDiffParentsStaging = nil
|
|
css.virtualUTXOSetStaging = nil
|
|
}
|
|
|
|
func (css *consensusStateStore) Commit(dbTx model.DBTransaction) error {
|
|
err := css.commitTips(dbTx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = css.commitVirtualDiffParents(dbTx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = css.commitVirtualUTXODiff(dbTx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = css.commitVirtualUTXOSet(dbTx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
css.Discard()
|
|
|
|
return nil
|
|
}
|
|
|
|
func (css *consensusStateStore) IsStaged() bool {
|
|
return css.tipsStaging != nil ||
|
|
css.virtualDiffParentsStaging != nil ||
|
|
css.virtualUTXODiffStaging != nil
|
|
}
|