diff --git a/store/branchkv/README.md b/store/kv/branch/README.md similarity index 81% rename from store/branchkv/README.md rename to store/kv/branch/README.md index 3732cfc85063..8c8a132bf428 100644 --- a/store/branchkv/README.md +++ b/store/kv/branch/README.md @@ -1,7 +1,7 @@ -# branchkv +# Branch KVStore -The `branchkv.Store` implementation defines a `BranchedKVStore` that contains a -reference to a `VersionedDatabase`, i.e. an SS backend. The `branchkv.Store` is +The `branch.Store` implementation defines a `BranchedKVStore` that contains a +reference to a `VersionedDatabase`, i.e. an SS backend. The `branch.Store` is meant to be used as the primary store used in a `RootStore` implementation. It provides the ability to get the current `ChangeSet`, branching, and writing to a parent store (if one is defined). Note, all reads first pass through the diff --git a/store/branchkv/iterator.go b/store/kv/branch/iterator.go similarity index 99% rename from store/branchkv/iterator.go rename to store/kv/branch/iterator.go index 77705f014e6a..ef676d4d30c9 100644 --- a/store/branchkv/iterator.go +++ b/store/kv/branch/iterator.go @@ -1,4 +1,4 @@ -package branchkv +package branch import ( "slices" diff --git a/store/branchkv/store.go b/store/kv/branch/store.go similarity index 98% rename from store/branchkv/store.go rename to store/kv/branch/store.go index 0d75cdc08bc8..1a0c73122946 100644 --- a/store/branchkv/store.go +++ b/store/kv/branch/store.go @@ -1,4 +1,4 @@ -package branchkv +package branch import ( "io" @@ -8,7 +8,7 @@ import ( "golang.org/x/exp/maps" "cosmossdk.io/store/v2" - "cosmossdk.io/store/v2/tracekv" + "cosmossdk.io/store/v2/kv/trace" ) var _ store.BranchedKVStore = (*Store)(nil) @@ -104,7 +104,7 @@ func (s *Store) Branch() store.BranchedKVStore { } func (s *Store) BranchWithTrace(w io.Writer, tc store.TraceContext) store.BranchedKVStore { - return NewWithParent(tracekv.New(s, w, tc)) + return NewWithParent(trace.New(s, w, tc)) } func (s *Store) Has(key []byte) bool { diff --git a/store/branchkv/store_test.go b/store/kv/branch/store_test.go similarity index 99% rename from store/branchkv/store_test.go rename to store/kv/branch/store_test.go index d1cfacfa45cf..3e5562075e7d 100644 --- a/store/branchkv/store_test.go +++ b/store/kv/branch/store_test.go @@ -1,4 +1,4 @@ -package branchkv_test +package branch_test import ( "fmt" @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/suite" "cosmossdk.io/store/v2" - "cosmossdk.io/store/v2/branchkv" + "cosmossdk.io/store/v2/kv/branch" "cosmossdk.io/store/v2/storage/sqlite" ) @@ -38,7 +38,7 @@ func (s *StoreTestSuite) SetupTest() { s.Require().NoError(storage.ApplyChangeset(1, cs)) - kvStore, err := branchkv.New(storeKey, storage) + kvStore, err := branch.New(storeKey, storage) s.Require().NoError(err) s.storage = storage diff --git a/store/kv/mem/README.md b/store/kv/mem/README.md new file mode 100644 index 000000000000..2badebbddc4e --- /dev/null +++ b/store/kv/mem/README.md @@ -0,0 +1,8 @@ +# Memory KVStore + +The `mem.Store` implementation defines an in-memory `KVStore`, which is internally +backed by a thread-safe BTree. The `mem.Store` does not provide any branching +functionality and should be used as an ephemeral store, typically reset between +blocks. A `mem.Store` contains no reference to a parent store, but can be used +as a parent store for other stores. The `mem.Store` is can be useful for testing +purposes and where state persistence is not required or should be ephemeral. diff --git a/store/memkv/iterator.go b/store/kv/mem/iterator.go similarity index 99% rename from store/memkv/iterator.go rename to store/kv/mem/iterator.go index 81d58de3de9c..e6d58437ca16 100644 --- a/store/memkv/iterator.go +++ b/store/kv/mem/iterator.go @@ -1,4 +1,4 @@ -package memkv +package mem import ( "bytes" diff --git a/store/memkv/store.go b/store/kv/mem/store.go similarity index 99% rename from store/memkv/store.go rename to store/kv/mem/store.go index b0914f745489..eb008a9f4dbf 100644 --- a/store/memkv/store.go +++ b/store/kv/mem/store.go @@ -1,4 +1,4 @@ -package memkv +package mem import ( "bytes" diff --git a/store/memkv/store_test.go b/store/kv/mem/store_test.go similarity index 98% rename from store/memkv/store_test.go rename to store/kv/mem/store_test.go index d20a22f0db5c..3ef90ceb6ed4 100644 --- a/store/memkv/store_test.go +++ b/store/kv/mem/store_test.go @@ -1,4 +1,4 @@ -package memkv_test +package mem_test import ( "fmt" @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/suite" "cosmossdk.io/store/v2" - "cosmossdk.io/store/v2/memkv" + "cosmossdk.io/store/v2/kv/mem" ) const storeKey = "storeKey" @@ -23,7 +23,7 @@ func TestStorageTestSuite(t *testing.T) { } func (s *StoreTestSuite) SetupTest() { - s.kvStore = memkv.New(storeKey) + s.kvStore = mem.New(storeKey) } func (s *StoreTestSuite) TestGetStoreType() { diff --git a/store/tracekv/README.md b/store/kv/trace/README.md similarity index 66% rename from store/tracekv/README.md rename to store/kv/trace/README.md index eda74979d8ed..9486e158bf8b 100644 --- a/store/tracekv/README.md +++ b/store/kv/trace/README.md @@ -1,15 +1,15 @@ -# tracekv +# Trace KVStore -The `tracekv.Store` implementation defines a store which wraps a parent `KVStore` +The `trace.Store` implementation defines a store which wraps a parent `KVStore` and traces all operations performed on it. Each trace operation is written to a provided `io.Writer` object. Specifically, a `TraceOperation` object is JSON encoded and written to the writer. The `TraceOperation` object contains the exact operation, e.g. a read or write, and the corresponding key and value pair. -A `tracekv.Store` can also be instantiated with a `store.TraceContext` which +A `trace.Store` can also be instantiated with a `store.TraceContext` which can allow each traced operation to include additional metadata, e.g. a block height or hash. -Note, `tracekv.Store` is not meant to be branched or written to. The parent `KVStore` -is responsible for all branching and writing operations, while a `tracekv.Store` +Note, `trace.Store` is not meant to be branched or written to. The parent `KVStore` +is responsible for all branching and writing operations, while a `trace.Store` wraps such a store and traces all relevant operations on it. diff --git a/store/tracekv/doc.go b/store/kv/trace/doc.go similarity index 67% rename from store/tracekv/doc.go rename to store/kv/trace/doc.go index b0d215adc9e0..1f29746ffbbb 100644 --- a/store/tracekv/doc.go +++ b/store/kv/trace/doc.go @@ -1,7 +1,7 @@ /* -Package tracekv provides a KVStore implementation that wraps a parent KVStore +Package trace provides a KVStore implementation that wraps a parent KVStore and allows all operations to be traced to an io.Writer. This can be useful to serve use cases such as tracing and digesting all read operations for a specific store key and key or value. */ -package tracekv +package trace diff --git a/store/tracekv/iterator.go b/store/kv/trace/iterator.go similarity index 98% rename from store/tracekv/iterator.go rename to store/kv/trace/iterator.go index 7ee39d583792..98de8b2d1ce8 100644 --- a/store/tracekv/iterator.go +++ b/store/kv/trace/iterator.go @@ -1,4 +1,4 @@ -package tracekv +package trace import ( "io" diff --git a/store/tracekv/store.go b/store/kv/trace/store.go similarity index 99% rename from store/tracekv/store.go rename to store/kv/trace/store.go index 549cd345f5cc..0bb0ff2d648a 100644 --- a/store/tracekv/store.go +++ b/store/kv/trace/store.go @@ -1,4 +1,4 @@ -package tracekv +package trace import ( "encoding/base64" diff --git a/store/tracekv/store_test.go b/store/kv/trace/store_test.go similarity index 97% rename from store/tracekv/store_test.go rename to store/kv/trace/store_test.go index 6f5a9f914520..1a226357710e 100644 --- a/store/tracekv/store_test.go +++ b/store/kv/trace/store_test.go @@ -1,4 +1,4 @@ -package tracekv_test +package trace_test import ( "bytes" @@ -9,8 +9,8 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/store/v2" - "cosmossdk.io/store/v2/memkv" - "cosmossdk.io/store/v2/tracekv" + "cosmossdk.io/store/v2/kv/mem" + "cosmossdk.io/store/v2/kv/trace" ) const storeKey = "storeKey" @@ -32,10 +32,10 @@ func newTraceKVStore(w io.Writer) store.KVStore { } func newEmptyTraceKVStore(w io.Writer) store.KVStore { - memKVStore := memkv.New(storeKey) + memKVStore := mem.New(storeKey) tc := store.TraceContext(map[string]any{"blockHeight": 64}) - return tracekv.New(memKVStore, w, tc) + return trace.New(memKVStore, w, tc) } func TestTraceKVStoreGet(t *testing.T) { diff --git a/store/memkv/README.md b/store/memkv/README.md deleted file mode 100644 index 52c07346498b..000000000000 --- a/store/memkv/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# memkv - -The `memkv.Store` implementation defines an in-memory `KVStore`, which is internally -backed by a thread-safe BTree. The `memkv.Store` does not provide any branching -functionality and should be used as an ephemeral store, typically reset between -blocks. A `memkv.Store` contains no reference to a parent store, but can be used -as a parent store for other stores. The `memkv.Store` is can be useful for testing -purposes and where state persistence is not required or should be ephemeral. diff --git a/store/root/store.go b/store/root/store.go index fb3e5ed904de..b3d048c2bb21 100644 --- a/store/root/store.go +++ b/store/root/store.go @@ -10,9 +10,9 @@ import ( "cosmossdk.io/log" "cosmossdk.io/store/v2" - "cosmossdk.io/store/v2/branchkv" "cosmossdk.io/store/v2/commitment" - "cosmossdk.io/store/v2/tracekv" + "cosmossdk.io/store/v2/kv/branch" + "cosmossdk.io/store/v2/kv/trace" ) // defaultStoreKey defines the default store key used for the single SC backend. @@ -62,7 +62,7 @@ func New( ss store.VersionedDatabase, sc *commitment.Database, ) (store.RootStore, error) { - rootKVStore, err := branchkv.New(defaultStoreKey, ss) + rootKVStore, err := branch.New(defaultStoreKey, ss) if err != nil { return nil, err } @@ -184,7 +184,7 @@ func (s *Store) LoadVersion(v uint64) (err error) { // root KVStore using Write(). func (s *Store) GetKVStore(_ string) store.KVStore { if s.TracingEnabled() { - return tracekv.New(s.rootKVStore, s.traceWriter, s.traceContext) + return trace.New(s.rootKVStore, s.traceWriter, s.traceContext) } return s.rootKVStore @@ -192,7 +192,7 @@ func (s *Store) GetKVStore(_ string) store.KVStore { func (s *Store) GetBranchedKVStore(_ string) store.BranchedKVStore { if s.TracingEnabled() { - return tracekv.New(s.rootKVStore, s.traceWriter, s.traceContext) + return trace.New(s.rootKVStore, s.traceWriter, s.traceContext) } return s.rootKVStore