Skip to content

Commit 1c5136e

Browse files
committed
fix: staking optimization, add integration tests for staking cache
1 parent 71cf364 commit 1c5136e

File tree

10 files changed

+1350
-54
lines changed

10 files changed

+1350
-54
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, mint, 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
### Improvements
68

79
* [#1903](https://github.com/crypto-org-chain/cronos/pull/1903) Feat: check authorization list in e2ee.

app/app.go

Lines changed: 14 additions & 8 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,
@@ -666,7 +672,7 @@ func New(
666672
app.CronosKeeper = *cronoskeeper.NewKeeper(
667673
appCodec,
668674
keys[cronostypes.StoreKey],
669-
keys[cronostypes.MemStoreKey],
675+
memKeys[cronostypes.MemStoreKey],
670676
app.BankKeeper,
671677
app.TransferKeeper,
672678
app.EvmKeeper,
@@ -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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ replace (
284284
// release/v0.50.x
285285
cosmossdk.io/store => github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20241217090828-cfbca9fe8254
286286
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
287+
// release/v0.50-cronosv1.6.x
288+
github.com/cosmos/cosmos-sdk => github.com/crypto-org-chain/cosmos-sdk v0.0.0-20251121110054-d5e74b9954c1
288289
)
289290

290291
replace (
@@ -305,8 +306,8 @@ replace (
305306
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2
306307
// release/v1.15
307308
github.com/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethereum v1.10.20-0.20250815065500-a4fbafcae0dd
308-
// release/v0.22.x
309-
github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.22.1-0.20251105021702-154426496ecd
309+
// release/v0.22.x-cronosv1.6-optstaking
310+
github.com/evmos/ethermint => github.com/randy-cro/ethermint v0.0.0-20251124083925-2498a0823d85
310311
// Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities.
311312
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
312313
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -906,14 +906,12 @@ github.com/crypto-org-chain/btree v0.0.0-20240406140148-2687063b042c h1:MOgfS4+F
906906
github.com/crypto-org-chain/btree v0.0.0-20240406140148-2687063b042c/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
907907
github.com/crypto-org-chain/cometbft v0.0.0-20251014161156-b0e778b18408 h1:7dfWkDRYCsguKrpd0t14nrZ3Xf/9aVHiQrWx5o0DCdo=
908908
github.com/crypto-org-chain/cometbft v0.0.0-20251014161156-b0e778b18408/go.mod h1:khbgmtxbgwJfMqDmnGY4rl2sQpTdzpPb1f9nqnfpy1o=
909-
github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20251119062431-8d0a31ef043d h1:ffzsdKbhbSSBIMBAGJGjezjEr60A/JgpznOJhMUMbfE=
910-
github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20251119062431-8d0a31ef043d/go.mod h1:8/AdT5lF3ILCCl/sDQXyBgzWGtcmD1tInWyhYeREVPA=
909+
github.com/crypto-org-chain/cosmos-sdk v0.0.0-20251121110054-d5e74b9954c1 h1:4aMpMx19bBo0vXDLx9jBtBW/BvWyOVW5SN4ciC7WhDc=
910+
github.com/crypto-org-chain/cosmos-sdk v0.0.0-20251121110054-d5e74b9954c1/go.mod h1:8/AdT5lF3ILCCl/sDQXyBgzWGtcmD1tInWyhYeREVPA=
911911
github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20241217090828-cfbca9fe8254 h1:NEgy0r3otU/O+0OAjMdEhbn4VotQlg+98hHbD7M23wU=
912912
github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20241217090828-cfbca9fe8254/go.mod h1:8DwVTz83/2PSI366FERGbWSH7hL6sB7HbYp8bqksNwM=
913913
github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20241217090828-cfbca9fe8254 h1:JzLOFRiKsDtLJt5h0M0jkEIPDKvFFyja7VEp7gG6O9U=
914914
github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20241217090828-cfbca9fe8254/go.mod h1:V6DImnwJMTq5qFjeGWpXNiT/fjgE4HtmclRmTqRVM3w=
915-
github.com/crypto-org-chain/ethermint v0.22.1-0.20251105021702-154426496ecd h1:R6G28wQwmbjLhtTp6qJQk8vRSk65b2LaA237hkrMpWo=
916-
github.com/crypto-org-chain/ethermint v0.22.1-0.20251105021702-154426496ecd/go.mod h1:StA36YNgLruMKlg6FG+fUie0+k3hQS8dapZJzl+CPI4=
917915
github.com/crypto-org-chain/go-block-stm v0.0.0-20241213061541-7afe924fb4a6 h1:6KPEi8dWkDSBddQb4NAvEXmNnTXymF3yVeTaT4Hz1iU=
918916
github.com/crypto-org-chain/go-block-stm v0.0.0-20241213061541-7afe924fb4a6/go.mod h1:iwQTX9xMX8NV9k3o2BiWXA0SswpsZrDk5q3gA7nWYiE=
919917
github.com/crypto-org-chain/go-ethereum v1.10.20-0.20250815065500-a4fbafcae0dd h1:ebSnzvM9yKVGFjvoGly7LFQQCS2HuOWMCvQyByJ52Gs=
@@ -1615,6 +1613,8 @@ github.com/prometheus/procfs v0.3.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O
16151613
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
16161614
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
16171615
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
1616+
github.com/randy-cro/ethermint v0.0.0-20251124070008-727854be8ff2 h1:g0670vTYe8JEZsp7wm1q/cNJN2QnXosJRQmmkEMDamk=
1617+
github.com/randy-cro/ethermint v0.0.0-20251124070008-727854be8ff2/go.mod h1:5UFsxp0fS2B5Bh1QZvTYedkmHPEqHIS/4kfRIwyDDVQ=
16181618
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
16191619
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
16201620
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=

gomod2nix.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ schema = 3
216216
version = "v1.0.0-beta.5"
217217
hash = "sha256-Fy/PbsOsd6iq0Njy3DVWK6HqWsogI+MkE8QslHGWyVg="
218218
[mod."github.com/cosmos/cosmos-sdk"]
219-
version = "v0.50.6-0.20251119062431-8d0a31ef043d"
220-
hash = "sha256-VxQus9ynUK8nAZh3ubNXRcxJsITzgndjd7UYYgMt6C0="
219+
version = "v0.0.0-20251121110054-d5e74b9954c1"
220+
hash = "sha256-XzBX/BIFpKZWMBqyGML0RpSBHMnQu1QVY9+dMi85mws="
221221
replaced = "github.com/crypto-org-chain/cosmos-sdk"
222222
[mod."github.com/cosmos/go-bip39"]
223223
version = "v1.0.0"
@@ -315,9 +315,9 @@ schema = 3
315315
version = "v0.2.2"
316316
hash = "sha256-0MLfSJKdeK3Z7tWAXTdzwB4091dmyxIX38S5SKH5QAw="
317317
[mod."github.com/evmos/ethermint"]
318-
version = "v0.22.1-0.20251105021702-154426496ecd"
319-
hash = "sha256-VU/v4owuoa6L9BffE/8dN/fEU7cJTZPwIUyNxDBjvdE="
320-
replaced = "github.com/crypto-org-chain/ethermint"
318+
version = "v0.0.0-20251124070008-727854be8ff2"
319+
hash = "sha256-pO/7DjbdxeCTtO4TAQFChkfDmP5qSxpB65S85a/W0nY="
320+
replaced = "github.com/randy-cro/ethermint"
321321
[mod."github.com/fatih/color"]
322322
version = "v1.17.0"
323323
hash = "sha256-QsKMy3MsvjbYNcA9jP8w6c3wpmWDZ0079bybAEzmXR0="

0 commit comments

Comments
 (0)