* [10948]: Add changelog entry. * [10948]: Deprecate the types.DBBackend variable and the NewLevelDB function. Create a NewDB function to replace them. * [10948]: Add a DBBackend string to the simulation config and a flag for setting it. Update the simulation setup to use that instead of the compile-time DBBackend variable. * [10948]: Update the mock app creator to use the NewDB function. Not sure what to do about the db backend in that case though. * [10948]: Update changelog to reflect new db-backend field name. * [10948]: Use the tendermint db-backend type for the snapshot db. * [10948]: Update the last use of NewLevelDB by adding a parameter to openDB and uppdating calls to that to provide the db type to use. * [10948]: Upddate the NewDB function to also have a default db backend type if an empty string is provided there. * [10948]: Remove the new TODO in mock.NewApp. After looking through it's uses, there doesn't seem to be any desire to change it, and there's no easy way to communicate it. * [10948]: Enhance the NewDB defer function to also add info to any err that is being returned. * [10948]: Add some unit tests for NewDB. * [10948]: Lint fixes. * [10948]: Add a changelog entry to the deprecated section. * [10948]: Update the makefile to no longer set the types.DBBackend value. * [10948]: Use memdb for the mock app instead of goleveldb. I know it was a goleveldb before, but for a mock app, a memdb feels like a better choice (assuming 'mock' and 'mem' mean what I assume they mean). * [10948]: Fix the store benchmark tests (had some index-out-of-range issues). * [10948]: Fix cachekv store bench test calling iter.Key() before checking iter.Valid(). * [10948]: Remove the panic recovery from types.NewDB since dbm.NewDB returns an error now (it didn't originally, when NewLevelDB was first written). * [10948]: Add changlog entry indicationg an API breaking change due to the DBBackend change. * [10948]: Get rid of the types.NewDB function in favor of just using the tm-db version of it. * [10948]: Fix Update the codeql-analysis github action to use go v1.17. * [10948]: Add config file option for the app db backend type. * [10948]: Adjust the comment on the app-db-backend config entry to clarify fallback behavior. * [10948]: Add a default of GoLevelDBBackend to GetAppDBBackend. The old DBBackend variable defaulted to that, and some unit tests assume that behavior still exists. * [10948]: Add the missing quotes around the app-db-backend value. * [10948]: Small tweak to the changelog's deprecated entry. * Add the go version declaration back into the codeql-analysis github action. * [10948]: Update new use of openDB. * [10948]: Put a brief delay after closing the test network. Hopefully that helps with address-in-use and non-empty directory errors. Co-authored-by: Marko <marbar3778@yahoo.com> |
||
|---|---|---|
| .. | ||
| cache | ||
| cachekv | ||
| cachemulti | ||
| dbadapter | ||
| gaskv | ||
| iavl | ||
| internal | ||
| listenkv | ||
| mem | ||
| prefix | ||
| rootmulti | ||
| streaming | ||
| tools/ics23 | ||
| tracekv | ||
| transient | ||
| types | ||
| v2alpha1 | ||
| firstlast.go | ||
| README.md | ||
| reexport.go | ||
| store.go | ||
Store
CacheKV
cachekv.Store is a wrapper KVStore which provides buffered writing / cached reading functionalities over the underlying KVStore.
type Store struct {
cache map[string]cValue
parent types.KVStore
}
Get
Store.Get() checks Store.cache first in order to find if there is any cached value associated with the key. If the value exists, the function returns it. If not, the function calls Store.parent.Get(), sets the key-value pair in the Store.cache, and returns it.
Set
Store.Set() sets the key-value pair to the Store.cache. cValue has the field dirty bool which indicates whether the cached value is different from the underlying value. When Store.Set() cache new pair, the cValue.dirty is set true so when Store.Write() is called it can be written to the underlying store.
Iterator
Store.Iterator() have to traverse on both caches items and the original items. In Store.iterator(), two iterators are generated for each of them, and merged. memIterator is essentially a slice of the KVPairs, used for cached items. mergeIterator is a combination of two iterators, where traverse happens ordered on both iterators.
CacheMulti
cachemulti.Store is a wrapper MultiStore which provides buffered writing / cached reading functionalities over the underlying MutliStore
type Store struct {
db types.CacheKVStore
stores map[types.StoreKey] types.CacheWrap
}
cachemulti.Store branches all substores in its constructor and hold them in Store.stores. Store.GetKVStore() returns the store from Store.stores, and Store.Write() recursively calls CacheWrap.Write() on the substores.
DBAdapter
dbadapter.Store is a adapter for dbm.DB making it fulfilling the KVStore interface.
type Store struct {
dbm.DB
}
dbadapter.Store embeds dbm.DB, so most of the KVStore interface functions are implemented. The other functions(mostly miscellaneous) are manually implemented.
IAVL
iavl.Store is a base-layer self-balancing merkle tree. It is guaranteed that
- Get & set operations are
O(log n), wherenis the number of elements in the tree - Iteration efficiently returns the sorted elements within the range
- Each tree version is immutable and can be retrieved even after a commit(depending on the pruning settings)
Specification and implementation of IAVL tree can be found in https://github.com/tendermint/iavl.
GasKV
gaskv.Store is a wrapper KVStore which provides gas consuming functionalities over the underlying KVStore.
type Store struct {
gasMeter types.GasMeter
gasConfig types.GasConfig
parent types.KVStore
}
When each KVStore methods are called, gaskv.Store automatically consumes appropriate amount of gas depending on the Store.gasConfig.
Prefix
prefix.Store is a wrapper KVStore which provides automatic key-prefixing functionalities over the underlying KVStore.
type Store struct {
parent types.KVStore
prefix []byte
}
When Store.{Get, Set}() is called, the store forwards the call to its parent, with the key prefixed with the Store.prefix.
When Store.Iterator() is called, it does not simply prefix the Store.prefix, since it does not work as intended. In that case, some of the elements are traversed even they are not starting with the prefix.
RootMulti
rootmulti.Store is a base-layer MultiStore where multiple KVStore can be mounted on it and retrieved via object-capability keys. The keys are memory addresses, so it is impossible to forge the key unless an object is a valid owner(or a receiver) of the key, according to the object capability principles.
TraceKV
tracekv.Store is a wrapper KVStore which provides operation tracing functionalities over the underlying KVStore.
type Store struct {
parent types.KVStore
writer io.Writer
context types.TraceContext
}
When each KVStore methods are called, tracekv.Store automatically logs traceOperation to the Store.writer.
type traceOperation struct {
Operation operation
Key string
Value string
Metadata map[string]interface{}
}
traceOperation.Metadata is filled with Store.context when it is not nil. TraceContext is a map[string]interface{}.
Transient
transient.Store is a base-layer KVStore which is automatically discarded at the end of the block.
type Store struct {
dbadapter.Store
}
Store.Store is a dbadapter.Store with a dbm.NewMemDB(). All KVStore methods are reused. When Store.Commit() is called, new dbadapter.Store is assigned, discarding previous reference and making it garbage collected.