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

* [NOD-1566] Add a dependency to golang-lru. * [NOD-1566] Add caching to blockstore.go. * [NOD-1566] Add LRUCache to all store objects and initialize them. * [NOD-1566] Add caching to acceptanceDataStore. * [NOD-1566] Add caching to blockHeaderStore. * [NOD-1566] Implement a simpler LRU cache. * [NOD-1566] Use the simpler cache implementation everywhere. * [NOD-1566] Remove dependency in golang-lru. * [NOD-1566] Fix object reuse issues in store Get functions. * [NOD-1566] Add caching to blockRelationStore. * [NOD-1566] Add caching to blockStatusStore. * [NOD-1566] Add caching to ghostdagDataStore. * [NOD-1566] Add caching to multisetStore. * [NOD-1566] Add caching to reachabilityDataStore. * [NOD-1566] Add caching to utxoDiffStore. * [NOD-1566] Add caching to reachabilityReindexRoot. * [NOD-1566] Add caching to pruningStore. * [NOD-1566] Add caching to headerTipsStore. * [NOD-1566] Add caching to consensusStateStore. * [NOD-1566] Add comments explaining why we don't discard staging at the normal location in consensusStateStore. * [NOD-1566] Make go vet happy. * [NOD-1566] Fix merge errors. * [NOD-1566] Add a missing break statement. * [NOD-1566] Run go mod tidy. * [NOD-1566] Remove serializedUTXOSetCache.
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
|
|
}
|