Skip to content

Commit 55eef37

Browse files
committed
fix: staking optimization, add integration tests for staking cache
1 parent 308d80e commit 55eef37

File tree

10 files changed

+1310
-154
lines changed

10 files changed

+1310
-154
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
timeout-minutes: 240
2020
strategy:
2121
matrix:
22-
tests: [unmarked, ibc, ibc_rly_evm, ibc_rly_gas, ibc_timeout, ibc_update_client, ica, gov, upgrade, slow, gas, mint]
22+
tests: [unmarked, ibc, ibc_rly_evm, ibc_rly_gas, ibc_timeout, ibc_update_client, ica, gov, upgrade, slow, gas, staking]
2323
env:
2424
TESTS_TO_RUN: ${{ matrix.tests }}
2525
steps:

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## UNRELEASED
44

5+
* [#1907](https://github.com/crypto-org-chain/cronos/pull/1907) fix: Optimize staking endblocker with an in-memory KV store and standardize gas consumption for staking related messages
6+
57
*Nov 30, 2025*
68

79
## v1.5.4

app/app.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ func StoreKeys() (
234234
map[string]*storetypes.KVStoreKey,
235235
map[string]*storetypes.TransientStoreKey,
236236
map[string]*storetypes.ObjectStoreKey,
237+
map[string]*storetypes.MemoryStoreKey,
237238
) {
238239
storeKeys := []string{
239240
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
@@ -255,9 +256,10 @@ func StoreKeys() (
255256
}
256257
keys := storetypes.NewKVStoreKeys(storeKeys...)
257258
tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey)
259+
memKeys := storetypes.NewMemoryStoreKeys(stakingtypes.CacheStoreKey, cronostypes.MemStoreKey)
258260
okeys := storetypes.NewObjectStoreKeys(banktypes.ObjectStoreKey, evmtypes.ObjectStoreKey)
259261

260-
return keys, tkeys, okeys
262+
return keys, tkeys, okeys, memKeys
261263
}
262264

263265
var (
@@ -285,10 +287,10 @@ type App struct {
285287
pendingTxListeners []evmante.PendingTxListener
286288

287289
// keys to access the substores
288-
keys map[string]*storetypes.KVStoreKey
289-
tkeys map[string]*storetypes.TransientStoreKey
290-
okeys map[string]*storetypes.ObjectStoreKey
291-
290+
keys map[string]*storetypes.KVStoreKey
291+
tkeys map[string]*storetypes.TransientStoreKey
292+
okeys map[string]*storetypes.ObjectStoreKey
293+
memKeys map[string]*storetypes.MemoryStoreKey
292294
// keepers
293295
AccountKeeper authkeeper.AccountKeeper
294296
BankKeeper bankkeeper.Keeper
@@ -447,7 +449,7 @@ func New(
447449
bApp.SetInterfaceRegistry(interfaceRegistry)
448450
bApp.SetTxEncoder(txConfig.TxEncoder())
449451

450-
keys, tkeys, okeys := StoreKeys()
452+
keys, tkeys, okeys, memKeys := StoreKeys()
451453

452454
invCheckPeriod := cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod))
453455
app := &App{
@@ -461,6 +463,7 @@ func New(
461463
keys: keys,
462464
tkeys: tkeys,
463465
okeys: okeys,
466+
memKeys: memKeys,
464467
blockProposalHandler: blockProposalHandler,
465468
dummyCheckTx: cast.ToBool(appOpts.Get(FlagUnsafeDummyCheckTx)),
466469
}
@@ -516,14 +519,17 @@ func New(
516519
panic(err)
517520
}
518521
app.txConfig = txConfig
522+
stakingCacheSize := cast.ToInt(appOpts.Get(server.FlagStakingCacheSize))
519523
app.StakingKeeper = stakingkeeper.NewKeeper(
520524
appCodec,
521525
runtime.NewKVStoreService(keys[stakingtypes.StoreKey]),
526+
runtime.NewMemStoreService(memKeys[stakingtypes.CacheStoreKey]),
522527
app.AccountKeeper,
523528
app.BankKeeper,
524529
authAddr,
525530
address.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
526531
address.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
532+
stakingCacheSize,
527533
)
528534
app.MintKeeper = mintkeeper.NewKeeper(
529535
appCodec,
@@ -975,7 +981,7 @@ func New(
975981
app.MountKVStores(keys)
976982
app.MountTransientStores(tkeys)
977983
app.MountObjectStores(okeys)
978-
984+
app.MountMemoryStores(memKeys)
979985
// initialize BaseApp
980986
app.SetInitChainer(app.InitChainer)
981987
app.SetPreBlocker(app.PreBlocker)

cmd/cronosd/cmd/versiondb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func ChangeSetCmd() *cobra.Command {
17-
keys, _, _ := app.StoreKeys()
17+
keys, _, _, _ := app.StoreKeys()
1818
storeNames := make([]string, 0, len(keys))
1919
for name := range keys {
2020
storeNames = append(storeNames, name)

go.mod

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/cosmos/cosmos-db v1.1.3
2222
github.com/cosmos/cosmos-proto v1.0.0-beta.5
2323
github.com/cosmos/cosmos-sdk v0.53.0
24-
github.com/cosmos/gogoproto v1.7.0
24+
github.com/cosmos/gogoproto v1.7.2
2525
// release/v10.0.x
2626
github.com/cosmos/ibc-go/v10 v10.1.1
2727
github.com/cosmos/rosetta v0.50.12
@@ -34,15 +34,15 @@ require (
3434
github.com/grpc-ecosystem/grpc-gateway v1.16.0
3535
github.com/hashicorp/go-metrics v0.5.4
3636
github.com/linxGnu/grocksdb v1.10.2
37-
github.com/spf13/cast v1.9.2
37+
github.com/spf13/cast v1.10.0
3838
github.com/spf13/cobra v1.9.1
39-
github.com/spf13/pflag v1.0.6
40-
github.com/spf13/viper v1.20.1
39+
github.com/spf13/pflag v1.0.10
40+
github.com/spf13/viper v1.21.0
4141
github.com/stretchr/testify v1.11.1
4242
golang.org/x/crypto v0.41.0
4343
google.golang.org/genproto/googleapis/api v0.0.0-20250707201910-8d1bb00bc6a7
44-
google.golang.org/grpc v1.75.0
45-
google.golang.org/protobuf v1.36.8
44+
google.golang.org/grpc v1.75.1
45+
google.golang.org/protobuf v1.36.10
4646
gopkg.in/yaml.v2 v2.4.0
4747
)
4848

@@ -77,8 +77,8 @@ require (
7777
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
7878
github.com/bgentry/speakeasy v0.2.0 // indirect
7979
github.com/bits-and-blooms/bitset v1.22.0 // indirect
80-
github.com/btcsuite/btcd v0.24.2 // indirect
81-
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
80+
github.com/btcsuite/btcd v0.25.0 // indirect
81+
github.com/btcsuite/btcd/btcec/v2 v2.3.5 // indirect
8282
github.com/btcsuite/btcd/btcutil v1.1.6 // indirect
8383
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
8484
github.com/bytedance/sonic v1.14.0 // indirect
@@ -97,8 +97,7 @@ require (
9797
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
9898
github.com/coinbase/rosetta-sdk-go/types v1.0.0 // indirect
9999
github.com/cometbft/cometbft-db v0.15.0 // indirect
100-
github.com/consensys/bavard v0.1.27 // indirect
101-
github.com/consensys/gnark-crypto v0.16.0 // indirect
100+
github.com/consensys/gnark-crypto v0.18.1 // indirect
102101
github.com/cosmos/btcutil v1.0.5 // indirect
103102
github.com/cosmos/go-bip39 v1.0.0 // indirect
104103
github.com/cosmos/gogogateway v1.2.0 // indirect
@@ -196,7 +195,6 @@ require (
196195
github.com/minio/highwayhash v1.0.3 // indirect
197196
github.com/mitchellh/go-homedir v1.1.0 // indirect
198197
github.com/mitchellh/mapstructure v1.5.0 // indirect
199-
github.com/mmcloughlin/addchain v0.4.0 // indirect
200198
github.com/mtibben/percent v0.2.1 // indirect
201199
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
202200
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
@@ -221,11 +219,11 @@ require (
221219
github.com/rogpeppe/go-internal v1.14.1 // indirect
222220
github.com/rs/cors v1.11.1 // indirect
223221
github.com/rs/zerolog v1.34.0 // indirect
224-
github.com/sagikazarmark/locafero v0.7.0 // indirect
222+
github.com/sagikazarmark/locafero v0.11.0 // indirect
225223
github.com/sasha-s/go-deadlock v0.3.5 // indirect
226224
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
227-
github.com/sourcegraph/conc v0.3.0 // indirect
228-
github.com/spf13/afero v1.12.0 // indirect
225+
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
226+
github.com/spf13/afero v1.15.0 // indirect
229227
github.com/spiffe/go-spiffe/v2 v2.5.0 // indirect
230228
github.com/subosito/gotenv v1.6.0 // indirect
231229
github.com/supranational/blst v0.3.14 // indirect
@@ -234,15 +232,15 @@ require (
234232
github.com/tidwall/btree v1.7.0 // indirect
235233
github.com/tidwall/gjson v1.18.0 // indirect
236234
github.com/tidwall/match v1.1.1 // indirect
237-
github.com/tidwall/pretty v1.2.0 // indirect
235+
github.com/tidwall/pretty v1.2.1 // indirect
238236
github.com/tidwall/sjson v1.2.5 // indirect
239237
github.com/tidwall/tinylru v1.1.0 // indirect
240238
github.com/tidwall/wal v1.1.7 // indirect
241239
github.com/tklauser/go-sysconf v0.3.12 // indirect
242240
github.com/tklauser/numcpus v0.6.1 // indirect
243241
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
244242
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
245-
github.com/ulikunitz/xz v0.5.14 // indirect
243+
github.com/ulikunitz/xz v0.5.15 // indirect
246244
github.com/zbiljic/go-filelock v0.0.0-20170914061330-1dbf7103ab7d // indirect
247245
github.com/zeebo/errs v1.4.0 // indirect
248246
github.com/zondax/hid v0.9.2 // indirect
@@ -258,8 +256,8 @@ require (
258256
go.opentelemetry.io/otel/sdk v1.37.0 // indirect
259257
go.opentelemetry.io/otel/sdk/metric v1.37.0 // indirect
260258
go.opentelemetry.io/otel/trace v1.37.0 // indirect
261-
go.uber.org/multierr v1.11.0 // indirect
262259
go.yaml.in/yaml/v2 v2.4.2 // indirect
260+
go.yaml.in/yaml/v3 v3.0.4 // indirect
263261
golang.org/x/arch v0.17.0 // indirect
264262
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect
265263
golang.org/x/net v0.43.0 // indirect
@@ -271,20 +269,19 @@ require (
271269
golang.org/x/time v0.10.0 // indirect
272270
google.golang.org/api v0.222.0 // indirect
273271
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect
274-
google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7 // indirect
272+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250804133106-a7a43d27e69b // indirect
275273
gopkg.in/yaml.v3 v3.0.1 // indirect
276274
gotest.tools/v3 v3.5.2 // indirect
277275
nhooyr.io/websocket v1.8.11 // indirect
278276
pgregory.net/rapid v1.2.0 // indirect
279-
rsc.io/tmplfunc v0.0.3 // indirect
280277
sigs.k8s.io/yaml v1.6.0 // indirect
281278
)
282279

283280
replace (
284281
// release/v0.50.x
285282
cosmossdk.io/store => github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20241217090828-cfbca9fe8254
286283
cosmossdk.io/x/tx => github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20241217090828-cfbca9fe8254
287-
github.com/cosmos/cosmos-sdk => github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20251119062431-8d0a31ef043d
284+
github.com/cosmos/cosmos-sdk => github.com/randy-cro/cosmos-sdk v0.0.0-20251119072907-e049d43514b4
288285
)
289286

290287
replace (
@@ -306,7 +303,7 @@ replace (
306303
// release/v1.15
307304
github.com/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethereum v1.10.20-0.20250815065500-a4fbafcae0dd
308305
// release/v0.22.x
309-
github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.22.1-0.20251105021702-154426496ecd
306+
github.com/evmos/ethermint => github.com/randy-cro/ethermint v0.0.0-20251119073804-839af2319bac
310307
// Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities.
311308
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
312309
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0

0 commit comments

Comments
 (0)