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

refactor(x/staking): migrate to use env #19414

Merged
merged 22 commits into from
Feb 14, 2024
Merged

refactor(x/staking): migrate to use env #19414

merged 22 commits into from
Feb 14, 2024

Conversation

tac0turtle
Copy link
Member

@tac0turtle tac0turtle commented Feb 12, 2024

Description

Migrate staking module to use env variable


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
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

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 all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features
    • Improved testing coverage by adding a new test function to assess the unbonding of a validator.
  • Refactor
    • Updated context handling in multiple functions to utilize header information effectively.
    • Enhanced modularity by adjusting the initialization process to use a more flexible environment variable.
  • Documentation
    • Updated the CHANGELOG.md to reflect the new initialization approach for NewStakingKeeper.

Copy link
Contributor

coderabbitai bot commented Feb 12, 2024

Warning

Rate Limit Exceeded

@tac0turtle has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 52 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between dd203e9 and 76a9e83.

Walkthrough

The changes focus on updating various components to leverage the new ctx.HeaderInfo() for height information, enhancing modularity, and improving testing practices. These modifications aim to streamline context handling, improve test accuracy, and enhance the flexibility and configuration of the staking module.

Changes

Files Change Summary
tests/integration/slashing/abci_test.go - Added import for coreheader.
- Updated TestBeginBlocker to use ctx.WithHeaderInfo.
tests/integration/slashing/keeper/keeper_test.go - Updated stakingKeeper initialization.
- Adjusted context updates in test functions.
x/staking/keeper/validator_test.go - Added TestUnbondingValidator.
- Updated endHeight calculation and context creation.
x/staking/CHANGELOG.md - NewStakingKeeper now accepts an environment variable.
x/staking/keeper/genesis.go - Modified block height setting in InitGenesis with a TODO comment.

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?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

x/staking/keeper/msg_server.go Fixed Show fixed Hide fixed
x/staking/keeper/msg_server.go Fixed Show fixed Hide fixed
x/staking/keeper/msg_server.go Fixed Show fixed Hide fixed
x/staking/keeper/msg_server.go Fixed Show fixed Hide fixed
x/staking/keeper/msg_server.go Fixed Show fixed Hide fixed
@tac0turtle tac0turtle marked this pull request as ready for review February 13, 2024 22:16
@tac0turtle tac0turtle requested a review from a team as a code owner February 13, 2024 22:16
@@ -271,7 +274,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
assert.NilError(t, f.stakingKeeper.SetUnbondingDelegation(f.sdkCtx, ubd))

// slash validator for the first time
f.sdkCtx = f.sdkCtx.WithBlockHeight(12)
f.sdkCtx = f.sdkCtx.WithHeaderInfo(header.Info{Height: 12})
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding assertions after each slashing operation to verify the expected state changes, not just at the end of the test. This will help ensure each step of the test behaves as expected and makes the test more robust.


Repeated slashing operations in the test are intended to simulate different scenarios. However, ensure there's clear documentation or comments explaining the rationale behind each operation and what specific condition or behavior it's testing. This will improve the maintainability and readability of the test.


The final assertions in the test verify the expected outcomes of the slashing operations, including the validator's power and the balances of the bonded and not bonded pools. These assertions are crucial for ensuring the slashing logic is correctly implemented. However, consider adding more granular assertions throughout the test to verify intermediate states after each significant operation.


The test function TestSlashWithUnbondingDelegation effectively covers the scenario it's designed to test. However, consider adding tests for edge cases, such as slashing with a fraction of zero or more than one, and cases where the unbonding delegation or validator does not exist. Expanding test coverage in this way can help ensure the robustness of the slashing logic under various conditions.

@@ -28,7 +28,7 @@ func (k Keeper) InitGenesis(ctx context.Context, data *types.GenesisState) (res
// first TM block is at height 1, so state updates applied from
// genesis.json are in block 0.
sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx = sdkCtx.WithBlockHeight(1 - sdk.ValidatorUpdateDelay)
sdkCtx = sdkCtx.WithBlockHeight(1 - sdk.ValidatorUpdateDelay) // TODO: replace this
Copy link
Contributor

Choose a reason for hiding this comment

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

Address the TODO comment regarding the replacement of block height setup in the context to ensure it aligns with the module's initialization requirements and does not lead to future technical debt.

Would you like me to open a GitHub issue to track the resolution of this TODO?

sdk.NewAttribute(types.AttributeKeyCompletionTime, completionTime.Format(time.RFC3339)),
),
})
if err := k.environment.EventService.EventManager(ctx).EmitKV(
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this be only be an EmitKV or could it also potentially also be an Emit too?

Copy link
Member Author

Choose a reason for hiding this comment

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

it could be emit but since we dont have the types defined i went with EmitKV

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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 3ada1ab and c1790e2.
Files selected for processing (4)
  • runtime/module.go (1 hunks)
  • tests/integration/slashing/abci_test.go (5 hunks)
  • x/staking/CHANGELOG.md (1 hunks)
  • x/staking/keeper/genesis.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • runtime/module.go
  • x/staking/keeper/genesis.go
Additional comments: 5
tests/integration/slashing/abci_test.go (4)
  • 10-10: The import of coreheader is correctly added to support the new ctx.WithHeaderInfo method usage.
  • 87-87: The update from ctx.BlockHeight() to ctx.HeaderInfo().Height aligns with the migration to use coreheader.Info. Ensure all instances where block height is needed are updated accordingly.
  • 98-98: Using ctx.WithHeaderInfo(coreheader.Info{Height: height}) for setting the block height is correct and improves the test's clarity by explicitly setting the header information.
  • 108-108: The combination of ctx.WithHeaderInfo and ctx.WithCometInfo in a single call is a good practice for setting multiple context properties simultaneously, ensuring the test context is correctly configured for each iteration.
x/staking/CHANGELOG.md (1)
  • 84-84: The changelog entry accurately reflects the significant change introduced by the PR, which is the modification of NewStakingKeeper to accept an environment variable. This entry is clear, follows the changelog format, and is placed correctly under "API Breaking Changes".

Copy link
Contributor

@likhita-809 likhita-809 left a comment

Choose a reason for hiding this comment

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

slash test is failing with height 0. Need to fix that.
Otherwise changes are looking good.

@julienrbrt julienrbrt changed the title chore(staking): migrate to use env refactor(x/staking): migrate to use env Feb 14, 2024
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.

Review Status

Actionable comments generated: 3

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between c1790e2 and dd203e9.
Files selected for processing (3)
  • tests/integration/slashing/abci_test.go (5 hunks)
  • tests/integration/slashing/keeper/keeper_test.go (11 hunks)
  • x/staking/keeper/validator_test.go (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • tests/integration/slashing/abci_test.go
  • tests/integration/slashing/keeper/keeper_test.go
Additional comments: 2
x/staking/keeper/validator_test.go (2)
  • 438-438: Using ctx.HeaderInfo().Height + 10 for endHeight calculation is a good practice as it relies on the current block height from the context, ensuring the test reflects more realistic scenarios.
  • 465-465: Creating a new context with updated header information using ctx.WithHeaderInfo(header.Info{Height: endHeight, Time: endTime}) is correctly implemented for testing unbonding at a specific block height and time.

x/staking/keeper/validator_test.go Show resolved Hide resolved
x/staking/keeper/validator_test.go Show resolved Hide resolved
@tac0turtle tac0turtle added this pull request to the merge queue Feb 14, 2024
Merged via the queue into main with commit 2dafb87 Feb 14, 2024
58 of 59 checks passed
@tac0turtle tac0turtle deleted the marko/staking_env branch February 14, 2024 23:12
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.

6 participants