Skip to content
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!: Avoid immediately jailing validators that are no longer opted-out #1549

Merged
merged 14 commits into from
Jan 9, 2024

Conversation

mpoke
Copy link
Contributor

@mpoke mpoke commented Jan 5, 2024

Description

Closes: #1517

This PR implements the solution from this comment. Mainly, when a validator can no longer opt out, the StartHeight fields in its SigningInfo struct (in the slashing module) is set to the current height. As a result, the validator cannot be jailed for downtime for at least the sliding window for downtime slashing (SignedBlocksWindow).


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...

  • Included the correct type prefix in the PR title
  • Added ! to the type prefix if the change is state-machine breaking
  • Confirmed this PR does not introduce changes requiring state migrations, OR migration code has been added to consumer and/or provider modules
  • Targeted the correct branch (see PR Targeting)
  • Provided a link to the relevant issue or specification
  • Followed the guidelines for building SDK modules
  • Included the necessary unit and integration tests
  • Added a changelog entry to CHANGELOG.md
  • Included comments for documenting Go code
  • Updated the relevant documentation or specification
  • Reviewed "Files changed" and left comments if necessary
  • Confirmed all CI checks have passed
  • If this PR is library API breaking, bump the go.mod version string of the repo, and follow through on a new major release

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.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! the type prefix if the change is state-machine breaking
  • confirmed this PR does not introduce changes requiring state migrations, OR confirmed migration code has been added to consumer and/or provider modules
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage

@github-actions github-actions bot added C:Testing Assigned automatically by the PR labeler C:x/consumer Assigned automatically by the PR labeler C:x/types Assigned automatically by the PR labeler labels Jan 5, 2024
// Update smallest validator power that cannot opt out.
am.keeper.UpdateSmallestNonOptOutPower(ctx)
// Execute BeginBlock logic for the Soft Opt-Out sub-protocol
am.keeper.BeginBlockSoftOptOut(ctx)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call
@mpoke mpoke marked this pull request as ready for review January 5, 2024 16:11
@mpoke mpoke requested a review from a team as a code owner January 5, 2024 16:11
tests/integration/common.go Outdated Show resolved Hide resolved
mpoke and others added 2 commits January 5, 2024 18:18
Co-authored-by: Simon Noetzlin <simon.ntz@gmail.com>
Co-authored-by: Simon Noetzlin <simon.ntz@gmail.com>
Copy link
Contributor

@p-offtermatt p-offtermatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious about this: why reset the start height instead of the missed blocks counter?

afaict, the cleanest solution to me seems to be to, for every opt-out validator, set the missed blocks counter to zero in each block, before it is entered on chain.

This has a few advantages:

  • No need for an extra field on validators (though it's still state machine breaking)
  • Works out-of-the-box with existing downtime checkers (they will just not see the missed blocks)

I might be missing something though. I think the current solution is also fine, maybe not worth changing this for.

@mpoke
Copy link
Contributor Author

mpoke commented Jan 8, 2024

Curious about this: why reset the start height instead of the missed blocks counter?

@p-offtermatt I didn't want to mess with the downtime logic too much. If you set the missed blocks counter to zero, you risk having the counter negative and potentially never trigger a downtime event. See https://github.com/cosmos/cosmos-sdk/blob/v0.47.7/x/slashing/keeper/infractions.go#L41-L52.

afaict, the cleanest solution to me seems to be to, for every opt-out validator, set the missed blocks counter to zero in each block, before it is entered on chain.

That would be a lot of store writes and I don't see the advantage of doing it like this.

This has a few advantages:

  • No need for an extra field on validators (though it's still state machine breaking)

Why is the extra field an issue?

  • Works out-of-the-box with existing downtime checkers (they will just not see the missed blocks)

See my comment above. I think reseting the missed blocks counter would mess with the downtime logic.

@p-offtermatt
Copy link
Contributor

Makes sense, thanks. I didn't take a close look at the missed-blocks logic in the slashing module (which is more intricate than I thought), and indeed I think your solution seems good under the constraints.

Co-authored-by: bernd-m <43466467+bermuell@users.noreply.github.com>
tests/integration/soft_opt_out.go Outdated Show resolved Hide resolved
tests/integration/soft_opt_out.go Outdated Show resolved Hide resolved
x/ccv/consumer/keeper/soft_opt_out.go Outdated Show resolved Hide resolved
mpoke and others added 3 commits January 9, 2024 13:45
Co-authored-by: bernd-m <43466467+bermuell@users.noreply.github.com>
Co-authored-by: bernd-m <43466467+bermuell@users.noreply.github.com>
Copy link
Contributor

@bermuell bermuell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls accept suggested changes on previous comments, thx

@sainoe sainoe self-requested a review January 9, 2024 13:40
@mpoke mpoke added this pull request to the merge queue Jan 9, 2024
Merged via the queue into main with commit b636a31 Jan 9, 2024
17 checks passed
@mpoke mpoke deleted the marius/1517-soft-opt-out branch January 9, 2024 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:Testing Assigned automatically by the PR labeler C:x/consumer Assigned automatically by the PR labeler C:x/types Assigned automatically by the PR labeler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Soft opt out implementation may lead to incorrect jailing
4 participants