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

[Application] Auto-undelegation of unstaked gateways #692

Merged
merged 9 commits into from
Jul 15, 2024

Conversation

red-0ne
Copy link
Contributor

@red-0ne red-0ne commented Jul 12, 2024

Summary

Support Application auto-undelegation when a Gateway unstakes.

  • Add a GatewayUnstaked event.
  • Use the GatewayUnstaked event to update the applicaiton's delegation state.

Most of the LOCs are pulsar and pb files

Issue

Applications need to update their delegation state when a gateway they delegated to has unstaked.

Type of change

Select one or more:

  • New feature, functionality or library
  • Bug fix
  • Code health or cleanup
  • Documentation
  • Other (specify)

Testing

Documentation changes (only if making doc changes)

  • make docusaurus_start; only needed if you make doc changes

Local Testing (only if making code changes)

  • Unit Tests: make go_develop_and_test
  • LocalNet E2E Tests: make test_e2e
  • See quickstart guide for instructions

PR Testing (only if making code changes)

  • DevNet E2E Tests: Add the devnet-test-e2e label to the PR.
    • THIS IS VERY EXPENSIVE, so only do it after all the reviews are complete.
    • Optionally run make trigger_ci if you want to re-trigger tests without any code changes
    • If tests fail, try re-running failed tests only using the GitHub UI as shown here

Sanity Checklist

  • I have tested my changes using the available tooling
  • I have commented my code
  • I have performed a self-review of my own code; both comments & source code
  • I create and reference any new tickets, if applicable
  • I have left TODOs throughout the codebase, if applicable

Summary by CodeRabbit

  • New Features

    • Introduced automated processing for unstaked gateway events, including address handling, protocol buffer support, and message management.
  • Bug Fixes

    • Corrected variable naming for clarity in the undelegation process.
  • Tests

    • Added tests to ensure accurate undelegation from unstaked gateways and verify state changes post-undelegation.
  • Chores

    • Emitted GatewayUnstaked events for better event handling and logging.

@red-0ne red-0ne added application Changes related to the Application actor gateway Changes related to the Gateway actor labels Jul 12, 2024
@red-0ne red-0ne self-assigned this Jul 12, 2024
Copy link

coderabbitai bot commented Jul 12, 2024

Walkthrough

The updates introduce functionality for handling GatewayUnstaked events within the Pulsar gateway. Key changes include defining the GatewayUnstaked message in protocol buffers, handling unstaked events in the keeper package, renaming variables for consistency, and adding unit tests. Essentially, these changes streamline the process of managing gateway unstaking and related delegations within the blockchain ecosystem.

Changes

File Change Summary
api/poktroll/gateway/event.pulsar.go Added GatewayUnstaked struct and methods for handling GatewayUnstaked events, including reflection and proto message functions.
proto/poktroll/gateway/event.proto Introduced EventGatewayUnstaked message defining the structure for unstaking gateway events with an address field.
x/application/keeper/auto_undelegate.go Added EndBlockerAutoUndelegateFromUnstakedGateways and getUnstakeGatewayEvents functions to manage automatic undelegation from unstaked gateways.
x/application/keeper/msg_server_undelegate_... Renamed variable currentBlock to currentHeight in UndelegateFromGateway method for consistency.
x/application/keeper/msg_server_undelegate_... Added TestMsgServer_UndelegateFromGateway_UndelegateFromUnstakedGateway function to test undelegation from unstaked gateway and verify state changes.
x/gateway/keeper/msg_server_unstake_gateway.go Emitted a GatewayUnstaked event using event manager in the UnstakeGateway function before returning a successful response.

Sequence Diagrams

Unstaking a Gateway and Auto-Undelegation

sequenceDiagram
    participant User
    participant Gateway
    participant Keeper
    participant EventManager

    User ->> Gateway: Unstake Gateway
    Gateway ->> EventManager: Emit GatewayUnstaked Event
    Gateway ->> Keeper: Call EndBlockerAutoUndelegateFromUnstakedGateways
    Keeper ->> Keeper: getUnstakeGatewayEvents
    Keeper ->> EventManager: Emit Unstaking and Undelegation Events
    Keeper ->> User: Confirm Undelegation
Loading

Poem

In fields of code where gateways lie,
A change was made, we can't deny.
Unstaked they were with gentle hands,
Events now pulse through data lands.
Auto-undelegation in every block,
The system hums, no need to knock.
🎉 A seamless flow, a bunny's cheer,
For changes bright, we toast and peer. 🐇


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 testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 testing code 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 and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 6

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6a0deba and f086dd6.

Files ignored due to path filters (1)
  • x/gateway/types/event.pb.go is excluded by !**/*.pb.go
Files selected for processing (7)
  • api/poktroll/gateway/event.pulsar.go (1 hunks)
  • proto/poktroll/gateway/event.proto (1 hunks)
  • x/application/keeper/auto_undelegate.go (1 hunks)
  • x/application/keeper/msg_server_undelegate_from_gateway.go (1 hunks)
  • x/application/keeper/msg_server_undelegate_from_gateway_test.go (2 hunks)
  • x/application/module/abci.go (1 hunks)
  • x/gateway/keeper/msg_server_unstake_gateway.go (1 hunks)
Additional comments not posted (4)
x/application/keeper/msg_server_undelegate_from_gateway.go (2)

55-55: Variable Rename for Clarity

The variable currentBlock has been renamed to currentHeight for better clarity. This change does not affect the logic.


57-57: Variable Rename for Clarity

The variable currentBlock has been renamed to currentHeight for better clarity. This change does not affect the logic.

x/application/keeper/msg_server_undelegate_from_gateway_test.go (1)

463-497: Comprehensive Test for Unstaked Gateway Undelegation

The test function TestMsgServer_UndelegateFromGateway_UndelegateFromUnstakedGateway is comprehensive and covers various scenarios of setting up the application, delegating to a gateway, unstaking the gateway, and verifying the undelegation logic.

api/poktroll/gateway/event.pulsar.go (1)

1-25: Addition of GatewayUnstaked Struct and Methods

The GatewayUnstaked struct and its methods for protocol buffer operations are correctly implemented. These methods include resetting, string representation, proto message, descriptor, and getting the address.

x/application/module/abci.go Outdated Show resolved Hide resolved
proto/poktroll/gateway/event.proto Outdated Show resolved Hide resolved
x/gateway/keeper/msg_server_unstake_gateway.go Outdated Show resolved Hide resolved
x/application/keeper/auto_undelegate.go Show resolved Hide resolved
x/application/keeper/auto_undelegate.go Outdated Show resolved Hide resolved
x/application/keeper/auto_undelegate.go Show resolved Hide resolved
Copy link

@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 f086dd6 and 732bdec.

Files ignored due to path filters (1)
  • x/gateway/types/event.pb.go is excluded by !**/*.pb.go
Files selected for processing (3)
  • api/poktroll/gateway/event.pulsar.go (1 hunks)
  • proto/poktroll/gateway/event.proto (1 hunks)
  • x/application/module/abci.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • api/poktroll/gateway/event.pulsar.go
  • proto/poktroll/gateway/event.proto
Additional comments not posted (1)
x/application/module/abci.go (1)

11-13: Handle and log errors instead of returning nil.

Returning nil on error can mask issues and make debugging difficult. Log the error and return it instead.

-		return err
+		k.Logger().Error("Failed to auto-undelegate from unstaked gateways", "error", err)
+		return err

proto/poktroll/gateway/event.proto Outdated Show resolved Hide resolved
x/application/keeper/auto_undelegate.go Outdated Show resolved Hide resolved
Comment on lines +15 to +16
// TODO_BLOCKER: Gateway unstaking should be delayed until the current block's
// session end height to align with the application's pending undelegations.
Copy link
Contributor

Choose a reason for hiding this comment

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

👀

x/application/keeper/auto_undelegate.go Outdated Show resolved Hide resolved
x/application/keeper/auto_undelegate.go Outdated Show resolved Hide resolved
Copy link

@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 732bdec and d63f6d0.

Files ignored due to path filters (1)
  • x/gateway/types/event.pb.go is excluded by !**/*.pb.go
Files selected for processing (5)
  • api/poktroll/gateway/event.pulsar.go (1 hunks)
  • proto/poktroll/gateway/event.proto (1 hunks)
  • x/application/keeper/auto_undelegate.go (1 hunks)
  • x/application/keeper/msg_server_undelegate_from_gateway_test.go (2 hunks)
  • x/gateway/keeper/msg_server_unstake_gateway.go (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • api/poktroll/gateway/event.pulsar.go
  • proto/poktroll/gateway/event.proto
  • x/application/keeper/auto_undelegate.go
  • x/application/keeper/msg_server_undelegate_from_gateway_test.go
  • x/gateway/keeper/msg_server_unstake_gateway.go

Copy link

The CI will now also run the e2e tests on devnet, which increases the time it takes to complete all CI checks.

You may need to run make trigger_ci to submit an empty commit that'll trigger the tests.

GCP workloads (requires changing the namespace to 692)
Grafana network dashboard for devnet-issue-{issue-id}

@github-actions github-actions bot added devnet push-image CI related - pushes images to ghcr.io labels Jul 15, 2024
@red-0ne red-0ne merged commit a56d58d into main Jul 15, 2024
10 checks passed
bryanchriswhite added a commit that referenced this pull request Jul 16, 2024
…ation-overserviced

* pokt/main:
  [TODO] Blockers @okdas (#674)
  [TODO_BLOCKER] chore: Remove stale TODO_BLOCKERs (#694)
  [TODO] refactor: query expiring claims w/ index (#671)
  [TODOs] `grace_period_end_offset_blocks` validation & cleanup (#667)
  [Testing] add account balance coverage to account settlement (#670)
  [Application] Auto-undelegation of unstaked gateways (#692)
  [RelayMiner] Fix LeanClient mutiple suppliers support (#662)
bryanchriswhite added a commit that referenced this pull request Jul 16, 2024
…-root

* pokt/main:
  [TODO] Blockers @okdas (#674)
  [TODO_BLOCKER] chore: Remove stale TODO_BLOCKERs (#694)
  [TODO] refactor: query expiring claims w/ index (#671)
  [TODOs] `grace_period_end_offset_blocks` validation & cleanup (#667)
  [Testing] add account balance coverage to account settlement (#670)
  [Application] Auto-undelegation of unstaked gateways (#692)
  [RelayMiner] Fix LeanClient mutiple suppliers support (#662)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
application Changes related to the Application actor devnet devnet-test-e2e gateway Changes related to the Gateway actor push-image CI related - pushes images to ghcr.io
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants