From 90869136e83edc400d28cf9270cc5b2fb177a0f6 Mon Sep 17 00:00:00 2001 From: yihuang Date: Mon, 11 Nov 2024 11:23:33 +0800 Subject: [PATCH] Problem: versiondb NewKVStore don't accept string as store name (#1684) * Problem: versiondb NewKVStore don't accept string as store name * Update CHANGELOG.md Signed-off-by: yihuang --------- Signed-off-by: yihuang --- CHANGELOG.md | 4 ++++ versiondb/multistore.go | 4 ++-- versiondb/store.go | 16 ++++++++-------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 791dc7005e..7b2a0fa24c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ * [#1679](https://github.com/crypto-org-chain/cronos/pull/1679) Include no trace detail on insufficient balance fix. +### Improvements + +* [#1684](https://github.com/crypto-org-chain/cronos/pull/1684) versiondb NewKVStore accept string as store name. + *Nov 6, 2024* ## v1.4.0-rc3 diff --git a/versiondb/multistore.go b/versiondb/multistore.go index a88850d0d3..a251fbc87a 100644 --- a/versiondb/multistore.go +++ b/versiondb/multistore.go @@ -36,7 +36,7 @@ func NewMultiStore( ) *MultiStore { stores := make(map[types.StoreKey]types.KVStore, len(storeKeys)) for _, k := range storeKeys { - stores[k] = NewKVStore(versionDB, k, nil) + stores[k] = NewKVStore(versionDB, k.Name(), nil) } return &MultiStore{ versionDB: versionDB, @@ -61,7 +61,7 @@ func (s *MultiStore) cacheMultiStore(version *int64) types.CacheMultiStore { if version == nil { stores[k] = s.stores[k] } else { - stores[k] = NewKVStore(s.versionDB, k, version) + stores[k] = NewKVStore(s.versionDB, k.Name(), version) } } return cachemulti.NewStore(nil, stores, nil, s.traceWriter, s.getTracingContext()) diff --git a/versiondb/store.go b/versiondb/store.go index 866b027e4e..28ddff401f 100644 --- a/versiondb/store.go +++ b/versiondb/store.go @@ -15,12 +15,12 @@ var _ types.KVStore = (*Store)(nil) // Store Implements types.KVStore type Store struct { - store VersionStore - storeKey types.StoreKey - version *int64 + store VersionStore + name string + version *int64 } -func NewKVStore(store VersionStore, storeKey types.StoreKey, version *int64) *Store { +func NewKVStore(store VersionStore, storeKey string, version *int64) *Store { return &Store{store, storeKey, version} } @@ -38,7 +38,7 @@ func (st *Store) CacheWrap() types.CacheWrap { // Implements types.KVStore. func (st *Store) Get(key []byte) []byte { defer telemetry.MeasureSince(time.Now(), "store", "versiondb", "get") - value, err := st.store.GetAtVersion(st.storeKey.Name(), key, st.version) + value, err := st.store.GetAtVersion(st.name, key, st.version) if err != nil { panic(err) } @@ -48,7 +48,7 @@ func (st *Store) Get(key []byte) []byte { // Implements types.KVStore. func (st *Store) Has(key []byte) (exists bool) { defer telemetry.MeasureSince(time.Now(), "store", "versiondb", "has") - has, err := st.store.HasAtVersion(st.storeKey.Name(), key, st.version) + has, err := st.store.HasAtVersion(st.name, key, st.version) if err != nil { panic(err) } @@ -57,7 +57,7 @@ func (st *Store) Has(key []byte) (exists bool) { // Implements types.KVStore. func (st *Store) Iterator(start, end []byte) types.Iterator { - itr, err := st.store.IteratorAtVersion(st.storeKey.Name(), start, end, st.version) + itr, err := st.store.IteratorAtVersion(st.name, start, end, st.version) if err != nil { panic(err) } @@ -66,7 +66,7 @@ func (st *Store) Iterator(start, end []byte) types.Iterator { // Implements types.KVStore. func (st *Store) ReverseIterator(start, end []byte) types.Iterator { - itr, err := st.store.ReverseIteratorAtVersion(st.storeKey.Name(), start, end, st.version) + itr, err := st.store.ReverseIteratorAtVersion(st.name, start, end, st.version) if err != nil { panic(err) }