Skip to content

Commit a33a22f

Browse files
Address PR comments
1 parent f3bafaa commit a33a22f

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

baseapp/baseapp.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -620,17 +620,12 @@ func (app *BaseApp) getContextForTx(mode sdk.ExecMode, txBytes []byte) sdk.Conte
620620
return ctx
621621
}
622622

623-
type poolingStore interface {
624-
storetypes.MultiStore
625-
CacheMultiStorePooled() storetypes.PooledCacheMultiStore
626-
}
627-
628623
// cacheTxContext returns a new context based off of the provided context with
629624
// a branched multi-store.
630625
func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context, storetypes.CacheMultiStore) {
631626
ms := ctx.MultiStore()
632627
var msCache storetypes.CacheMultiStore
633-
if msPooled, ok := ms.(poolingStore); ok {
628+
if msPooled, ok := ms.(storetypes.PoolingMultiStore); ok {
634629
msCache = msPooled.CacheMultiStorePooled()
635630
} else {
636631
msCache = ms.CacheMultiStore()

store/cachekv/internal/btree.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func NewBTree() BTree {
3636
}
3737
}
3838

39+
// Clear clears the tree.
3940
func (bt BTree) Clear() {
4041
bt.tree.Clear()
4142
}

store/cachekv/store.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ type Store struct {
3232
parent types.KVStore
3333
}
3434

35+
// PooledStore wraps a Store object and implements the types.PooledCacheKVStore interface,
36+
// which allows it to be pooled and reused without the overhead of allocation.
3537
type PooledStore struct {
3638
Store
3739
}
@@ -60,13 +62,15 @@ var storePool = sync.Pool{
6062
},
6163
}
6264

65+
// Release releases the PooledStore object back to the pool.
6366
func (store *PooledStore) Release() {
6467
store.resetCaches()
6568
store.parent = nil
6669
store.mtx = sync.Mutex{}
6770
storePool.Put(store)
6871
}
6972

73+
// NewPooledStore gets a PooledStore object from the pool.
7074
func NewPooledStore(parent types.KVStore) *PooledStore {
7175
store := storePool.Get().(*PooledStore)
7276
store.parent = parent

store/cachemulti/store.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@ type Store struct {
3434
traceContext types.TraceContext
3535
}
3636

37+
// PooledStore is a wrapper around Store that implements the PooledCacheKVStore interface.
38+
// It's used to avoid allocating new Store instances .
3739
type PooledStore struct {
3840
Store
3941
}
4042

41-
var _ types.CacheMultiStore = &Store{}
42-
43-
var _ types.PooledCacheMultiStore = &PooledStore{}
43+
var (
44+
_ types.CacheMultiStore = &Store{}
45+
_ types.PooledCacheMultiStore = &PooledStore{}
46+
)
4447

4548
// NewFromKVStore creates a new Store object from a mapping of store keys to
4649
// CacheWrapper objects and a KVStore as the database. Each CacheWrapper store
@@ -91,6 +94,8 @@ var storePool = sync.Pool{
9194
},
9295
}
9396

97+
// newFromKVStorePooled returns a PooledStore object, populated with a mapping of store keys to
98+
// CacheWrapper objects and a KVStore as the database.
9499
func newFromKVStorePooled(
95100
store types.KVStore, stores map[types.StoreKey]types.CacheWrap,
96101
traceWriter io.Writer, traceContext types.TraceContext,
@@ -113,6 +118,7 @@ func newFromKVStorePooled(
113118
return cms
114119
}
115120

121+
// Release releases the PooledStore object back to the pool.
116122
func (cms *PooledStore) Release() {
117123
// clear the stores map
118124
for k, v := range cms.stores {
@@ -202,6 +208,7 @@ func (cms *Store) CacheMultiStore() types.CacheMultiStore {
202208
return newCacheMultiStoreFromCMS(cms)
203209
}
204210

211+
// CacheMultiStorePooled returns a PooledCacheMultiStore object from a pool.
205212
func (cms *Store) CacheMultiStorePooled() types.PooledCacheMultiStore {
206213
return newFromKVStorePooled(cms.db, cms.stores, cms.traceWriter, cms.traceContext)
207214
}

store/types/store.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,19 @@ type MultiStore interface {
146146
LatestVersion() int64
147147
}
148148

149+
// PoolingMultiStore is a MultiStore that can return CacheMultiStores from a pool, without needing to allocate a new one each time.
150+
type PoolingMultiStore interface {
151+
MultiStore
152+
CacheMultiStorePooled() PooledCacheMultiStore
153+
}
154+
149155
// CacheMultiStore extends MultiStore with a Write() method.
150156
type CacheMultiStore interface {
151157
MultiStore
152158
Write() // Writes operations to underlying KVStore
153159
}
154160

161+
// PooledCacheMultiStore is a CacheMultiStore that can be pooled and reused without the overhead of allocation.
155162
type PooledCacheMultiStore interface {
156163
CacheMultiStore
157164
Release() // Releases the cache

0 commit comments

Comments
 (0)