Skip to content

Commit 6fee430

Browse files
Address PR comments
1 parent e6365dc commit 6fee430

File tree

13 files changed

+27
-21
lines changed

13 files changed

+27
-21
lines changed

baseapp/baseapp.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -693,17 +693,12 @@ func (app *BaseApp) getContextForTx(mode execMode, txBytes []byte) sdk.Context {
693693
return ctx
694694
}
695695

696-
type poolingStore interface {
697-
storetypes.MultiStore
698-
CacheMultiStorePooled() storetypes.PooledCacheMultiStore
699-
}
700-
701696
// cacheTxContext returns a new context based off of the provided context with
702697
// a branched multi-store.
703698
func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context, storetypes.CacheMultiStore) {
704699
ms := ctx.MultiStore()
705700
var msCache storetypes.CacheMultiStore
706-
if msPooled, ok := ms.(poolingStore); ok {
701+
if msPooled, ok := ms.(storetypes.PoolingMultiStore); ok {
707702
msCache = msPooled.CacheMultiStorePooled()
708703
} else {
709704
msCache = ms.CacheMultiStore()

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,4 @@ retract (
205205
v0.43.0
206206
)
207207

208-
replace cosmossdk.io/store => github.com/hyphacoop/cosmos-sdk/store v0.0.0-20250429164929-acbbfb9baf40
208+
replace cosmossdk.io/store => ./store

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,6 @@ github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0Jr
420420
github.com/huandu/skiplist v1.2.1 h1:dTi93MgjwErA/8idWTzIw4Y1kZsMWx35fmI2c8Rij7w=
421421
github.com/huandu/skiplist v1.2.1/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w=
422422
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
423-
github.com/hyphacoop/cosmos-sdk/store v0.0.0-20250429164929-acbbfb9baf40 h1:bNPGeuCvdmzN5j7Rp9D0emqZD4XJB5nLCKFtV59TyY8=
424-
github.com/hyphacoop/cosmos-sdk/store v0.0.0-20250429164929-acbbfb9baf40/go.mod h1:hMQGoX8OASEjyoShate33bT6zgSM1X9gIEhUBh7D084=
425423
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
426424
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
427425
github.com/improbable-eng/grpc-web v0.15.0 h1:BN+7z6uNXZ1tQGcNAuaU1YjsLTApzkjt2tzCixLaUPQ=

simapp/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,4 @@ replace (
239239
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
240240
)
241241

242-
replace cosmossdk.io/store => github.com/hyphacoop/cosmos-sdk/store v0.0.0-20250429164929-acbbfb9baf40
242+
replace cosmossdk.io/store => ../store

simapp/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,8 +1204,6 @@ github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0Jr
12041204
github.com/huandu/skiplist v1.2.1 h1:dTi93MgjwErA/8idWTzIw4Y1kZsMWx35fmI2c8Rij7w=
12051205
github.com/huandu/skiplist v1.2.1/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w=
12061206
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
1207-
github.com/hyphacoop/cosmos-sdk/store v0.0.0-20250429164929-acbbfb9baf40 h1:bNPGeuCvdmzN5j7Rp9D0emqZD4XJB5nLCKFtV59TyY8=
1208-
github.com/hyphacoop/cosmos-sdk/store v0.0.0-20250429164929-acbbfb9baf40/go.mod h1:hMQGoX8OASEjyoShate33bT6zgSM1X9gIEhUBh7D084=
12091207
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
12101208
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
12111209
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=

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 {
@@ -201,6 +207,7 @@ func (cms *Store) CacheMultiStore() types.CacheMultiStore {
201207
return newCacheMultiStoreFromCMS(cms)
202208
}
203209

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

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
// From MultiStore.CacheMultiStore()....
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

tests/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,4 @@ replace (
234234
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.1
235235
)
236236

237-
replace cosmossdk.io/store => github.com/hyphacoop/cosmos-sdk/store v0.0.0-20250429164929-acbbfb9baf40
237+
replace cosmossdk.io/store => ../store

tests/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,8 +1201,6 @@ github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0Jr
12011201
github.com/huandu/skiplist v1.2.1 h1:dTi93MgjwErA/8idWTzIw4Y1kZsMWx35fmI2c8Rij7w=
12021202
github.com/huandu/skiplist v1.2.1/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w=
12031203
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
1204-
github.com/hyphacoop/cosmos-sdk/store v0.0.0-20250429164929-acbbfb9baf40 h1:bNPGeuCvdmzN5j7Rp9D0emqZD4XJB5nLCKFtV59TyY8=
1205-
github.com/hyphacoop/cosmos-sdk/store v0.0.0-20250429164929-acbbfb9baf40/go.mod h1:hMQGoX8OASEjyoShate33bT6zgSM1X9gIEhUBh7D084=
12061204
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
12071205
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
12081206
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=

tests/systemtests/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,4 @@ require (
169169
sigs.k8s.io/yaml v1.4.0 // indirect
170170
)
171171

172-
replace cosmossdk.io/store => github.com/hyphacoop/cosmos-sdk/store v0.0.0-20250429164929-acbbfb9baf40
172+
replace cosmossdk.io/store => ../../store

tests/systemtests/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,6 @@ github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0Jr
412412
github.com/huandu/skiplist v1.2.1 h1:dTi93MgjwErA/8idWTzIw4Y1kZsMWx35fmI2c8Rij7w=
413413
github.com/huandu/skiplist v1.2.1/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w=
414414
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
415-
github.com/hyphacoop/cosmos-sdk/store v0.0.0-20250429164929-acbbfb9baf40 h1:bNPGeuCvdmzN5j7Rp9D0emqZD4XJB5nLCKFtV59TyY8=
416-
github.com/hyphacoop/cosmos-sdk/store v0.0.0-20250429164929-acbbfb9baf40/go.mod h1:hMQGoX8OASEjyoShate33bT6zgSM1X9gIEhUBh7D084=
417415
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
418416
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
419417
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=

0 commit comments

Comments
 (0)