fix(x/slashing): migrate signing info on SignedBlocksWindow change#26017
fix(x/slashing): migrate signing info on SignedBlocksWindow change#26017SaswataPatra wants to merge 4 commits intocosmos:mainfrom
Conversation
Fixes cosmos#12541 When the SignedBlocksWindow parameter changes via governance, validator signing info and missed block bitmaps must be migrated to prevent incorrect MissedBlocksCounter values and orphaned bitmap data. This implementation uses proportional scaling with bitmap adjustment to preserve validators' relative miss rates while ensuring bitmap-counter invariants remain intact. The approach prevents both unfair immediate slashing and validators receiving undeserved clean slates. The migration logic: 1. Calculates proportional counter: oldCounter × (newWindow / oldWindow) 2. Truncates bitmap to new window size 3. Adjusts bitmap to match proportional counter: - Excess misses: removes from earliest positions - Insufficient misses: adds at positions visited last 4. Updates IndexOffset: oldOffset % newWindow This ensures bitmap and counter remain synchronized while maintaining fairness across window size changes.
Greptile SummaryThis PR implements automatic migration of validator signing info and missed block bitmaps when the Key changes:
Critical issues found:
Test coverage: Comprehensive tests for single-validator scenarios covering window shrinkage, expansion, and edge cases. However, tests don't cover multi-validator scenarios or error conditions. Confidence Score: 2/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[UpdateParams Called] --> B{SignedBlocksWindow Changed?}
B -->|No| C[Update Params]
B -->|Yes| D[Get Old Window Size]
D --> E[Call MigrateSignedBlocksWindow]
E --> F[Iterate All Validators]
F --> G[Calculate Proportional Counter]
G --> H[Read Missed Positions from Old Bitmap]
H --> I[Delete Old Bitmap]
I --> J{actualMissedCount vs proportionalCounter?}
J -->|More misses| K[Remove excess from left]
J -->|Fewer misses| L[Add fabricated misses at positions visited last]
J -->|Equal| M[Keep existing positions]
K --> N[Write Adjusted Bitmap]
L --> N
M --> N
N --> O[Update MissedBlocksCounter]
O --> P[Update IndexOffset % newWindow]
P --> Q[Save ValidatorSigningInfo]
Q --> R{More Validators?}
R -->|Yes| F
R -->|No| S{Migration Successful?}
S -->|Yes| C
S -->|No| T[Return Error - Params NOT Updated]
style T fill:#ff6b6b
style S fill:#ffd93d
style Q fill:#6bcf7f
Last reviewed commit: 67634c0 |
Added comprehensive test cases for the migration of validator signing info and missed block bitmaps when the SignedBlocksWindow parameter changes. The new tests cover scenarios with multiple validators and handle corrupted state guards, ensuring that the migration logic correctly adjusts missed blocks and counters while maintaining fairness and integrity across validators.
…swataPatra/cosmos-sdk into fix/slashing-window-migration
SaswataPatra
left a comment
There was a problem hiding this comment.
Fixed in latest commit: we now collect validators first and migrate in a loop so errors propagate; also added overflow guard by clamping MissedBlocksCounter to oldWindow.”
|
@SaswataPatra conflicts |
Fixes #12541
When the SignedBlocksWindow parameter changes via governance, validator signing info and missed block bitmaps must be migrated to prevent incorrect MissedBlocksCounter values and orphaned bitmap data.
This implementation uses proportional scaling with bitmap adjustment to preserve validators' relative miss rates while ensuring bitmap-counter invariants remain intact. The approach prevents both unfair immediate slashing and validators receiving undeserved clean slates.
The migration logic:
This ensures bitmap and counter remain synchronized while maintaining fairness across window size changes.
Description
Closes: #XXXX