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

feat(sequencer, rollapp): liveness slashing and jailing #1009

Merged
merged 142 commits into from
Aug 8, 2024

Conversation

danwt
Copy link
Contributor

@danwt danwt commented Jul 25, 2024

Description


Closes #927

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.

PR review checkboxes:

I have...

  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Targeted PR against the correct branch
  • included the correct type prefix in the PR title
  • Linked to the GitHub issue with discussion and accepted design
  • Targets only one GitHub issue
  • Wrote unit and integration tests
  • Wrote relevant migration scripts if necessary
  • All CI checks have passed
  • Added relevant godoc comments
  • Updated the scripts for local run, e.g genesis_config_commands.sh if the PR changes parameters
  • Add an issue in the e2e-tests repo if necessary

SDK Checklist

  • Import/Export Genesis
  • Registered Invariants
  • Registered Events
  • Updated openapi.yaml
  • No usage of go map
  • No usage of time.Now()
  • Used fixed point arithmetic and not float arithmetic
  • Avoid panicking in Begin/End block as much as possible
  • No unexpected math Overflow
  • Used sendCoin and not SendCoins
  • Out-of-block compute is bounded
  • No serialized ID at the end of store keys
  • UInt to byte conversion should use BigEndian

Full security checklist here

----;

For Reviewer:

  • Confirmed the correct type prefix in the PR title
  • Reviewers assigned
  • Confirmed all author checklist items have been addressed

---;

After reviewer approval:

  • In case the PR targets the main branch, PR should not be squash merge in order to keep meaningful git history.
  • In case the PR targets a release branch, PR must be rebased.

Summary by CodeRabbit

  • New Features

    • Enhanced liveness management with the introduction of tracking liveness events and associated penalties.
    • New parameters for configurability regarding liveness slashing and jailing conditions.
    • Added functionality for efficient management of liveness-related events in rollapps.
    • New interface and methods for handling sequencer penalties effectively.
  • Bug Fixes

    • Improved clarity in handling slashing and jailing of sequencers to avoid fraud.
  • Tests

    • Comprehensive test suite for liveness functionality, ensuring robust handling of state changes and penalties.
    • Updates to tests reflecting new methods and parameters for better coverage of functionality.
  • Chores

    • Refactoring of parameter management for improved readability and maintainability throughout the codebase.

@danwt danwt mentioned this pull request Jul 25, 2024
6 tasks
@danwt danwt requested a review from mtsitrin August 7, 2024 13:59
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ecface5 and 8f4a4ca.

Files ignored due to path filters (2)
  • go.sum is excluded by !**/*.sum
  • x/rollapp/types/rollapp.pb.go is excluded by !**/*.pb.go
Files selected for processing (9)
  • go.mod (5 hunks)
  • proto/dymensionxyz/dymension/rollapp/rollapp.proto (1 hunks)
  • x/rollapp/keeper/invariants.go (3 hunks)
  • x/rollapp/keeper/liveness_test.go (1 hunks)
  • x/rollapp/types/genesis_test.go (6 hunks)
  • x/rollapp/types/params.go (4 hunks)
  • x/rollapp/types/rollapp.go (1 hunks)
  • x/sequencer/keeper/msg_server_create_sequencer_test.go (1 hunks)
  • x/sequencer/types/params.go (7 hunks)
Files skipped from review due to trivial changes (1)
  • x/sequencer/keeper/msg_server_create_sequencer_test.go
Files skipped from review as they are similar to previous changes (6)
  • go.mod
  • proto/dymensionxyz/dymension/rollapp/rollapp.proto
  • x/rollapp/keeper/liveness_test.go
  • x/rollapp/types/params.go
  • x/rollapp/types/rollapp.go
  • x/sequencer/types/params.go
Additional comments not posted (9)
x/rollapp/types/genesis_test.go (6)

26-26: LGTM! Improved parameter initialization.

The use of DefaultParams() and WithRegFee method enhances clarity and maintainability by encapsulating the parameter initialization logic.


71-71: LGTM! Improved parameter initialization.

The use of DefaultParams() and WithRegFee method enhances clarity and maintainability by encapsulating the parameter initialization logic.


82-87: LGTM! Improved parameter initialization.

The use of DefaultParams() and WithDisputePeriodInBlocks and WithRegFee methods enhances clarity and maintainability by encapsulating the parameter initialization logic.


93-98: LGTM! Improved parameter initialization.

The use of DefaultParams() and WithLivenessSlashBlocks method enhances clarity and maintainability by encapsulating the parameter initialization logic.


104-109: LGTM! Improved parameter initialization.

The use of DefaultParams() and WithLivenessSlashInterval method enhances clarity and maintainability by encapsulating the parameter initialization logic.


Line range hint 115-120: LGTM! Improved parameter initialization.

The use of DefaultParams() and WithLivenessJailBlocks method enhances clarity and maintainability by encapsulating the parameter initialization logic.

x/rollapp/keeper/invariants.go (3)

18-18: LGTM! Registered new invariant.

The RegisterInvariants function is updated to register the LivenessEventInvariant, ensuring it is included in the invariant checks.


44-47: LGTM! Integrated new invariant.

The AllInvariants function is updated to include the LivenessEventInvariant check, ensuring it is part of the overall invariant validation process.


265-312: LGTM! Added new invariant function.

The LivenessEventInvariant function validates the integrity of liveness events associated with rollapps, ensuring accurate tracking and robustness.

zale144
zale144 previously approved these changes Aug 7, 2024
Copy link
Contributor

@zale144 zale144 left a comment

Choose a reason for hiding this comment

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

nice work!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8f4a4ca and 518e3e2.

Files ignored due to path filters (2)
  • go.sum is excluded by !**/*.sum
  • x/rollapp/types/rollapp.pb.go is excluded by !**/*.pb.go
Files selected for processing (7)
  • go.mod (5 hunks)
  • proto/dymensionxyz/dymension/rollapp/rollapp.proto (1 hunks)
  • x/rollapp/keeper/invariants.go (3 hunks)
  • x/rollapp/keeper/liveness_test.go (1 hunks)
  • x/rollapp/keeper/rollapp_suite_test.go (2 hunks)
  • x/rollapp/types/rollapp.go (1 hunks)
  • x/sequencer/keeper/msg_server_create_sequencer_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • go.mod
  • proto/dymensionxyz/dymension/rollapp/rollapp.proto
  • x/rollapp/keeper/liveness_test.go
  • x/rollapp/types/rollapp.go
  • x/sequencer/keeper/msg_server_create_sequencer_test.go
Additional comments not posted (6)
x/rollapp/keeper/rollapp_suite_test.go (3)

47-47: LGTM! Improved parameter management.

The change to retrieve default parameters and modify specific fields enhances clarity and maintainability.


63-65: LGTM! Useful helper method.

The keeper method is a valuable addition that provides cleaner access to the RollappKeeper instance.


67-70: LGTM! Enhances block simulation.

The nextBlock method improves the test suite's ability to simulate block progression, which is crucial for scenarios dependent on block height.

x/rollapp/keeper/invariants.go (3)

19-19: LGTM! New invariant registered.

The addition of LivenessEventInvariant to RegisterInvariants ensures that the new invariant will be checked during validation.


45-48: LGTM! Integrated new invariant.

The inclusion of LivenessEventInvariant in AllInvariants enhances the robustness of the validation process.


261-308: LGTM! Comprehensive liveness event check.

The LivenessEventInvariant function is a well-structured addition that ensures the integrity of liveness events associated with rollapps, improving the logical flow and control mechanisms within the invariants.

x/rollapp/keeper/keeper.go Outdated Show resolved Hide resolved
x/rollapp/types/params.go Outdated Show resolved Hide resolved
x/rollapp/keeper/liveness.go Show resolved Hide resolved
x/rollapp/keeper/liveness.go Show resolved Hide resolved
x/rollapp/types/liveness.go Show resolved Hide resolved
x/rollapp/types/liveness.go Outdated Show resolved Hide resolved
@danwt
Copy link
Contributor Author

danwt commented Aug 7, 2024

@mtsitrin not sure why I can't reply to this one

can u add doc in what cases the break wil be called?

There is a comment and docstring already?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 518e3e2 and a39538f.

Files selected for processing (2)
  • x/rollapp/types/liveness.go (1 hunks)
  • x/rollapp/types/params.go (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • x/rollapp/types/liveness.go
  • x/rollapp/types/params.go

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a39538f and 9e0f12b.

Files selected for processing (3)
  • x/rollapp/keeper/keeper.go (4 hunks)
  • x/rollapp/keeper/liveness.go (1 hunks)
  • x/rollapp/types/liveness.go (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • x/rollapp/keeper/keeper.go
  • x/rollapp/keeper/liveness.go
  • x/rollapp/types/liveness.go

@danwt danwt requested review from mtsitrin and zale144 August 8, 2024 08:42
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
x/rollapp/keeper/keeper.go (1)

35-35: Ensure NewKeeper Calls Include sequencerKeeper Parameter

The NewKeeper function in x/rollapp/keeper/keeper.go is not consistently called with the sequencerKeeper parameter. Specifically, in testutil/keeper/rollapp.go, the call to NewKeeper does not include this parameter. Please review and update the test setup to include sequencerKeeper where necessary.

  • File: testutil/keeper/rollapp.go
    • Line: k := keeper.NewKeeper(cdc, storeKey, paramsSubspace, nil, nil, nil)
Analysis chain

Update: NewKeeper function now includes sequencerKeeper.

The NewKeeper function has been updated to include sequencerKeeper, ensuring proper initialization of Keeper instances with this new dependency. Verify that all calls to NewKeeper are updated accordingly.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all calls to `NewKeeper` include the `sequencerKeeper` parameter.

# Test: Search for `NewKeeper` function calls. Expect: Inclusion of `sequencerKeeper` parameter.
rg --type go -A 5 $'NewKeeper'

Length of output: 14145


Script:

#!/bin/bash
# Description: Verify that all calls to `NewKeeper` in `x/rollapp/keeper/keeper.go` include the `sequencerKeeper` parameter.

# Test: Search for `NewKeeper` function calls in `x/rollapp/keeper/keeper.go`. Expect: Inclusion of `sequencerKeeper` parameter.
rg --type go -A 5 'NewKeeper' x/rollapp/keeper/keeper.go

Length of output: 228


Script:

#!/bin/bash
# Description: Verify that all calls to `NewKeeper` in the codebase include the `sequencerKeeper` parameter.

# Test: Search for `NewKeeper` function calls across the codebase. Expect: Inclusion of `sequencerKeeper` parameter.
rg --type go -A 5 'NewKeeper'

Length of output: 14145

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9e0f12b and 1ee791a.

Files ignored due to path filters (2)
  • x/rollapp/types/params.pb.go is excluded by !**/*.pb.go
  • x/rollapp/types/rollapp.pb.go is excluded by !**/*.pb.go
Files selected for processing (15)
  • app/keepers/keepers.go (2 hunks)
  • go.mod (3 hunks)
  • proto/dymensionxyz/dymension/rollapp/params.proto (1 hunks)
  • proto/dymensionxyz/dymension/rollapp/rollapp.proto (1 hunks)
  • testutil/keeper/rollapp.go (1 hunks)
  • x/rollapp/keeper/keeper.go (4 hunks)
  • x/rollapp/keeper/liveness_test.go (1 hunks)
  • x/rollapp/keeper/params.go (2 hunks)
  • x/rollapp/keeper/rollapp_suite_test.go (2 hunks)
  • x/rollapp/types/expected_keepers.go (1 hunks)
  • x/rollapp/types/genesis_test.go (6 hunks)
  • x/rollapp/types/params.go (3 hunks)
  • x/rollapp/types/rollapp.go (1 hunks)
  • x/sequencer/keeper/hook_listener.go (1 hunks)
  • x/sequencer/keeper/msg_server_create_sequencer_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • x/sequencer/keeper/msg_server_create_sequencer_test.go
Files skipped from review as they are similar to previous changes (12)
  • app/keepers/keepers.go
  • go.mod
  • proto/dymensionxyz/dymension/rollapp/params.proto
  • proto/dymensionxyz/dymension/rollapp/rollapp.proto
  • testutil/keeper/rollapp.go
  • x/rollapp/keeper/liveness_test.go
  • x/rollapp/keeper/params.go
  • x/rollapp/keeper/rollapp_suite_test.go
  • x/rollapp/types/expected_keepers.go
  • x/rollapp/types/genesis_test.go
  • x/rollapp/types/params.go
  • x/rollapp/types/rollapp.go
Additional comments not posted (3)
x/sequencer/keeper/hook_listener.go (1)

48-49: Enhancement in fraud handling: Verify SlashAndJailFraud implementation.

The replacement of Slashing with SlashAndJailFraud enhances the fraud handling by adding jailing to the slashing process. Ensure that the new method is correctly implemented and covers all necessary fraud scenarios.

Verification successful

Fraud Handling Enhancement Verified: SlashAndJailFraud Implementation

The SlashAndJailFraud function is correctly implemented. It handles fraud scenarios by checking if the sequencer is known and not unbonded, slashing all tokens, and jailing the sequencer. The function also handles errors appropriately.

  • Located in x/sequencer/keeper/slashing.go, lines 13-38.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `SlashAndJailFraud` to ensure it handles all fraud scenarios.

# Test: Search for the `SlashAndJailFraud` function definition. Expect: Proper handling of fraud scenarios.
ast-grep --lang go --pattern $'func (k Keeper) SlashAndJailFraud($_, $_) error {
  $$$
}'

Length of output: 1525

x/rollapp/keeper/keeper.go (2)

63-65: New method: SetSequencerKeeper added for flexibility.

The SetSequencerKeeper method provides flexibility for testing and runtime adjustments, enhancing the modularity of the Keeper. Ensure that this method is utilized where necessary.


24-24: Enhancement: Added sequencerKeeper to Keeper struct.

The addition of the sequencerKeeper field enhances the Keeper's capabilities to manage sequencing operations. Ensure its usage is consistent and correctly integrated within the codebase.

Verification successful

Integration of sequencerKeeper is consistent and correct.

The sequencerKeeper field is properly integrated within the Keeper struct. It is initialized in the NewKeeper function, used in liveness.go for managing sequencing operations, and has a setter method. No inconsistencies were found in its usage.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `sequencerKeeper` field to ensure consistent integration.

# Test: Search for the usage of `sequencerKeeper`. Expect: Consistent and correct integration.
rg --type go -A 5 $'sequencerKeeper'

Length of output: 1968

Copy link
Contributor

@zale144 zale144 left a comment

Choose a reason for hiding this comment

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

nice work!

@danwt danwt merged commit 04bd9df into main Aug 8, 2024
8 of 114 checks passed
@danwt danwt deleted the danwt/927-lazy-liveness-slashing branch August 8, 2024 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sequencer liveness - fails to submit batch to SL within pre-determined time - Impl
3 participants