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

* [NOD-1492] Implement GHOSTDAGDataStore. * [NOD-1492] Implement MultisetStore. * [NOD-1492] Implement PruningStore. * [NOD-1492] Implement ReachabilityDataStore. * [NOD-1492] Implement UTXODiffStore. * [NOD-1492] Pluralize the multiset bucket name. * [NOD-1492] In PruningPoint and PruningPointSerializedUTXOSet, don't use IsStaged. * [NOD-1492] Leave pruning point serialization/deserialization for future implementation. * [NOD-1492] Leave reachability reindex root serialization/deserialization for future implementation. * [NOD-1492] Leave utxo diff child serialization/deserialization for future implementation. * [NOD-1492] Add Serialize() to Multiset. * [NOD-1492] Also check serializedUTXOSetStaging in IsStaged. * [NOD-1492] Also check utxoDiffChildStaging in IsStaged. * [NOD-1492] Fix UTXODiffStore.Delete.
91 lines
2.6 KiB
Go
91 lines
2.6 KiB
Go
package pruningstore
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/domain/consensus/model"
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
"github.com/kaspanet/kaspad/domain/consensus/utils/dbkeys"
|
|
)
|
|
|
|
var pruningBlockHashKey = dbkeys.MakeBucket().Key([]byte("pruning-block-hash"))
|
|
var pruningSerializedUTXOSetkey = dbkeys.MakeBucket().Key([]byte("pruning-utxo-set"))
|
|
|
|
// pruningStore represents a store for the current pruning state
|
|
type pruningStore struct {
|
|
blockHashStaging *externalapi.DomainHash
|
|
serializedUTXOSetStaging []byte
|
|
}
|
|
|
|
// New instantiates a new PruningStore
|
|
func New() model.PruningStore {
|
|
return &pruningStore{
|
|
blockHashStaging: nil,
|
|
serializedUTXOSetStaging: nil,
|
|
}
|
|
}
|
|
|
|
// Stage stages the pruning state
|
|
func (ps *pruningStore) Stage(pruningPointBlockHash *externalapi.DomainHash, pruningPointUTXOSet model.ReadOnlyUTXOSet) {
|
|
ps.blockHashStaging = pruningPointBlockHash
|
|
ps.serializedUTXOSetStaging = ps.serializeUTXOSet(pruningPointUTXOSet)
|
|
}
|
|
|
|
func (ps *pruningStore) IsStaged() bool {
|
|
return ps.blockHashStaging != nil || ps.serializedUTXOSetStaging != nil
|
|
}
|
|
|
|
func (ps *pruningStore) Discard() {
|
|
ps.blockHashStaging = nil
|
|
ps.serializedUTXOSetStaging = nil
|
|
}
|
|
|
|
func (ps *pruningStore) Commit(dbTx model.DBTransaction) error {
|
|
err := dbTx.Put(pruningBlockHashKey, ps.serializePruningPoint(ps.blockHashStaging))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = dbTx.Put(pruningSerializedUTXOSetkey, ps.serializedUTXOSetStaging)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
ps.Discard()
|
|
return nil
|
|
}
|
|
|
|
// PruningPoint gets the current pruning point
|
|
func (ps *pruningStore) PruningPoint(dbContext model.DBReader) (*externalapi.DomainHash, error) {
|
|
if ps.blockHashStaging != nil {
|
|
return ps.blockHashStaging, nil
|
|
}
|
|
|
|
blockHashBytes, err := dbContext.Get(pruningBlockHashKey)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
blockHash, err := ps.deserializePruningPoint(blockHashBytes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return blockHash, nil
|
|
}
|
|
|
|
// PruningPointSerializedUTXOSet returns the serialized UTXO set of the current pruning point
|
|
func (ps *pruningStore) PruningPointSerializedUTXOSet(dbContext model.DBReader) ([]byte, error) {
|
|
if ps.serializedUTXOSetStaging != nil {
|
|
return ps.serializedUTXOSetStaging, nil
|
|
}
|
|
return dbContext.Get(pruningSerializedUTXOSetkey)
|
|
}
|
|
|
|
func (ps *pruningStore) serializePruningPoint(pruningPoint *externalapi.DomainHash) []byte {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (ps *pruningStore) deserializePruningPoint(pruningPointBytes []byte) (*externalapi.DomainHash, error) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (ps *pruningStore) serializeUTXOSet(utxoSet model.ReadOnlyUTXOSet) []byte {
|
|
panic("implement me")
|
|
}
|