Documentation
¶
Index ¶
- Variables
- type CommitStore
- func (c *CommitStore) Close() error
- func (c *CommitStore) Commit(version uint64) (*proof.CommitInfo, error)
- func (c *CommitStore) Get(storeKey []byte, version uint64, key []byte) ([]byte, error)
- func (c *CommitStore) GetCommitInfo(version uint64) (*proof.CommitInfo, error)
- func (c *CommitStore) GetLatestVersion() (uint64, error)
- func (c *CommitStore) GetProof(storeKey []byte, version uint64, key []byte) ([]proof.CommitmentOp, error)
- func (c *CommitStore) Has(storeKey []byte, version uint64, key []byte) (bool, error)
- func (c *CommitStore) Iterator(storeKey []byte, version uint64, start, end []byte) (corestore.Iterator, error)
- func (c *CommitStore) LoadVersion(targetVersion uint64) error
- func (c *CommitStore) LoadVersionAndUpgrade(targetVersion uint64, upgrades *corestore.StoreUpgrades) error
- func (c *CommitStore) LoadVersionForOverwriting(targetVersion uint64) error
- func (c *CommitStore) PausePruning(pause bool)
- func (c *CommitStore) Prune(version uint64) error
- func (c *CommitStore) Restore(version uint64, format uint32, protoReader protoio.Reader) (snapshotstypes.SnapshotItem, error)
- func (c *CommitStore) ReverseIterator(storeKey []byte, version uint64, start, end []byte) (corestore.Iterator, error)
- func (c *CommitStore) SetInitialVersion(version uint64) error
- func (c *CommitStore) Snapshot(version uint64, protoWriter protoio.Writer) error
- func (c *CommitStore) VersionExists(version uint64) (bool, error)
- func (c *CommitStore) WriteChangeset(cs *corestore.Changeset) error
- type CommitStoreTestSuite
- func (s *CommitStoreTestSuite) TestStore_Get()
- func (s *CommitStoreTestSuite) TestStore_GetProof()
- func (s *CommitStoreTestSuite) TestStore_LoadVersion()
- func (s *CommitStoreTestSuite) TestStore_Pruning()
- func (s *CommitStoreTestSuite) TestStore_Snapshotter()
- func (s *CommitStoreTestSuite) TestStore_Upgrades()
- type Exporter
- type Importer
- type MetadataStore
- type MountTreeFn
- type Reader
- type Tree
Constants ¶
This section is empty.
Variables ¶
var ErrorExportDone = errors.New("export is complete")
ErrorExportDone is returned by Exporter.Next() when all items have been exported.
Functions ¶
This section is empty.
Types ¶
type CommitStore ¶
type CommitStore struct {
// contains filtered or unexported fields
}
CommitStore is a wrapper around multiple Tree objects mapped by a unique store key. Each store key reflects dedicated and unique usage within a module. A caller can construct a CommitStore with one or more store keys. It is expected that a RootStore use a CommitStore as an abstraction to handle multiple store keys and trees.
func NewCommitStore ¶
func NewCommitStore(trees, oldTrees map[string]Tree, db corestore.KVStoreWithBatch, logger corelog.Logger) (*CommitStore, error)
NewCommitStore creates a new CommitStore instance.
func (*CommitStore) Close ¶
func (c *CommitStore) Close() error
func (*CommitStore) Commit ¶
func (c *CommitStore) Commit(version uint64) (*proof.CommitInfo, error)
func (*CommitStore) GetCommitInfo ¶
func (c *CommitStore) GetCommitInfo(version uint64) (*proof.CommitInfo, error)
func (*CommitStore) GetLatestVersion ¶
func (c *CommitStore) GetLatestVersion() (uint64, error)
func (*CommitStore) GetProof ¶
func (c *CommitStore) GetProof(storeKey []byte, version uint64, key []byte) ([]proof.CommitmentOp, error)
GetProof returns a proof for the given key and version.
func (*CommitStore) Iterator ¶
func (c *CommitStore) Iterator(storeKey []byte, version uint64, start, end []byte) (corestore.Iterator, error)
Iterator implements store.VersionedReader.
func (*CommitStore) LoadVersion ¶
func (c *CommitStore) LoadVersion(targetVersion uint64) error
func (*CommitStore) LoadVersionAndUpgrade ¶
func (c *CommitStore) LoadVersionAndUpgrade(targetVersion uint64, upgrades *corestore.StoreUpgrades) error
LoadVersionAndUpgrade implements store.UpgradeableStore.
func (*CommitStore) LoadVersionForOverwriting ¶
func (c *CommitStore) LoadVersionForOverwriting(targetVersion uint64) error
func (*CommitStore) PausePruning ¶
func (c *CommitStore) PausePruning(pause bool)
PausePruning implements store.PausablePruner.
func (*CommitStore) Prune ¶
func (c *CommitStore) Prune(version uint64) error
Prune implements store.Pruner.
func (*CommitStore) Restore ¶
func (c *CommitStore) Restore( version uint64, format uint32, protoReader protoio.Reader, ) (snapshotstypes.SnapshotItem, error)
Restore implements snapshotstypes.CommitSnapshotter.
func (*CommitStore) ReverseIterator ¶
func (c *CommitStore) ReverseIterator(storeKey []byte, version uint64, start, end []byte) (corestore.Iterator, error)
ReverseIterator implements store.VersionedReader.
func (*CommitStore) SetInitialVersion ¶
func (c *CommitStore) SetInitialVersion(version uint64) error
func (*CommitStore) Snapshot ¶
func (c *CommitStore) Snapshot(version uint64, protoWriter protoio.Writer) error
Snapshot implements snapshotstypes.CommitSnapshotter.
func (*CommitStore) VersionExists ¶
func (c *CommitStore) VersionExists(version uint64) (bool, error)
VersionExists implements store.VersionedReader.
func (*CommitStore) WriteChangeset ¶
func (c *CommitStore) WriteChangeset(cs *corestore.Changeset) error
type CommitStoreTestSuite ¶
type CommitStoreTestSuite struct { suite.Suite NewStore func(db corestore.KVStoreWithBatch, dbDir string, storeKeys, oldStoreKeys []string, logger corelog.Logger) (*CommitStore, error) TreeType string }
CommitStoreTestSuite is a test suite to be used for all tree backends.
func (*CommitStoreTestSuite) TestStore_Get ¶
func (s *CommitStoreTestSuite) TestStore_Get()
func (*CommitStoreTestSuite) TestStore_GetProof ¶
func (s *CommitStoreTestSuite) TestStore_GetProof()
func (*CommitStoreTestSuite) TestStore_LoadVersion ¶
func (s *CommitStoreTestSuite) TestStore_LoadVersion()
func (*CommitStoreTestSuite) TestStore_Pruning ¶
func (s *CommitStoreTestSuite) TestStore_Pruning()
func (*CommitStoreTestSuite) TestStore_Snapshotter ¶
func (s *CommitStoreTestSuite) TestStore_Snapshotter()
TestStore_Snapshotter tests the snapshot functionality of the CommitStore. This test verifies that the store can correctly create snapshots and restore from them. The test follows these steps:
1. Setup & Data Population:
- Creates a new CommitStore with two stores (store1 and store2)
- Writes 10 versions of data (version 1-10)
- For each version, writes 10 key-value pairs to each store
- Total data: 2 stores * 10 versions * 10 pairs = 200 key-value pairs
- Keys are formatted as "key-{version}-{index}"
- Values are formatted as "value-{version}-{index}"
- Each version is committed to get a CommitInfo
2. Snapshot Creation:
- Creates a dummy extension item for metadata testing
- Sets up a new target store for restoration
- Creates a channel for snapshot chunks
- Launches a goroutine to:
- Create a snapshot writer
- Take a snapshot at version 10
- Write extension metadata
3. Snapshot Restoration:
- Creates a snapshot reader from the chunks
- Sets up a channel for state changes during restoration
- Launches a goroutine to collect restored key-value pairs
- Restores the snapshot into the target store
- Verifies the extension metadata was preserved
4. Verification:
- Confirms all 200 key-value pairs were restored correctly
- Verifies the format: "{storeKey}_key-{version}-{index}" -> "value-{version}-{index}"
- Checks that the restored store's Merkle tree hashes match the original
- Ensures store integrity by comparing CommitInfo hashes
func (*CommitStoreTestSuite) TestStore_Upgrades ¶
func (s *CommitStoreTestSuite) TestStore_Upgrades()
type Exporter ¶
type Exporter interface { Next() (*snapshotstypes.SnapshotIAVLItem, error) io.Closer }
Exporter is the interface that wraps the basic Export methods.
type Importer ¶
type Importer interface { Add(*snapshotstypes.SnapshotIAVLItem) error Commit() error io.Closer }
Importer is the interface that wraps the basic Import methods.
type MetadataStore ¶
type MetadataStore struct {
// contains filtered or unexported fields
}
MetadataStore is a store for metadata related to the commitment store. It isn't metadata store role to close the underlying KVStore.
func NewMetadataStore ¶
func NewMetadataStore(kv corestore.KVStoreWithBatch) *MetadataStore
NewMetadataStore creates a new MetadataStore.
func (*MetadataStore) GetCommitInfo ¶
func (m *MetadataStore) GetCommitInfo(version uint64) (*proof.CommitInfo, error)
GetCommitInfo returns the commit info for the given version.
func (*MetadataStore) GetLatestVersion ¶
func (m *MetadataStore) GetLatestVersion() (uint64, error)
GetLatestVersion returns the latest committed version.
func (*MetadataStore) GetRemovedStoreKeys ¶
func (m *MetadataStore) GetRemovedStoreKeys(version uint64) (storeKeys [][]byte, err error)
type MountTreeFn ¶
MountTreeFn is a function that mounts a tree given a store key. It is used to lazily mount trees when needed (e.g. during upgrade or proof generation).
type Reader ¶
type Reader interface { Get(version uint64, key []byte) ([]byte, error) Iterator(version uint64, start, end []byte, ascending bool) (corestore.Iterator, error) }
Reader is the optional interface that is only used to read data from the tree during the migration process.
type Tree ¶
type Tree interface { Set(key, value []byte) error Remove(key []byte) error GetLatestVersion() (uint64, error) // Hash returns the hash of the current version of the tree Hash() []byte // Version returns the current version of the tree Version() uint64 LoadVersion(version uint64) error LoadVersionForOverwriting(version uint64) error Commit() ([]byte, uint64, error) SetInitialVersion(version uint64) error GetProof(version uint64, key []byte) (*ics23.CommitmentProof, error) Prune(version uint64) error Export(version uint64) (Exporter, error) Import(version uint64) (Importer, error) io.Closer }
Tree is the interface that wraps the basic Tree methods.