-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(x/staking): stop validators from rotating to the same key on the same block #20649
Conversation
WalkthroughWalkthroughThe recent changes introduce a safeguard in the Changes
Sequence Diagram(s)sequenceDiagram
participant Validator1
participant Validator2
participant Keeper
participant Error
Validator1->>Keeper: Request to rotate to new consensus key
Keeper->>Keeper: Check if key is already used
Keeper-->>Validator1: Success (Key not used)
Validator2->>Keeper: Request to rotate to same consensus key
Keeper->>Keeper: Check if key is already used
Keeper->>Error: ErrConsensusPubKeyAlreadyUsedForValidator
Error-->>Validator2: Error (Key already used)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
@facundomedica your pull request is missing a changelog! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (2)
- x/staking/keeper/cons_pubkey.go (1 hunks)
- x/staking/keeper/msg_server_test.go (1 hunks)
Additional context used
Path-based instructions (2)
x/staking/keeper/cons_pubkey.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.x/staking/keeper/msg_server_test.go (2)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Pattern
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"
Additional comments not posted (1)
x/staking/keeper/msg_server_test.go (1)
1382-1407
: The testTestConsKeyRotationInSameBlock
correctly simulates the scenario where multiple validators attempt to rotate to the same consensus key within the same block, and it properly asserts that the second rotation should fail. This aligns well with the PR's objectives to prevent such behavior.
// check if there's another key rotation for this same key in the same block | ||
allRotations, err := k.GetBlockConsPubKeyRotationHistory(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
for _, r := range allRotations { | ||
if r.NewConsPubkey.Compare(newPubKey) == 0 { | ||
return types.ErrConsensusPubKeyAlreadyUsedForValidator | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic to prevent key rotation conflicts within the same block is correctly implemented.
However, consider enhancing the error message to include details about the conflicting validator or block height to aid in debugging.
- return types.ErrConsensusPubKeyAlreadyUsedForValidator
+ return sdkerrors.Wrapf(types.ErrConsensusPubKeyAlreadyUsedForValidator, "conflict with validator %s at height %d", valAddr.String(), height)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
// check if there's another key rotation for this same key in the same block | |
allRotations, err := k.GetBlockConsPubKeyRotationHistory(ctx) | |
if err != nil { | |
return err | |
} | |
for _, r := range allRotations { | |
if r.NewConsPubkey.Compare(newPubKey) == 0 { | |
return types.ErrConsensusPubKeyAlreadyUsedForValidator | |
} | |
} | |
// check if there's another key rotation for this same key in the same block | |
allRotations, err := k.GetBlockConsPubKeyRotationHistory(ctx) | |
if err != nil { | |
return err | |
} | |
for _, r := range allRotations { | |
if r.NewConsPubkey.Compare(newPubKey) == 0 { | |
return sdkerrors.Wrapf(types.ErrConsensusPubKeyAlreadyUsedForValidator, "conflict with validator %s at height %d", valAddr.String(), height) | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* main: fix(x/staking): stop validators from rotating to the same key on the same block (#20649) perf: add cache to address codec (#20122) build(deps): Bump google.golang.org/protobuf from 1.34.1 to 1.34.2 (#20632) fix: remove recipient amount from map (#20625) fix(proto): remove conditional preventing proper generated file placement (#20650) (serverv2/cometbft) Read config from commands & handle `FlagNode` (#20621) fix(x/consensus): fix .proto file placement (#20646) fix(store): avoid nil error on not exhausted payload stream (#20644) fix (x/accounts): Fix genesis condition check (#20645) feat(accounts): add genesis account initialization (#20642) fix(x/gov): limit execution in gov (#20348)
Description
This is an edge case, but it would allow 2 or more validators to try to rotate to the same key in the same block, which could cause issues down the line.
Now we check for the rotations in the same block, so only the first to rotate will be able to execute its message.
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.
I have...
Summary by CodeRabbit
Bug Fixes
Tests