fix: staking optimization
Description
To address the issue of slow nodes due to heavy i/o in staking endblocker, two key changes were introduced:
-
Use of an in-memory KV store to manage staking caches.
Reference -
Implementation of fixed gas consumption for staking-related messages to ensure consistent gas usage.
Reference
PR Checklist:
- [ ] Have you read the CONTRIBUTING.md?
- [ ] Does your PR follow the C4 patch requirements?
- [ ] Have you rebased your work on top of the latest master?
- [ ] Have you checked your code compiles? (
make) - [ ] Have you included tests for any non-trivial functionality?
- [ ] Have you checked your code passes the unit tests? (
make test) - [ ] Have you checked your code formatting is correct? (
go fmt) - [ ] Have you checked your basic code style is fine? (
golangci-lint run) - [ ] If you added any dependencies, have you checked they do not contain any known vulnerabilities? (
go list -json -m all | nancy sleuth) - [ ] If your changes affect the client infrastructure, have you run the integration test?
- [ ] If your changes affect public APIs, does your PR follow the C4 evolution of public contracts?
- [ ] If your code changes public APIs, have you incremented the crate version numbers and documented your changes in the CHANGELOG.md?
- [ ] If you are contributing for the first time, please read the agreement in CONTRIBUTING.md now and add a comment to this pull request stating that your PR is in accordance with the Developer's Certificate of Origin.
Thank you for your code, it's appreciated! :)
Summary by CodeRabbit
-
New Features
- Staking CLI: fixed-gas staking flows, new staking query commands, and support for min self-delegation when editing validators.
-
Tests
- CI test matrix now includes staking.
- New end-to-end staking cache tests covering delegations, redelegations, unbonding, validator unbonding, and cross-node consistency.
-
Improvements
- Standardized gas usage for staking operations and expanded staking cache scenarios.
-
Bug Fixes
- Fixed multiple transaction replacement issue.
-
Chores
- Updated changelog and bumped several module dependencies.
✏️ Tip: You can customize this high-level summary in your review settings.
@randy-cro your pull request is missing a changelog!
Walkthrough
App startup now exposes and mounts memory-backed stores (memKeys) and wires them into keepers; staking CI adds a staking job; integration tests and CLI add staking flows and cache-size scenarios; dependencies and nix metadata updated; changelog extended.
Changes
| Cohort / File(s) | Summary |
|---|---|
Memory store wiring app/app.go, cmd/cronosd/cmd/versiondb.go |
StoreKeys() now returns map[string]*storetypes.MemoryStoreKey; App gains memKeys; New captures/assigns memKeys; memory stores mounted via MountMemoryStores(memKeys); StakingKeeper/CronosKeeper constructors updated; callers updated to accept extra return value (versiondb command ignores the extra value). |
Integration-tests workflow .github/workflows/test.yml |
Adds staking to the test matrix; no other workflow logic changes. |
Integration test CLI & staking RPCs integration_tests/cosmoscli.py |
Adds STAKING_DEFAULT_GAS; new query methods get_delegations, get_unbonding_delegations, get_redelegations; staking ops updated to use fixed gas parameters and signatures adjusted (delegate_amount, unbond_amount, redelegate_amount, edit_validator accepts min_self_delegation). |
Staking cache integration tests & config integration_tests/configs/staking_cache.jsonnet, integration_tests/test_staking_cache.py |
New 7-validator config with varied per-node staking cache sizes and accounts; adds pytest fixture cronos_staking_cache and tests for multiple unbondings, redelegations, validator unbonding, and cross-node consistency. |
Changelog update CHANGELOG.md |
Updates UNRELEASED and v1.5.x entries (adds PR #1907, adjustments and dates). |
Dependency updates & nix metadata go.mod, gomod2nix.toml |
Bumps module versions (gogoproto, btcd, btcec, google genproto, etc.); updates replace directives to forked sources (cosmos-sdk/ethermint) and refreshes nix metadata/hashes. |
Misc (calculator/example) src/calculator.py |
Adds coderabbit_add, changes coderabbit_formula(x,y) → coderabbit_formula(x,y,z), renames old_global_var → new_global_var. |
Sequence Diagram(s)
sequenceDiagram
participant App as App Init
participant Mem as MemoryStoreMgr
participant Keepers as Keepers (Staking/Cronos)
participant KV as PersistentKV
rect rgb(247,250,255)
note over App,Mem: Startup — expose & mount memory stores
App->>Mem: StoreKeys() -> memKeys
App->>App: MountMemoryStores(memKeys)
App->>Keepers: New(..., MemStoreService(memKeys[staking]))
end
rect rgb(240,248,255)
note over Keepers,Mem: Runtime — cache lookup/update flow
Keepers->>Mem: query cache for queue entries
alt cache hit
Mem-->>Keepers: cached entries
else cache miss
Keepers->>KV: iterate persistent KV for entries
KV-->>Keepers: entries
Keepers->>Mem: update cache
end
end
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
- Focus review on:
-
app/app.go: memKeys creation, MountMemoryStores ordering, keeper constructor changes. -
integration_tests/cosmoscli.pyandintegration_tests/test_staking_cache.py: staking gas behavior, new query methods, timing and cross-node assertions. -
go.mod/gomod2nix.toml: replace targets, version/hash consistency.
-
Possibly related PRs
- crypto-org-chain/cronos#1804 — edits around
StoreKeyssignature and memKeys/memory-store APIs. - crypto-org-chain/cronos#1782 — similar memKeys propagation and app store-key handling.
- crypto-org-chain/cronos#1638 — related dependency/version and replace-target updates.
Suggested labels
cronos
Suggested reviewers
- calvinaco
- songgaoye
Poem
🐰 I cached my carrots in a tiny mem heap,
Seven validators hummed while ledgers did leap,
Delegate, unbond, redelegate—hops in the night,
Tests march the nodes till each state is right,
A rabbit’s small cheer for memory stores neat.
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 64.71% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title 'fix: staking optimization' accurately reflects the main objective of the PR, which is to optimize staking performance by addressing slow nodes caused by heavy I/O through in-memory caching and fixed gas consumption. |
✨ Finishing touches
- [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
- [ ] Commit unit tests in branch
fix/staking-optimization
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
| Diff | Package | Supply Chain Security |
Vulnerability | Quality | Maintenance | License |
|---|---|---|---|---|---|---|
| golang/github.com/randy-cro/ethermint@v0.0.0-20251121082919-46c057ac4dde | ||||||
| golang/github.com/crypto-org-chain/cosmos-sdk@v0.50.6-0.20251119062431-8d0a31ef043d ⏵ v0.0.0-20251121110054-d5e74b9954c1 | ||||||
| golang/github.com/cosmos/gogoproto@v1.7.2 |
Lets change the target to main
v1.6.x is scheduled to be released soon and we do not have time to test this feature