forked from kaspanet/kaspad
-
Notifications
You must be signed in to change notification settings - Fork 1
/
consensus_state_store.go
35 lines (30 loc) · 1.44 KB
/
consensus_state_store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package consensusstatestore
import (
"github.com/catspa3/catspad/domain/consensus/model"
"github.com/catspa3/catspad/domain/consensus/model/externalapi"
"github.com/catspa3/catspad/domain/consensus/utils/utxolrucache"
"github.com/catspa3/catspad/util/staging"
)
var importingPruningPointUTXOSetKeyName = []byte("importing-pruning-point-utxo-set")
// consensusStateStore represents a store for the current consensus state
type consensusStateStore struct {
shardID model.StagingShardID
virtualUTXOSetCache *utxolrucache.LRUCache
tipsCache []*externalapi.DomainHash
tipsKey model.DBKey
utxoSetBucket model.DBBucket
importingPruningPointUTXOSetKey model.DBKey
}
// New instantiates a new ConsensusStateStore
func New(prefixBucket model.DBBucket, utxoSetCacheSize int, preallocate bool) model.ConsensusStateStore {
return &consensusStateStore{
shardID: staging.GenerateShardingID(),
virtualUTXOSetCache: utxolrucache.New(utxoSetCacheSize, preallocate),
tipsKey: prefixBucket.Key(tipsKeyName),
importingPruningPointUTXOSetKey: prefixBucket.Key(importingPruningPointUTXOSetKeyName),
utxoSetBucket: prefixBucket.Bucket(utxoSetBucketName),
}
}
func (css *consensusStateStore) IsStaged(stagingArea *model.StagingArea) bool {
return css.stagingShard(stagingArea).isStaged()
}