ExocoreNetwork / exocore

5 stars 9 forks source link

[feat] add the new slash implementation and some missed RPC and CLI #61

Closed TimmyExogenous closed 2 weeks ago

TimmyExogenous commented 1 month ago

Description

This PR implements the new slash design except for the voting power snapshot according to the above documentation: slash design

The historical voting power for dogfood is provided by cometbft. Additionally, this PR adds the missed RPC and CLI to query the undelegations and USD values.

todo

Summary by CodeRabbit

coderabbitai[bot] commented 3 weeks ago

Walkthrough

The changes involve significant updates across multiple files in the Exocore project, addressing both enhancements and refactoring. Specifically, they introduce new message and RPC types for querying operator and AVS financial information, update methods for handling undelegations, and enhance slashing functionality. Additionally, the changes include cleanups and reordering of fields in protos, and various code refactors to improve functionality and maintainability.

Changes

Files Change Summary
proto/.../delegation/v1/query.proto Added new messages and RPCs for querying undelegations by staker ID, asset ID, and block height.
proto/.../operator/v1/query.proto Introduced new messages and updated RPCs for querying operator and AVS USD value, and handling slash information.
proto/.../operator/v1/tx.proto New message types for slashing events and execution information.
x/assets/keeper/operator_asset.go Added isUpdate parameter to IteratorAssetsForOperator function.
x/avs/keeper/avs_test.go Cleanups and comment adjustments in test functions.
x/delegation/client/cli/query.go Added functions for querying undelegations in CLI.
x/delegation/keeper/grpc_query.go Added new query functions for undelegations by various criteria.
x/operator/client/cli/query.go Added functions for querying operator and AVS info in CLI.
x/operator/keeper/abci.go Refactored USD value calculation method for operators.
x/operator/keeper/grpc_query.go Introduced functions for querying operator and AVS USD values and slash information.
x/operator/keeper/keeper.go Replaced and added new slashing-related functions and updated imports.
x/operator/keeper/operator_slash_state.go Refactored function for updating operator slash info and added a new function for retrieving all slash info.
x/operator/keeper/opt.go Updated comment about operator rewards.
x/operator/keeper/opt_test.go Added error logging and refactored TestOptOut function.
x/operator/keeper/slash.go Refactored and added functions for various slashing operations, including handling dogfood module.
x/operator/keeper/slash_test.go New test file introduced to test slashing with infraction reasons.
x/assets/types/keys.go Added function to generate joined store key with a trailing slash.

Sequence Diagram(s)

sequenceDiagram
    participant CLI
    participant Keeper
    participant AssetsModule
    participant ABCIModule
    participant GrpcServer

    CLI ->> GrpcServer: QueryOperatorUSDValue
    GrpcServer ->> Keeper: QueryOperatorUSDValue
    Keeper ->> AssetsModule: FetchAssetPrices
    AssetsModule -->> Keeper: AssetPrices
    Keeper ->> GrpcServer: OperatorUSDValueResponse
    GrpcServer -->> CLI: USD Value

    CLI ->> GrpcServer: QueryAVSUSDValue
    GrpcServer ->> Keeper: QueryAVSUSDValue
    Keeper ->> AssetsModule: FetchAssetPrices for AVS
    AssetsModule -->> Keeper: AssetPrices
    Keeper ->> GrpcServer: AVSUSDValueResponse
    GrpcServer -->> CLI: AVS USD Value

    CLI ->> GrpcServer: QueryOperatorSlashInfo
    GrpcServer ->> Keeper: QueryOperatorSlashInfo
    Keeper ->> ABCIModule: GetSlashInfo
    ABCIModule -->> Keeper: SlashInfo
    Keeper ->> GrpcServer: SlashInfoResponse
    GrpcServer -->> CLI: Slash Info

In fields and code where rabbits hop, New queries and slashes make the data pop. 🐇 Values of dollars, now clear in sight, Operators, AVS, all set right. Let's cheer for changes, oh so grand, Our code improved, across the land! 🎉


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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
cloud8little commented 2 weeks ago

@TimmyExogenous could you resolve the conflicts?

cloud8little commented 2 weeks ago

Test object: https://github.com/ExocoreNetwork/exocore/pull/61/commits/10e1ac976f2f4a9235f98902067f1228e2de3506 Undelegate part of the amount of delegation for the slashed operator seems incorrect.

Steps:

  1. Start a single operator consensus, with slash_fraction_downtime as default value 0.010000000000000000
  2. Register a new operator and staker delegate 100 tokens with decimal as 0 ( 0xdac17f958d2ee523a2206206994597c13d831ec7_0x65).
  3. Turn off the new operator (the operator addr is exo10zkthkjkx7fwknhq90srqrw9mu2j58cz635gxr)and wait for slashing to take effect.
  4. Check the operator assets, the operator assets is slashed.
    0xdac17f958d2ee523a2206206994597c13d831ec7_0x65:
    operator_amount: "0"
    operator_share: "0.000000000000000000"
    operator_unbonding_amount: "0"
    total_amount: "99"
    total_share: "100.000000000000000000"
    wait_unbonding_amount: "0"
  5. Undelegate 90 tokens from the slashed operator. Check the operator assets and staker assets.

Operator assets

  0xdac17f958d2ee523a2206206994597c13d831ec7_0x65:
    operator_amount: "0"
    operator_share: "0.000000000000000000"
    operator_unbonding_amount: "0"
    total_amount: "10"
    total_share: "9.090909090909090910"
    wait_unbonding_amount: "89"

Staker assets:

exocored query assets QueStakerAssetInfos 0xc6E1c84c2Fdc8EF1747512Cda73AaC7d338906ac_0x65
asset_infos:
  0xdac17f958d2ee523a2206206994597c13d831ec7_0x65:
    total_deposit_amount: "100"
    wait_unbonding_amount: "0"
    withdrawable_amount: "89"
cloud8little commented 2 weeks ago

Test object: 10e1ac9 Undelegate part of the amount of delegation for the slashed operator seems incorrect.

Steps:

  1. Start a single operator consensus, with slash_fraction_downtime as default value 0.010000000000000000
  2. Register a new operator and staker delegate 100 tokens with decimal as 0 ( 0xdac17f958d2ee523a2206206994597c13d831ec7_0x65).
  3. Turn off the new operator (the operator addr is exo10zkthkjkx7fwknhq90srqrw9mu2j58cz635gxr)and wait for slashing to take effect.
  4. Check the operator assets, the operator assets is slashed.
  0xdac17f958d2ee523a2206206994597c13d831ec7_0x65:
    operator_amount: "0"
    operator_share: "0.000000000000000000"
    operator_unbonding_amount: "0"
    total_amount: "99"
    total_share: "100.000000000000000000"
    wait_unbonding_amount: "0"
  1. Undelegate 90 tokens from the slashed operator. Check the operator assets and staker assets.

Operator assets

  0xdac17f958d2ee523a2206206994597c13d831ec7_0x65:
    operator_amount: "0"
    operator_share: "0.000000000000000000"
    operator_unbonding_amount: "0"
    total_amount: "10"
    total_share: "9.090909090909090910"
    wait_unbonding_amount: "89"

Staker assets:

exocored query assets QueStakerAssetInfos 0xc6E1c84c2Fdc8EF1747512Cda73AaC7d338906ac_0x65
asset_infos:
  0xdac17f958d2ee523a2206206994597c13d831ec7_0x65:
    total_deposit_amount: "100"
    wait_unbonding_amount: "0"
    withdrawable_amount: "89"

Even though the wait_unbonding_amount not exactly same with the undelegation amount input, it ends up with the correct amount 99 after several times undelegation. so it is issue here.

cloud8little commented 2 weeks ago

All test scenarioes passed.

cloud8little commented 2 weeks ago

Test QueryUndelegations and QueryUndelegationsByHeight function passed.

exocored query delegation QueryUndelegations 0xa53f68563D22EB0dAFAA871b6C08a6852f91d627_0x65 0xdAC17F958D2ee523a2206206994597C13D831ec7_0x65
undelegations:
- actual_completed_amount: "10"
  amount: "10"
  asset_id: 0xdac17f958d2ee523a2206206994597c13d831ec7_0x65
  block_number: "1827"
  complete_block_number: "1837"
  is_pending: true
  lz_tx_nonce: "0"
  operator_addr: exo1u8yx7e02wr2yvs5zk3zhvehhekh4vzxdr6sv2x
  staker_id: 0xa53f68563d22eb0dafaa871b6c08a6852f91d627_0x65
  tx_hash: 0x0a54e26e182d10eddf792d9cb9c05770ea8f77d6a8fce2388bb14a9727981b6e
exocored query delegation QueryUndelegationsByHeight 1837
undelegations:
- actual_completed_amount: "10"
  amount: "10"
  asset_id: 0xdac17f958d2ee523a2206206994597c13d831ec7_0x65
  block_number: "1827"
  complete_block_number: "1837"
  is_pending: true
  lz_tx_nonce: "0"
  operator_addr: exo1u8yx7e02wr2yvs5zk3zhvehhekh4vzxdr6sv2x
  staker_id: 0xa53f68563d22eb0dafaa871b6c08a6852f91d627_0x65
  tx_hash: 0x0a54e26e182d10eddf792d9cb9c05770ea8f77d6a8fce2388bb14a9727981b6e
mikebraver commented 2 weeks ago

Please resolve all comments from @MaxMustermann2 and me and good to merge

MaxMustermann2 commented 2 weeks ago

https://github.com/ExocoreNetwork/exocore/blob/693c2e5781800769676af7e282f87535057002b4/x/operator/keeper/usd_value.go#L176 Please also remove this line

cloud8little commented 2 weeks ago

Testing querying capabilities for operator and AVS USD values, please hold on the merge.

cloud8little commented 2 weeks ago

Test passed with querying USD value, commit: https://github.com/ExocoreNetwork/exocore/pull/61/commits/be3b8e5322a63dae4a2fdbb20d21b6e4be439f6c

before slash:

exocored q operator QueryOperatorUSDValue exo1u8yx7e02wr2yvs5zk3zhvehhekh4vzxdr6sv2x exocoretestnet_233-2
amount: "1000.000000000000000000"

after slash:

exocored q operator QueryOperatorUSDValue exo1u8yx7e02wr2yvs5zk3zhvehhekh4vzxdr6sv2x exocoretestnet_233-2
amount: "990.000000000000000000"
exocored q operator QueryOperatorSlashInfo exo1u8yx7e02wr2yvs5zk3zhvehhekh4vzxdr6sv2x exocoretestnet_233-2
all_slash_info:
- info:
    event_height: "702"
    execution_info:
      slash_assets_pool:
      - amount: "10"
        asset_id: 0xdac17f958d2ee523a2206206994597c13d831ec7_0x65
      slash_proportion: "0.010000000000000000"
      slash_undelegations: []
      slash_value: "10.000000000000000000"
    is_vetoed: false
    slash_contract: ""
    slash_proportion: "0.010000000000000000"
    slash_type: 2
    submitted_height: "704"
  slash_id: 0x2/0x2be
pagination:
  next_key: null
  total: "1"