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(genesis export): genesis exporting for assets, delegation and operator modules. #108

Merged

Conversation

TimmyExogenous
Copy link
Contributor

@TimmyExogenous TimmyExogenous commented Jun 18, 2024

Description

It provides the genesis exporting functions for the assets, delegation, and operator modules. It provides compatibility for starting the Exocore node from the bootStrap contract and general genesis file.

Please refer to this documentation to get more details:
understanding-of-the-Genesis-exporting

The main changes are the proto files related to the genesis state. All other changes are implemented around the redefined genesis state structure to enable the genesis import and export functionality.

  • Assets module: add operator_assets in the genesis state
  • Operator module: add OperatorConsKeyRecord,OptedState,AVSUSDValue,OperatorUSDValue,OperatorSlashState,PrevConsKey,OperatorKeyRemoval in the genesis state.
  • delegation module: remove delegations, and add delegation_states,stakers_by_operator,undelegations in the genesis state.

The purpose of these changes is to ensure the unbalanced states won't influence the exported state.

Todo

  • unit test
  • integration test

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced initialization options with improved parameters for operator management.
    • Introduced new message structures for managing operator details and delegation states, improving data organization.
    • Updated asset management functionality with refined handling of operator-specific assets.
    • Added new fields in genesis state for comprehensive representation of delegation and operator information.
    • Improved data retrieval methods by changing return types from maps to slices for better performance.
  • Bug Fixes

    • Corrected issues with struct field assignments in genesis state initialization to ensure accuracy.
  • Refactor

    • Renamed instances of ExocoreApp to exocoreApp for clarity and consistency in application creation and export functions.
    • Updated function signatures and return types in various modules to improve data handling and clarity.
  • Tests

    • Improved test coverage and assertion accuracy for genesis state validation and asset management functions.
  • Chores

    • Updated the git package version in the Dockerfile for potential bug fixes and improvements.

Copy link
Contributor

coderabbitai bot commented Jun 18, 2024

Walkthrough

The changes involve significant modifications across multiple files, focusing on the initialization and management of operator and delegation data. Key updates include the removal of certain parameters in function calls, the introduction of new data structures, and the transition from map fields to slice fields in various proto files. These alterations enhance the clarity and maintainability of the codebase, streamlining the overall functionality of the Exocore application.

Changes

Files/Paths Summary of Changes
app/app.go Removed bApp.CreateQueryContext from NewExocoreApp function, simplifying OperatorKeeper initialization.
app/ethtest_helper.go Updated genesisStateWithValSet to use dynamic depositAmount and replaced OperatorInfo with OperatorDetail.
app/test_helpers.go Modified GenesisStateWithValSet to enhance asset handling and updated operator information to use OperatorDetail.
cmd/exocored/root.go Renamed variable evmosApp to exocoreApp for clarity in app initialization.
cmd/exocored/testnet.go Updated getTestExocoreGenesis to reflect new operator and delegation data structures.
local_node.sh Changed JSON structure for staking and delegation data, updating initial values and formats for better tracking.
precompiles/assets/tx.go Changed extraction of LayerZeroChainID to iterate over infos, updating assignment of AssetBasicInfo.
proto/exocore/... Introduced new message types and modified existing ones across various proto files; improved nullability annotations.
x/assets/... Updated return types for asset information functions from maps to slices, enhancing functionality.
x/delegation/... Modified NewGenesis function to accept additional parameters for delegation management.
x/operator/... Enhanced operator management with new functions and modifications to existing logic for better data representation.

Possibly related PRs

  • feat(assets): remove total supply #181: This PR modifies the app/app.go file, which is also affected by the main PR's changes to the NewExocoreApp function. Although the changes are minor and focus on comment formatting, both PRs involve the same file and contribute to the overall structure of the application.

  • remove total supply in genesis #191: This PR removes the total_supply parameter from the genesis configuration, which aligns with the main PR's focus on changes in how the application manages query contexts related to the operator keeper. Both PRs reflect a broader shift in the management of asset supply within the Exocore framework.

Suggested labels

Type: Build

Poem

In the land of Exocore delight,
A new constant sees the light.
Clients and keepers dance anew,
With structs and fields in tidy queue.
Genesis state now neat and bright,
Hopping through code, forever in sight.
Here's to changes, small and grand,
From a rabbit's burrow, perfectly planned! 🐇🚀


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>, please review it.
    -- 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

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

x/operator/types/query.pb.go Fixed Show fixed Hide fixed
x/operator/types/query.pb.go Fixed Show fixed Hide fixed
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: 50

Outside diff range and nitpick comments (3)
x/assets/keeper/client_chain_and_asset_test.go (1)

[!TIP]
Codebase Verification

Ensure Comprehensive Tests for Asset Initialization and Retrieval

The current tests check for successful retrieval of assets and client chains but do not cover scenarios where no assets or client chains are found. Please add test cases to handle these edge cases.

  • Add tests for GetAllClientChainInfo when no client chains exist.
  • Add tests for GetAllStakingAssetsInfo when no staking assets exist.

These additions will ensure robustness in handling all possible scenarios.

Analysis chain

Line range hint 29-51: Validate Asset Initialization and Retrieval Logic

The tests for asset initialization and retrieval seem comprehensive. However, ensure that the GetAllClientChainInfo and GetAllStakingAssetsInfo methods are thoroughly tested to handle cases where the assets or client chains are not found in the system.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the comprehensive testing of asset initialization and retrieval.

# Test: Search for the function usage and test coverage.
rg --type go $'GetAllClientChainInfo|GetAllStakingAssetsInfo'

Length of output: 2039



Script:

#!/bin/bash
# Description: Verify the test cases for handling empty results or errors in asset initialization and retrieval.

# Search for test cases handling empty results or errors for GetAllClientChainInfo
rg --type go 'GetAllClientChainInfo' -A 10 | grep -E 'NoError|Error|Empty|Len|Contains|Equal'

# Search for test cases handling empty results or errors for GetAllStakingAssetsInfo
rg --type go 'GetAllStakingAssetsInfo' -A 10 | grep -E 'NoError|Error|Empty|Len|Contains|Equal'

Length of output: 1266

x/delegation/keeper/keeper.go (1)

Line range hint 15-40: Proper integration of isGeneralInit flag, but consider alternative approaches for passing flags.

The addition of the isGeneralInit flag is well-documented. However, passing such flags through the context or command line as noted might be limiting. Consider using a configuration file or environment variables for greater flexibility and separation of concerns.

x/operator/keeper/keeper.go (1)

[!TIP]
Codebase Verification

Ensure that the historicalCtx field is utilized in the keeper's methods.

The historicalCtx field is declared and initialized but not used in any keeper's methods. This could lead to potential runtime issues if it's intended to be used.

  • File: x/operator/keeper/keeper.go
  • Lines: 37-43
Analysis chain

Line range hint 40-51: Ensure that all necessary fields are initialized in the NewKeeper function.

The NewKeeper function initializes a new Keeper instance. It's important to ensure that all fields, especially the new isGeneralInit and historicalCtx, are correctly utilized in the keeper's methods to prevent runtime issues.


To ensure that the isGeneralInit and historicalCtx fields are correctly utilized in the keeper's methods, we need to delve deeper into the usage of historicalCtx as the rg output does not show its usage clearly. This will help us confirm if it's being used appropriately in the methods.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check usage of `isGeneralInit` and `historicalCtx` fields throughout the keeper's methods.
rg 'isGeneralInit|historicalCtx' --type go

Length of output: 1875



Script:

#!/bin/bash
# Check usage of `historicalCtx` field throughout the keeper's methods.
rg 'historicalCtx' --type go

Length of output: 228

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 86d84f2 and 9502f43.

Files ignored due to path filters (6)
  • x/assets/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/assets/types/query.pb.go is excluded by !**/*.pb.go
  • x/assets/types/tx.pb.go is excluded by !**/*.pb.go
  • x/delegation/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/operator/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/operator/types/tx.pb.go is excluded by !**/*.pb.go
Files selected for processing (52)
  • app/app.go (3 hunks)
  • app/ethtest_helper.go (2 hunks)
  • app/test_helpers.go (1 hunks)
  • cmd/exocored/root.go (4 hunks)
  • cmd/exocored/testnet.go (3 hunks)
  • precompiles/assets/tx.go (1 hunks)
  • proto/exocore/assets/v1/genesis.proto (3 hunks)
  • proto/exocore/assets/v1/query.proto (5 hunks)
  • proto/exocore/assets/v1/tx.proto (2 hunks)
  • proto/exocore/delegation/v1/genesis.proto (2 hunks)
  • proto/exocore/operator/v1/genesis.proto (1 hunks)
  • proto/exocore/operator/v1/tx.proto (1 hunks)
  • testutil/utils.go (4 hunks)
  • x/assets/keeper/client_chain.go (1 hunks)
  • x/assets/keeper/client_chain_and_asset_test.go (2 hunks)
  • x/assets/keeper/client_chain_asset.go (1 hunks)
  • x/assets/keeper/genesis.go (4 hunks)
  • x/assets/keeper/genesis_test.go (1 hunks)
  • x/assets/keeper/keeper.go (1 hunks)
  • x/assets/keeper/msg_server.go (1 hunks)
  • x/assets/keeper/operator_asset.go (1 hunks)
  • x/assets/keeper/staker_asset.go (2 hunks)
  • x/assets/keeper/staker_asset_test.go (1 hunks)
  • x/assets/types/errors.go (1 hunks)
  • x/assets/types/genesis.go (5 hunks)
  • x/assets/types/genesis_test.go (5 hunks)
  • x/assets/types/keys.go (2 hunks)
  • x/delegation/keeper/cross_chain_tx_process.go (2 hunks)
  • x/delegation/keeper/delegation_state.go (3 hunks)
  • x/delegation/keeper/genesis.go (2 hunks)
  • x/delegation/keeper/keeper.go (2 hunks)
  • x/delegation/keeper/un_delegation_state.go (1 hunks)
  • x/delegation/types/errors.go (1 hunks)
  • x/delegation/types/genesis.go (3 hunks)
  • x/delegation/types/keys.go (1 hunks)
  • x/operator/client/cli/tx.go (3 hunks)
  • x/operator/keeper/consensus_keys.go (2 hunks)
  • x/operator/keeper/genesis.go (1 hunks)
  • x/operator/keeper/keeper.go (3 hunks)
  • x/operator/keeper/operator.go (3 hunks)
  • x/operator/keeper/operator_info_test.go (3 hunks)
  • x/operator/keeper/operator_slash_state.go (1 hunks)
  • x/operator/keeper/slash.go (4 hunks)
  • x/operator/keeper/slash_test.go (1 hunks)
  • x/operator/keeper/usd_value.go (1 hunks)
  • x/operator/keeper/usd_value_test.go (1 hunks)
  • x/operator/types/expected_keepers.go (2 hunks)
  • x/operator/types/genesis.go (4 hunks)
  • x/operator/types/genesis_test.go (8 hunks)
  • x/operator/types/keys.go (4 hunks)
  • x/reward/keeper/claim_reward_test.go (1 hunks)
  • x/slash/keeper/execute_slash_test.go (1 hunks)
Files skipped from review due to trivial changes (5)
  • proto/exocore/operator/v1/tx.proto
  • x/assets/types/errors.go
  • x/assets/types/genesis_test.go
  • x/delegation/types/keys.go
  • x/operator/keeper/slash_test.go
Additional context used
GitHub Check: break-check
proto/exocore/assets/v1/query.proto

[failure] 24-24:
Previously present message "QueryAllClientChainInfoResponse.AllClientChainInfosEntry" was deleted from file.


[failure] 26-26:
Field "1" on message "QueryAllClientChainInfoResponse" changed type from "exocore.assets.v1.QueryAllClientChainInfoResponse.AllClientChainInfosEntry" to "exocore.assets.v1.ClientChainInfo".


[failure] 40-40:
Previously present message "QueryAllStakingAssetsInfoResponse.AllStakingAssetsInfoEntry" was deleted from file.


[failure] 42-42:
Field "1" on message "QueryAllStakingAssetsInfoResponse" changed type from "exocore.assets.v1.QueryAllStakingAssetsInfoResponse.AllStakingAssetsInfoEntry" to "exocore.assets.v1.StakingAssetInfo".


[failure] 52-52:
Previously present message "QueryAssetInfoResponse.AssetInfosEntry" was deleted from file.


[failure] 54-54:
Field "1" on message "QueryAssetInfoResponse" changed type from "exocore.assets.v1.QueryAssetInfoResponse.AssetInfosEntry" to "exocore.assets.v1.DepositByAsset".


[failure] 72-72:
Previously present message "QueryOperatorAssetInfosResponse.AssetInfosEntry" was deleted from file.


[failure] 74-74:
Field "1" on message "QueryOperatorAssetInfosResponse" changed type from "exocore.assets.v1.QueryOperatorAssetInfosResponse.AssetInfosEntry" to "exocore.assets.v1.AssetByID".

proto/exocore/operator/v1/genesis.proto

[failure] 15-15:
Field "1" on message "GenesisState" changed type from "exocore.operator.v1.OperatorInfo" to "exocore.operator.v1.OperatorDetail".

GitHub Check: Run golangci-lint
x/assets/types/genesis.go

[warning] 107-107:
unused-parameter: parameter 'i' seems to be unused, consider removing or renaming it as _ (revive)


[warning] 180-180:
unused-parameter: parameter 'i' seems to be unused, consider removing or renaming it as _ (revive)


[warning] 202-202:
unused-parameter: parameter 'i' seems to be unused, consider removing or renaming it as _ (revive)

Additional comments not posted (49)
x/reward/keeper/claim_reward_test.go (1)

46-46: Ensure Correct Arithmetic in Test Assertion

The line adds the StakingTotalAmount from assets[0] with a new sdkmath.NewInt(10), which is a part of the test setup. Ensure that this addition accurately reflects the expected state change in the system after the reward operation.

x/assets/keeper/msg_server.go (1)

58-58: Ensure Initial Staking Amount is Correct

The initialization of StakingTotalAmount to zero when registering a new asset is critical. Confirm that this aligns with the expected behavior, especially in scenarios where an asset might be expected to have an initial non-zero staking amount due to business rules or previous state.

Verification successful

Ensure Initial Staking Amount is Correct

The RegisterAsset function in x/assets/keeper/msg_server.go correctly initializes StakingTotalAmount to zero when a new asset is registered. This aligns with the expected behavior of starting with zero staking amount. There are no indications of business rules or previous states affecting this initialization.

  • x/assets/keeper/msg_server.go, lines 54-64: RegisterAsset function initializes StakingTotalAmount to zero.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the initial staking amount during asset registration.

# Test: Check for any business rules or previous states that might affect this initialization.
rg --type go $'RegisterAsset'

Length of output: 6899



Script:

#!/bin/bash
# Extract the implementation of the RegisterAsset function from msg_server.go
ast-grep --lang go --pattern $'func (k Keeper) RegisterAsset(ctx context.Context, req *assetstype.RegisterAssetReq) (*assetstype.RegisterAssetResponse, error) {
  $$$
}' --json

Length of output: 1231

proto/exocore/delegation/v1/genesis.proto (4)

8-8: Approved new import statement.

The import of query.proto is correctly placed and necessary for the new message types introduced in this file.


18-29: Enhancements to GenesisState are well-defined.

The addition of delegation_states, stakers_by_operator, and undelegations with non-nullable constraints enhances the robustness of the data structure. Consider adding more detailed comments to explain the purpose and usage of each new field for better code maintainability.


31-37: New message type DelegationStates is well-formed.

The structure is clear, and the use of non-nullable fields ensures data integrity. Enhance the comments to provide examples of what constitutes a key for better clarity.


39-44: New message type StakersByOperator is correctly implemented.

The message type is properly defined with all fields marked as non-nullable. It would be beneficial to include examples or a more detailed description of the key format used here.

precompiles/assets/tx.go (1)

95-97: Well-implemented client chain retrieval, suggest adding explanatory comments.

The conversion of LayerZeroChainID to uint32 is crucial and correctly implemented. Consider adding a comment to explain why this conversion is necessary, especially if there are specific constraints or compatibility issues.

x/operator/keeper/operator_info_test.go (2)

25-26: Consider removing debug print statements from test cases.

The fmt.Println statement on line 26 should be removed from the test case to keep the test output clean and focused only on test results.


37-49: Ensure consistency in test assertions.

The test case TestAllOperators sets up an OperatorDetail, but it's unclear if the Contains assertion in line 49 is sufficient to verify the correctness of AllOperators function. Consider using more specific assertions that check individual fields of the returned operators.

x/operator/keeper/keeper.go (1)

18-25: Document the rationale behind not using context for passing flags.

The comment on lines 22-24 explains why the isGeneralInit flag is not passed through the context. It would be beneficial to expand this comment to include potential alternatives considered or why they were dismissed, to provide more context to future maintainers.

proto/exocore/assets/v1/genesis.proto (1)

39-45: Ensure AssetsByOperator struct is utilized correctly.

The AssetsByOperator message has been introduced to store operator and their assets state. It's important to verify that this structure is being used appropriately across the module to maintain state integrity.

Verification successful

The AssetsByOperator struct is utilized correctly.

The search results show that the AssetsByOperator struct is used in various parts of the module, including the keeper and genesis state files. This indicates that the structure is integrated and utilized as intended across the codebase, maintaining state integrity.

  • Files verified:
    • x/assets/keeper/operator_asset.go
    • x/assets/types/genesis.go
    • x/assets/types/genesis.pb.go
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for usages of `AssetsByOperator` to ensure it's being utilized correctly.
rg 'AssetsByOperator' --type go

Length of output: 3165

x/assets/types/keys.go (2)

94-96: Approved: Function IsJoinedStoreKey correctly checks for joined keys.


94-102: Approved: Function ParseJoinedStoreKey correctly parses and validates the key structure.

x/assets/keeper/staker_asset.go (2)

14-44: Approved: Function AllDeposits is well-implemented with proper resource management and error handling.


Line range hint 47-64: Approved: Function GetStakerAssetInfos correctly retrieves asset information for a specific staker.

x/delegation/keeper/cross_chain_tx_process.go (1)

Line range hint 119-131: Approved: Function UndelegateFrom correctly handles undelegation logic with proper validation and state updates.

x/assets/keeper/genesis_test.go (1)

10-156: Approved: Function TestInitGenesisFromBootStrap is well-implemented with comprehensive test cases and proper handling of test state modifications.

x/operator/keeper/genesis.go (1)

11-173: Approved: Function InitGenesis in the operator module is robust, correctly handling multiple aspects of genesis initialization with detailed error handling.

x/operator/types/genesis_test.go (2)

62-67: Ensure no duplicate or invalid data in genesis state.

These test cases effectively check for duplicates and invalid data in the genesis state. It's crucial to ensure that the genesis state is correctly initialized to prevent issues at runtime.

Also applies to: 76-90, 102-104, 118-120, 134-139, 168-170, 190-195


51-53: Check the address validation logic for operator address.

The test case checks for the validity of the operator address using a hardcoded "invalid" string. Ensure the test is robust by checking various forms of invalid addresses.

Verification successful

Check the address validation logic for operator address.

The validation logic is implemented in the ValidateHexAddress function found in x/assets/types/params.go. Additionally, the test cases in x/operator/types/genesis_test.go cover various forms of invalid addresses, ensuring robustness.

  • Implementation: x/assets/types/params.go
  • Test Cases: x/operator/types/genesis_test.go
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the address validation logic is robust.

# Test: Search for the address validation function. Expect: A robust validation logic.
ast-grep --lang go --pattern $'func ValidateAddress($_, $_) {
  $$$
}'

Length of output: 71



Script:

#!/bin/bash
# Description: Verify that the address validation logic is robust.

# Search for address validation function by looking for common validation patterns and functions in Go.
# Look for functions that might validate addresses by searching for keywords 'validate' and 'address'.
rg 'validate.*address' --glob '*.go'

# Also, look for the usage of the term 'invalid' in test files to see if other invalid address cases are being tested.
rg 'invalid' --glob '*_test.go'

Length of output: 11889



Script:

#!/bin/bash
# Description: Verify the robustness of the address validation logic.

# Check the implementation of ValidateHexAddress function.
rg 'func ValidateHexAddress' --glob '*.go'

# Check the test cases in x/operator/types/genesis_test.go to ensure various forms of invalid addresses are covered.
rg 'invalid' x/operator/types/genesis_test.go

Length of output: 792

x/assets/keeper/staker_asset_test.go (1)

88-90: Ensure correct handling of WaitUnbondingAmount.

The tests now include checks for WaitUnbondingAmount. This is important for accurately tracking the unbonding amounts which are critical for financial calculations in staking logic.

Also applies to: 93-95

x/operator/keeper/usd_value_test.go (1)

123-123: Check asset information retrieval in voting power test.

The retrieval of asset information using the AssetBasicInfo field is crucial for ensuring the correct calculation of voting power based on asset values. Ensure that this retrieval is robust and handles possible edge cases.

x/assets/keeper/operator_asset.go (1)

13-44: Review the implementation of asset retrieval by operators.

The function AllOperatorAssets efficiently retrieves all assets associated with operators. The use of a prefix store and iterator ensures optimal performance. However, ensure error handling and data consistency are robust, especially in edge cases where data might be corrupted or missing.

x/operator/client/cli/tx.go (1)

78-82: Clarification on default earning address behavior.

The comment and logic suggest that if no earning address is provided, it defaults to the sender's address. This behavior is implicit and could benefit from explicit documentation in the command's help text to ensure it's clear to users.

app/ethtest_helper.go (1)

Line range hint 192-214: Clarification needed on staking total amount comment.

The comment about the staking total amount being required to be zero during initialization is unclear. It would be helpful to expand on why this is necessary, as it impacts understanding the initial state setup for assets.

x/operator/keeper/slash.go (4)

49-49: Validate future SlashEventHeight properly.

The validation logic to ensure that the SlashEventHeight does not exceed the current block height is crucial for the integrity of the slashing process. This prevents retrospective or future-dated slashing which could lead to inconsistencies or abuses.


85-86: Initialization of slice fields in SlashExecutionInfo.

Initializing the SlashUndelegations and SlashAssetsPool slices with zero length is a good practice as it ensures that these slices are ready to use and avoids potential nil slice issues.


94-94: Appending to SlashUndelegations within a loop.

Appending to the SlashUndelegations slice within a loop based on conditional logic is efficient and ensures that only relevant undelegations are considered. This is a good use of memory and processing resources.
[APROVED]


135-135: Efficient management of slashed assets.

Appending to the SlashAssetsPool slice within the asset iteration function is efficient. This ensures that only the assets that are actually slashed are recorded, which is crucial for accurate and efficient state management.

proto/exocore/assets/v1/tx.proto (2)

72-72: Clarify the use of (gogoproto.nullable) = false

The use of (gogoproto.nullable) = false on asset_basic_info within StakingAssetInfo ensures that the AssetInfo cannot be null. This is a good practice for required fields to prevent runtime errors due to null dereferencing.


119-120: Clarify the exclusion of wait_unbonding_amount

The comment on total_amount now specifies that it excludes the wait_unbonding_amount. This is a useful clarification for maintaining clear understanding of the asset's total amount during calculations and reporting.

x/delegation/types/genesis.go (1)

144-184: Ensure proper error handling and data validation in ValidateDelegationStates

The function ValidateDelegationStates properly checks for nil and negative values in delegation states, which is crucial for data integrity. However, consider adding checks for other potential data anomalies, such as extremely large values which might indicate data corruption or overflow issues.

app/test_helpers.go (2)

221-221: Clarification on StakingTotalAmount initialization

The initialization of StakingTotalAmount to zero is noted as being required due to deposits being handled post-token initialization. This is a critical implementation detail that ensures correct application state before operations that could affect token amounts.


229-236: Review initialization of OperatorInfo

The initialization of OperatorInfo within OperatorDetail includes setting the Commission to zero. Ensure this is the intended behavior, as zero commission might not be typical or expected in operational environments.

x/operator/keeper/usd_value.go (1)

261-276: Ensure proper error handling in GetAllUSDValues.

In the function GetAllUSDValues, it retrieves all USD values. It's crucial to ensure that any potential errors during the unmarshalling process are handled appropriately. Currently, the code assumes the unmarshalling will always succeed which might not be the case.

cmd/exocored/root.go (2)

Line range hint 270-290: Ensure chain ID is correctly set in newApp.

The function newApp initializes the ExocoreApp with various configurations. It is crucial to ensure that the chainID is correctly retrieved and set, as it influences many operational aspects of the application.

Verification successful

Ensure correct retrieval and setting of chainID in newApp.

The chainID is correctly retrieved using the getChainID function and set using baseapp.SetChainID(chainID) in the newApp function.

  • Retrieval: chainID := getChainID(appOpts, homePath) is present in the cmd/exocored/root.go file.
  • Setting: baseapp.SetChainID(chainID) is also present in the same file.

No issues found with the retrieval and setting of chainID.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the chain ID is correctly set and used in the newApp function.

# Test: Search for chainID usage in the newApp function. Expect: Correct retrieval and usage.
ast-grep --lang go --pattern $'func (a appCreator) newApp($_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_) {
  $_ := getChainID($_, $_)
  $$$
  baseapp.SetChainID($_)
}'

Length of output: 241



Script:

#!/bin/bash
# Description: Verify the retrieval and setting of chainID in the newApp function.

# Search for the definition and retrieval of chainID in the newApp function.
ast-grep --lang go --pattern $'func (a appCreator) newApp($_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_) {
  chainID := $_
  $$$
}' 

# Search for the setting of chainID in the newApp function.
ast-grep --lang go --pattern $'func (a appCreator) newApp($_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_) {
  $$$
  baseapp.SetChainID(chainID)
}'

Length of output: 425



Script:

#!/bin/bash
# Description: Verify the retrieval and setting of chainID in the newApp function.

# Search for the definition and retrieval of chainID in the newApp function.
rg 'chainID := .*' -A 10 -B 10 --glob '*.go' | tee chainID_retrieval.txt

# Search for the setting of chainID in the newApp function.
rg 'baseapp.SetChainID\(chainID\)' -A 10 -B 10 --glob '*.go' | tee chainID_setting.txt

Length of output: 305



Script:

#!/bin/bash
# Description: Verify the retrieval and setting of chainID in the newApp function.

# Search for the definition and retrieval of chainID in the newApp function.
rg 'chainID := .*' -A 10 -B 10 --glob '*.go' 

# Search for the setting of chainID in the newApp function.
rg 'baseapp.SetChainID\(chainID\)' -A 10 -B 10 --glob '*.go'

Length of output: 29371


Line range hint 305-331: Check for potential improvements in appExport.

The appExport function handles the export of app state and validators. It's important to ensure that the function handles different scenarios robustly, especially the condition where height is not -1, which implies loading a specific blockchain height.

Verification successful

Potential Improvements in appExport Function Handling Different Scenarios

The appExport function in cmd/exocored/root.go handles the export of app state and validators, particularly focusing on scenarios where height is not -1. The function appears to robustly handle the condition by creating an instance of ExocoreApp and loading the specified height if needed. However, it's always good to ensure edge cases and potential improvements are considered.

  • Function Implementation:

    • The function checks whether height is -1 and handles the creation of ExocoreApp accordingly.
    • If height is not -1, it attempts to load the specified height.
    • If any error occurs during this process, it returns the error.
  • Potential Improvements:

    • Error Handling: Ensure all possible errors are caught and handled gracefully.
    • Logging: Add detailed logging for better traceability and debugging.
    • Configuration Checks: Validate all configurations and parameters before proceeding with the export.

Code Locations:

  • cmd/exocored/root.go: appExport function implementation.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify robust handling of different scenarios in appExport function.

# Test: Search for conditional logic handling different heights. Expect: Robust handling of edge cases.
ast-grep --lang go --pattern $'func (a appCreator) appExport($_, $_, $_, height int64, $_, $_, $_, $_) ($_ error) {
  if height != -1 {
    $$$
  } else {
    $$$
  }
}'

Length of output: 170



Script:

#!/bin/bash
# Description: Verify the existence of the appExport function in the codebase.

# Search for the appExport function definition in the codebase.
rg "func (a appCreator) appExport"

Length of output: 36



Script:

#!/bin/bash
# Description: Broaden the search to find any function related to exporting app state or validators.

# Search for any function definitions that might be related to exporting app state or validators.
rg "func.*Export"

Length of output: 1697



Script:

#!/bin/bash
# Description: Extract the full implementation of the appExport function in cmd/exocored/root.go.

# Extract the full implementation of the appExport function.
ast-grep --lang go --pattern $'func (a appCreator) appExport($_, $_, $_, height int64, $_, $_, $_, $_) ($_ error) {
  $$$
}' cmd/exocored/root.go

Length of output: 146



Script:

#!/bin/bash
# Description: Display the content of cmd/exocored/root.go to manually verify the appExport function definition.

# Display the content of cmd/exocored/root.go.
cat cmd/exocored/root.go

Length of output: 11413

testutil/utils.go (3)

142-142: Clarification on the StakingTotalAmount field.

The comment indicates that the StakingTotalAmount is required to be zero because deposits are handled after token initialization. This is a good practice as it ensures clarity on the state of the tokens at the time of initialization.


151-166: Consider adding more detailed comments for OperatorDetail.

The struct OperatorDetail is used to initialize operator information. It would be beneficial to include more detailed comments explaining the purpose of each field, especially OperatorMetaInfo and Commission, to aid future maintainability and understanding.

+  // OperatorMetaInfo provides metadata about the operator
+  // Commission defines the fee structure for the operator

Line range hint 179-188: Check consistency of OperatorAddress usage.

The OperatorAddress field is used as a key in the consensus key records. Ensure that this address is consistently used across all modules and that its format (e.g., bech32, hex) is standardized across your application to avoid potential bugs or mismatches.

x/operator/types/genesis.go (3)

24-24: Ensure proper unit testing for DefaultGenesis function.

The DefaultGenesis function initializes a GenesisState with empty slices. Ensure that unit tests cover this initialization to verify correct behavior and prevent future regressions.

Verification successful

Unit tests for DefaultGenesis function are already present.

The DefaultGenesis function is tested within the TestValidateGenesis method in x/operator/types/genesis_test.go. This test suite includes various test cases to ensure the correct behavior of the DefaultGenesis function, covering valid and invalid scenarios.

  • x/operator/types/genesis_test.go
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify unit tests for `DefaultGenesis` function.

# Test: Search for unit tests related to `DefaultGenesis`.
rg --type go $'func TestDefaultGenesis'

Length of output: 40



Script:

#!/bin/bash
# Description: Locate the `DefaultGenesis` function definition in the codebase.

# Search for the `DefaultGenesis` function definition in Go files.
ast-grep --lang go --pattern 'func DefaultGenesis($_) $_'

Length of output: 59



Script:

#!/bin/bash
# Description: Broaden the search criteria to locate any potential variations of the `DefaultGenesis` function definition.

# Search for any occurrence of `DefaultGenesis` in Go files.
rg --type go 'DefaultGenesis'

Length of output: 6374



Script:

#!/bin/bash
# Description: Verify the content of `x/operator/types/genesis_test.go` for tests related to `DefaultGenesis`.

# Display the content of `x/operator/types/genesis_test.go`.
cat x/operator/types/genesis_test.go

Length of output: 5496


Line range hint 30-98: Check the comprehensive validation logic in ValidateOperators.

The ValidateOperators method contains extensive validation logic, including duplicate address checks, Bech32 format validation, and earnings address validation. It's crucial to ensure that all these checks are covered thoroughly in unit tests, particularly the new checks added for ClientChainEarningsAddr and commission validations.


Line range hint 100-157: Review error handling and validation logic in ValidateOperatorConsKeyRecords.

This function performs multiple checks on consensus keys and addresses, including Bech32 format validation and duplicate address checking. Ensure these validations are correctly implemented and covered by unit tests, especially since this function handles critical data for chain operations.

x/assets/types/genesis.go (3)

11-14: Approved: New struct definition for TotalSupplyAndStaking.

The struct TotalSupplyAndStaking has been defined to hold total supply and staking amounts as math.Int types, which is appropriate for handling large numbers without floating point inaccuracies.


268-342: Approved: Comprehensive validation in ValidateOperatorAssets.

The function ValidateOperatorAssets provides thorough validation for operator assets, ensuring no inconsistencies in the asset registration and staking amounts. This is critical for maintaining the integrity of the blockchain state.


343-364: Approved: Overall genesis state validation.

The Validate method aggregates all individual validation functions to provide a comprehensive check of the genesis state. This method is crucial for ensuring the blockchain starts in a consistent and expected state.

cmd/exocored/testnet.go (1)

Line range hint 402-471: Ensure consistency in data structures and initialization within getTestExocoreGenesis.

The function getTestExocoreGenesis appears to handle the initialization of various genesis states correctly based on the new structures and fields mentioned in the PR summary. However, ensure that the new fields and data structures used here are consistently initialized and used across other parts of the codebase that interact with these modules.

Verification successful

Initialization and Usage of New Fields Verified

The new fields OperatorDetail and GenesisState are consistently initialized and used across the codebase. The function getTestExocoreGenesis correctly handles the initialization of these fields.

  • The fields OperatorDetail and GenesisState are defined and used in various places, ensuring consistency.
  • The initialization within getTestExocoreGenesis aligns with their definitions and usages elsewhere.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of new fields across the codebase.

# Search for new field `OperatorDetail` and `GenesisState` modifications in other relevant files.
fd . --type f --exec rg --type py 'OperatorDetail|GenesisState'

Length of output: 33941

app/app.go (2)

548-549: Modification of NewExocoreApp function to handle isGeneralInit parameter.

The isGeneralInit boolean parameter has been added to the NewExocoreApp function to conditionally initialize various keepers based on the genesis state. This change is crucial for ensuring that initialization logic can be customized based on how the genesis state is set up, which is important for the application's flexibility in startup configurations. The implementation appears correct and aligns with the newly introduced constant.

Also applies to: 566-566


301-310: New constant GenesisIsGeneralInit introduced.

The constant GenesisIsGeneralInit has been introduced to manage initialization states based on the genesis file. This addition appears to be well-documented with comments explaining its purpose and future considerations. However, it mentions a dependency on code from another repository which should be tracked to ensure compatibility and timely updates.

x/operator/keeper/slash.go Outdated Show resolved Hide resolved
x/operator/keeper/usd_value.go Outdated Show resolved Hide resolved
x/assets/types/genesis.go Outdated Show resolved Hide resolved
x/assets/types/genesis.go Outdated Show resolved Hide resolved
x/assets/types/genesis.go Outdated Show resolved Hide resolved
x/operator/types/expected_keepers.go Show resolved Hide resolved
proto/exocore/assets/v1/genesis.proto Show resolved Hide resolved
x/delegation/keeper/genesis.go Outdated Show resolved Hide resolved
x/delegation/keeper/genesis.go Outdated Show resolved Hide resolved
x/assets/keeper/client_chain_asset.go Show resolved Hide resolved
@TimmyExogenous TimmyExogenous force-pushed the actual-genesis-export branch from 9502f43 to ede2cba Compare August 9, 2024 12:03
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: 21

Outside diff range, codebase verification and nitpick comments (14)
x/assets/keeper/client_chain_and_asset_test.go (2)

43-43: Check for comprehensive client chain assertions.

The test now only checks for the presence of the first client chain. Consider verifying all expected client chains to ensure comprehensive validation.

- suite.Contains(clientChains, defaultGensisState.ClientChains[0])
+ for _, expectedChain := range defaultGensisState.ClientChains {
+     suite.Contains(clientChains, expectedChain)
+ }

52-52: Ensure thorough asset assertions.

Similar to client chains, consider verifying all expected assets to ensure comprehensive validation.

- suite.Contains(assets, defaultGensisState.Tokens[0])
+ for _, expectedAsset := range defaultGensisState.Tokens {
+     suite.Contains(assets, expectedAsset)
+ }
x/assets/types/errors.go (1)

95-98: Ensure consistency of error messages.

The error message "the joined key can't be parsed" should be consistent with the style and clarity of other error messages in the file. Consider revising for uniformity if needed.

- "the joined key can't be parsed"
+ "unable to parse the joined key"
x/operator/keeper/operator_info_test.go (3)

4-5: Remove unnecessary import.

The fmt package is imported but only used for a debug print statement. Consider removing the import and the print statement for cleaner code.

-	"fmt"

25-26: Remove debug print statement.

The print statement is likely used for debugging purposes. It should be removed to keep the test output clean.

-	fmt.Println("the acc address length is:", len(suite.AccAddress))

37-49: Add comprehensive test coverage for OperatorDetail fields.

The current tests do not consistently cover all fields of OperatorInfo, particularly ApproveAddr and ClientChainEarningsAddr. Ensure that all fields are included in the tests to maintain comprehensive coverage.

  • Ensure ApproveAddr and ClientChainEarningsAddr are tested in operator_info_test.go and other relevant test files.
Analysis chain

Ensure comprehensive test coverage for OperatorDetail.

The TestAllOperators method has been updated to use OperatorDetail. Ensure that all fields of OperatorDetail are being tested, especially if more fields are added in the future.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all fields of `OperatorDetail` are covered in tests.

# Test: Search for `OperatorDetail` usage in tests. Expect: Comprehensive test coverage for all fields.
rg 'OperatorDetail' --type go -A 10

Length of output: 22484


Script:

#!/bin/bash
# Extract the definition of `OperatorInfo` to understand its fields.
ast-grep --lang go --pattern 'type OperatorInfo struct {
  $$$
}' 

# Check for test coverage of `OperatorInfo` fields.
rg 'OperatorInfo' --type go -A 10

Length of output: 82437

x/assets/keeper/staker_asset_test.go (1)

88-90: Add Test Cases for Non-Zero WaitUnbondingAmount

The current test coverage for WaitUnbondingAmount only includes scenarios where it is set to zero. Consider adding test cases with non-zero values to ensure comprehensive validation of its behavior.

  • Review and update tests in x/assets/keeper/staker_asset_test.go and other relevant files to include non-zero scenarios for WaitUnbondingAmount.
Analysis chain

Ensure comprehensive test coverage for WaitUnbondingAmount.

The addition of the WaitUnbondingAmount field is a valuable enhancement. Ensure that the test cases cover scenarios where this field is non-zero to validate its behavior.

Also applies to: 93-95

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that `WaitUnbondingAmount` is adequately tested with non-zero values.

# Test: Search for tests involving `WaitUnbondingAmount` with non-zero values.
rg --type go --word-regexp 'WaitUnbondingAmount:\s*math\.NewInt\([1-9]\d*\)'

Length of output: 78


Script:

#!/bin/bash
# Description: Refine the search for tests involving `WaitUnbondingAmount` with non-zero values.

# Test: Search for all instances where `WaitUnbondingAmount` is set, and check for non-zero values.
rg --type go 'WaitUnbondingAmount:\s*math\.NewInt\(\d+\)' -A 3

Length of output: 2297

x/operator/client/cli/tx.go (2)

22-22: Document the purpose of FlagEarningAddr.

Ensure that the constant FlagEarningAddr is well-documented and its usage is clear throughout the code.

// FlagEarningAddr is used to specify a distinct address for receiving earnings.

78-82: Ensure clarity in the flag description.

The description for FlagEarningAddr should clearly state its purpose and default behavior.

- "The address which is used to receive the earning reward in the Exocore chain. "+
+ "The address used to receive earnings in the Exocore chain. Defaults to the sender's address if not provided."
x/delegation/keeper/un_delegation_state.go (1)

42-42: Reminder: Clarify the TODO comment.

The comment suggests checking if the state can only be set once. Consider clarifying or addressing this TODO.

proto/exocore/assets/v1/tx.proto (1)

120-121: Improved documentation for total_amount.

The updated comment clarifies that total_amount excludes wait_unbonding_amount, which enhances understanding for developers.

x/operator/keeper/slash.go (1)

Line range hint 172-172: Address TODO comment regarding return value.

The TODO comment suggests a future change in the return value to reflect the amount of burned Exo.

Would you like me to help implement this change or open a GitHub issue to track it?

testutil/utils.go (1)

203-227: Incomplete Transition to OperatorDetail

The transition from OperatorInfo to OperatorDetail is incomplete. There are still many instances of OperatorInfo in the codebase. Please update all occurrences to OperatorDetail to maintain consistency and avoid potential issues.

  • Files with OperatorInfo:
    • x/slash/keeper/slash_state.go
    • x/slash/types/keys.go
    • x/operator/types/keys.go
    • x/operator/keeper/operator_info_test.go
    • x/operator/keeper/operator.go
    • x/dogfood/keeper/opt_out_test.go
    • x/dogfood/keeper/unbonding_test.go
    • x/operator/keeper/msg_server.go
    • x/operator/keeper/grpc_query.go
    • x/operator/types/genesis_test.go
    • x/operator/types/tx.pb.go
    • x/operator/types/query.pb.go
    • x/operator/client/cli/query.go
    • x/operator/types/genesis.go
    • x/operator/keeper/genesis.go
    • x/delegation/keeper/delegation_op_test.go
    • x/avs/keeper/avs_test.go
    • testutil/utils.go
    • cmd/exocored/testnet.go
    • app/ethtest_helper.go
    • app/test_helpers.go
Analysis chain

Ensure consistent usage of OperatorDetail.

Verify that all instances of OperatorInfo have been updated to OperatorDetail throughout the codebase to maintain consistency.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent usage of `OperatorDetail`.

# Test: Search for any remaining instances of `OperatorInfo`.
rg --type go 'OperatorInfo'

Length of output: 17193

x/operator/keeper/consensus_keys.go (1)

537-549: Add error handling for encoding in GetAllOperatorKeyRemovals.

Consider adding error handling for hexutil.Encode to ensure robustness in case of unexpected encoding issues.

encodedKey, err := hexutil.Encode(iterator.Key())
if err != nil {
    return nil, err
}
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9502f43 and ede2cba.

Files ignored due to path filters (10)
  • x/assets/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/assets/types/query.pb.go is excluded by !**/*.pb.go
  • x/assets/types/tx.pb.go is excluded by !**/*.pb.go
  • x/assets/types/tx.pb.gw.go is excluded by !**/*.pb.gw.go
  • x/avs/types/query.pb.gw.go is excluded by !**/*.pb.gw.go
  • x/avs/types/tx.pb.gw.go is excluded by !**/*.pb.gw.go
  • x/delegation/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/delegation/types/types/query.pb.go is excluded by !**/*.pb.go
  • x/delegation/types/types/query.pb.gw.go is excluded by !**/*.pb.gw.go
  • x/operator/types/genesis.pb.go is excluded by !**/*.pb.go
Files selected for processing (49)
  • app/app.go (1 hunks)
  • app/ethtest_helper.go (4 hunks)
  • app/test_helpers.go (3 hunks)
  • cmd/exocored/root.go (4 hunks)
  • cmd/exocored/testnet.go (3 hunks)
  • go.mod (2 hunks)
  • local_node.sh (1 hunks)
  • precompiles/assets/tx.go (1 hunks)
  • proto/exocore/assets/v1/genesis.proto (3 hunks)
  • proto/exocore/assets/v1/query.proto (4 hunks)
  • proto/exocore/assets/v1/tx.proto (2 hunks)
  • proto/exocore/delegation/v1/genesis.proto (2 hunks)
  • proto/exocore/operator/v1/genesis.proto (1 hunks)
  • proto/exocore/operator/v1/tx.proto (1 hunks)
  • testutil/utils.go (3 hunks)
  • x/assets/keeper/client_chain_and_asset_test.go (1 hunks)
  • x/assets/keeper/client_chain_asset.go (2 hunks)
  • x/assets/keeper/genesis.go (2 hunks)
  • x/assets/keeper/keeper.go (1 hunks)
  • x/assets/keeper/operator_asset.go (1 hunks)
  • x/assets/keeper/staker_asset.go (2 hunks)
  • x/assets/keeper/staker_asset_test.go (1 hunks)
  • x/assets/types/errors.go (1 hunks)
  • x/assets/types/genesis.go (5 hunks)
  • x/assets/types/genesis_test.go (5 hunks)
  • x/assets/types/keys.go (3 hunks)
  • x/delegation/keeper/delegation.go (2 hunks)
  • x/delegation/keeper/delegation_state.go (5 hunks)
  • x/delegation/keeper/genesis.go (2 hunks)
  • x/delegation/keeper/un_delegation_state.go (1 hunks)
  • x/delegation/types/errors.go (1 hunks)
  • x/delegation/types/genesis.go (2 hunks)
  • x/delegation/types/genesis_test.go (3 hunks)
  • x/delegation/types/keys.go (1 hunks)
  • x/operator/client/cli/tx.go (3 hunks)
  • x/operator/keeper/consensus_keys.go (2 hunks)
  • x/operator/keeper/genesis.go (1 hunks)
  • x/operator/keeper/keeper.go (3 hunks)
  • x/operator/keeper/operator.go (3 hunks)
  • x/operator/keeper/operator_info_test.go (3 hunks)
  • x/operator/keeper/operator_slash_state.go (1 hunks)
  • x/operator/keeper/slash.go (4 hunks)
  • x/operator/keeper/slash_test.go (1 hunks)
  • x/operator/keeper/usd_value.go (9 hunks)
  • x/operator/keeper/usd_value_test.go (2 hunks)
  • x/operator/types/expected_keepers.go (1 hunks)
  • x/operator/types/genesis.go (2 hunks)
  • x/operator/types/genesis_test.go (6 hunks)
  • x/operator/types/keys.go (5 hunks)
Files skipped from review due to trivial changes (2)
  • cmd/exocored/root.go
  • go.mod
Additional context used
Learnings (1)
x/delegation/keeper/un_delegation_state.go (1)
Learnt from: MaxMustermann2
PR: ExocoreNetwork/exocore#95
File: x/dogfood/keeper/unbonding.go:91-116
Timestamp: 2024-06-12T04:29:35.064Z
Learning: The `GetAllUndelegationsToMature` function in `x/dogfood/keeper/unbonding.go` uses an iterator that processes one record per iteration, and the record keys are stored efficiently as a key-value pair with the key being a prefix + big-endian epoch. This storage pattern provides direct and efficient access to the data.
GitHub Check: break-check
proto/exocore/delegation/v1/genesis.proto

[failure] 18-18:
Field "1" with name "associations" on message "GenesisState" changed option "json_name" from "delegations" to "associations".


[failure] 18-18:
Field "1" on message "GenesisState" changed type from "exocore.delegation.v1.DelegationsByStaker" to "exocore.delegation.v1.StakerToOperator".


[failure] 18-18:
Field "1" on message "GenesisState" changed name from "delegations" to "associations".


[failure] 22-22:
Field "2" with name "delegation_states" on message "GenesisState" changed option "json_name" from "associations" to "delegationStates".

proto/exocore/assets/v1/query.proto

[failure] 48-48:
Field "1" on message "QueryAllStakingAssetsInfoResponse" changed type from "exocore.assets.v1.QueryAllStakingAssetsInfoResponse.AllStakingAssetsInfoEntry" to "exocore.assets.v1.StakingAssetInfo".


[failure] 60-60:
Field "1" on message "QueryAssetInfoResponse" changed type from "exocore.assets.v1.QueryAssetInfoResponse.AssetInfosEntry" to "exocore.assets.v1.DepositByAsset".


[failure] 80-80:
Field "1" on message "QueryOperatorAssetInfosResponse" changed type from "exocore.assets.v1.QueryOperatorAssetInfosResponse.AssetInfosEntry" to "exocore.assets.v1.AssetByID".

GitHub Check: Run golangci-lint
x/assets/types/genesis.go

[warning] 109-109:
unused-parameter: parameter 'i' seems to be unused, consider removing or renaming it as _ (revive)


[warning] 183-183:
unused-parameter: parameter 'i' seems to be unused, consider removing or renaming it as _ (revive)


[warning] 205-205:
unused-parameter: parameter 'i' seems to be unused, consider removing or renaming it as _ (revive)

Additional comments not posted (107)
x/assets/keeper/client_chain_and_asset_test.go (1)

29-30: Verify the initialization of StakingTotalAmount.

The StakingTotalAmount is initialized using math.NewIntWithDecimal(201, 6). Ensure this value is correct and aligns with the intended test scenario.

x/delegation/types/errors.go (1)

107-110: Clarify Error Message for Better Understandability.

The error message "the block height to complete the undelegation is invalid" could be more descriptive. Consider specifying what makes the block height invalid.

- "the block height to complete the unelegation is invalid",
+ "the block height to complete the undelegation is invalid: must be greater than the current height",
proto/exocore/delegation/v1/genesis.proto (1)

18-28: Verify Impact of Breaking Changes in GenesisState.

The changes to the GenesisState message, including renaming and changing field types, introduce breaking changes. Ensure that all dependent systems and clients are updated to handle these changes.

Tools
GitHub Check: break-check

[failure] 18-18:
Field "1" with name "associations" on message "GenesisState" changed option "json_name" from "delegations" to "associations".


[failure] 18-18:
Field "1" on message "GenesisState" changed type from "exocore.delegation.v1.DelegationsByStaker" to "exocore.delegation.v1.StakerToOperator".


[failure] 18-18:
Field "1" on message "GenesisState" changed name from "delegations" to "associations".


[failure] 22-22:
Field "2" with name "delegation_states" on message "GenesisState" changed option "json_name" from "associations" to "delegationStates".

x/assets/keeper/keeper.go (1)

50-56: Verify Impact of Return Type Changes in IAssets Interface.

The return types of several methods in the IAssets interface have been changed from maps to slices. Ensure that all implementations and usages of these methods are updated to handle the new return types.

x/assets/keeper/genesis.go (2)

Line range hint 29-54:
Optimize map initialization and error handling in InitGenesis.

In the function InitGenesis, the map tokenState is initialized with a size of 0, which is not optimal for performance. Initializing it with the expected size, based on data.Tokens, would reduce potential reallocations. Additionally, the error handling during the setting of StakingAssetInfo could be more descriptive to aid debugging.

- tokenState := make(map[string]types.TotalSupplyAndStaking, 0)
+ tokenState := make(map[string]types.TotalSupplyAndStaking, len(data.Tokens))
- panic(errorsmod.Wrapf(
+ return errorsmod.Wrapf(

Line range hint 62-103:
Review and potentially refactor the ExportGenesis function for clarity and error handling.

The function ExportGenesis is crucial for exporting the genesis state of assets. It currently panics on any error encountered, which could be replaced with error returns for better error handling and consistency with other modules. Additionally, consider breaking this function into smaller sub-functions for better readability and maintainability.

- panic(err)
+ return nil, err
x/operator/keeper/keeper.go (1)

16-17: Simplification of Keeper initialization.

The removal of the historicalCtx field and parameter simplifies the Keeper initialization process. This change reduces complexity related to context management within the keeper's functionality. Ensure that the removal does not affect any dependent logic or functionality.

proto/exocore/assets/v1/genesis.proto (3)

30-34: Ensure handling of operator_assets in genesis functions.

The operator_assets field has been added to GenesisState. Ensure that the InitGenesis and ExportGenesis functions are updated to handle this new field.


47-54: Clarify the purpose of AssetByID.

The AssetByID message is introduced to encapsulate asset information. Ensure that its usage is well-documented and integrated into the system's logic.

Verification successful

AssetByID is documented inline.

The AssetByID message is documented with inline comments within the codebase, explaining its purpose and usage. These comments provide sufficient documentation for understanding its role in the system.

  • Inline comments in x/assets/types/genesis.pb.go describe AssetByID as a helper struct used in the genesis state to store asset IDs and their info for an operator.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration and documentation of `AssetByID`.

# Test: Search for `AssetByID` usage in the codebase. Expect: Proper integration and documentation.
rg 'AssetByID' --type go

Length of output: 3925


Script:

#!/bin/bash
# Search for documentation related to `AssetByID` in markdown files or comments within the codebase.
rg 'AssetByID' --type md

Length of output: 24


Script:

#!/bin/bash
# Search for comments related to `AssetByID` in Go files to check for inline documentation.
rg 'AssetByID' --type go -A 3 | rg '//'

Length of output: 675


36-45: Clarify the purpose of AssetsByOperator.

The AssetsByOperator message is introduced to store operator asset states. Ensure that its usage is well-documented and integrated into the system's logic.

x/assets/keeper/client_chain_asset.go (2)

46-48: Validation for negative staking amounts is appropriate.

The added validation in SetStakingAssetInfo to prevent negative staking amounts is a good practice to ensure data integrity.


94-103: Consider edge case handling in GetAllStakingAssetsInfo.

The method now returns a slice instead of a map. Ensure that edge cases, such as empty data, are handled appropriately.

x/delegation/types/keys.go (1)

Line range hint 75-81:
LGTM! But verify the function usage in the codebase.

The renaming of the function to ParseStakerAssetIDAndOperator improves readability and aligns with its functionality.

However, ensure that all function calls to ParseStakerAssetIDAndOperator match the new name.

Verification successful

All function calls to ParseStakerAssetIDAndOperator are correctly updated. The function is consistently used with its new name across the codebase, ensuring that there are no mismatches or outdated references.

  • x/delegation/keeper/delegation_state.go
  • x/delegation/types/genesis.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `ParseStakerAssetIDAndOperator` match the new name.

# Test: Search for the function usage. Expect: Only occurrences of the new name.
rg --type go -A 5 $'ParseStakerAssetIDAndOperator'

Length of output: 1733

x/assets/keeper/staker_asset.go (2)

14-45: LGTM! New method AllDeposits is well-implemented.

The AllDeposits method effectively retrieves and aggregates deposit information for all stakers. It handles potential errors and returns a comprehensive view of deposits.


Line range hint 47-64:
LGTM! But verify the method usage in the codebase.

The return type of GetStakerAssetInfos has been changed from a map to a slice, which streamlines the output format.

However, ensure that all method calls to GetStakerAssetInfos handle the new return type.

Verification successful

Method usage of GetStakerAssetInfos is correctly updated. The method is used in x/assets/keeper/grpc_query.go and tested in x/assets/keeper/staker_asset_test.go, both of which handle the new slice return type appropriately. No further action is required.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all method calls to `GetStakerAssetInfos` handle the new return type.

# Test: Search for the method usage. Expect: Only occurrences handling the new return type.
rg --type go -A 5 $'GetStakerAssetInfos'

Length of output: 2783

x/operator/keeper/slash_test.go (1)

75-79: LGTM! Dereferencing removal enhances readability.

The removal of dereferencing in TestSlashWithInfractionReason enhances readability and reduces potential nil pointer dereference issues.

precompiles/assets/tx.go (1)

146-146: Verify the impact of passing asset by value instead of by reference.

The change from passing a pointer to passing the asset variable directly might affect how SetStakingAssetInfo handles AssetBasicInfo. Ensure that this modification does not introduce unintended side effects, such as performance issues or incorrect data handling.

x/assets/types/keys.go (2)

94-96: LGTM! The IsJoinedStoreKey function enhances utility.

The addition of IsJoinedStoreKey provides a straightforward way to determine the structure of keys, improving the module's robustness.


Line range hint 102-108:
Improved error handling in ParseJoinedStoreKey.

Changing the error type to ErrParseJoinedKey provides a more accurate description of the error context, aiding in debugging and maintenance.

x/operator/types/expected_keepers.go (1)

27-27: Verify the impact of changing GetAllStakingAssetsInfo return type.

The return type change from a map to a slice may affect iteration and access patterns in code that implements or utilizes this interface. Ensure that all consumers of this method are updated accordingly.

Verification successful

Return type change of GetAllStakingAssetsInfo is compatible with current usage.

The change from a map to a slice has been accounted for in the codebase. The method is used in various files, and the operations performed on its return value are consistent with slice operations, such as iteration and length checks. The test files further confirm that the change has been addressed appropriately. No further action is required.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `GetAllStakingAssetsInfo` to ensure compatibility with the new return type.

# Test: Search for all usages of `GetAllStakingAssetsInfo`. Expect: Proper handling of the new return type.
rg --type go 'GetAllStakingAssetsInfo' -A 5

Length of output: 4475

x/operator/types/genesis_test.go (1)

Line range hint 27-220:
Comprehensive test coverage for genesis validation.

The restructuring and addition of new test cases significantly enhance the robustness of the genesis validation logic. The tests cover a wide range of invalid states, ensuring thorough validation.

x/assets/keeper/operator_asset.go (2)

14-43: Efficient retrieval and organization of operator assets.

The AllOperatorAssets function efficiently retrieves and organizes operator assets into a structured format. The use of slices for grouping is a clear and effective approach.


46-55: Improved structure for operator asset information.

The change to return a slice of AssetByID improves the consistency and usability of the function. This aligns with the overall enhancements in asset information representation.

x/delegation/types/genesis_test.go (11)

70-72: Test case "base, should pass" looks good.

The test case correctly uses the new delegationStates structure.


75-82: Test case "invalid staker id" effectively tests validation logic.

The test case correctly manipulates the Key to test invalid staker ID handling.


86-93: Test case "duplicate state key" correctly tests for duplicates.

The test case effectively checks the validation logic for duplicate state keys.


98-105: Test case "invalid asset id" correctly tests validation logic.

The test case manipulates the Key to test invalid asset ID handling.


110-120: Test case "asset id mismatch" effectively tests mismatched IDs.

The test case correctly manipulates the Key to create a mismatch.


124-131: Test case "nil wrapped undelegatable share" correctly tests nil handling.

The test case effectively checks the validation logic for nil UndelegatableShare.


135-142: Test case "nil wrapped unbonding amount" correctly tests nil handling.

The test case effectively checks the validation logic for nil WaitUndelegationAmount.


146-153: Test case "negative wrapped undelegatable share" correctly tests negative handling.

The test case effectively checks the validation logic for negative UndelegatableShare.


158-165: Test case "invalid operator address" effectively tests validation logic.

The test case manipulates the Key to test invalid operator address handling.


Line range hint 170-181:
Test case "duplicate stakerID in associations" correctly tests for duplicates.

The test case effectively checks the validation logic for duplicate StakerID in Associations.


Line range hint 185-196:
Test case "one stakerID in associations" correctly tests single StakerID handling.

The test case effectively checks the validation logic for a single StakerID in Associations.

proto/exocore/assets/v1/query.proto (3)

48-48: Change to repeated field in QueryAllStakingAssetsInfoResponse looks good.

The change from a map to a repeated field is consistent with the new structure. Ensure compatibility with existing clients.

Tools
GitHub Check: break-check

[failure] 48-48:
Field "1" on message "QueryAllStakingAssetsInfoResponse" changed type from "exocore.assets.v1.QueryAllStakingAssetsInfoResponse.AllStakingAssetsInfoEntry" to "exocore.assets.v1.StakingAssetInfo".


60-60: Change to repeated field in QueryAssetInfoResponse looks good.

The change from a map to a repeated field is consistent with the new structure. Ensure compatibility with existing clients.

Tools
GitHub Check: break-check

[failure] 60-60:
Field "1" on message "QueryAssetInfoResponse" changed type from "exocore.assets.v1.QueryAssetInfoResponse.AssetInfosEntry" to "exocore.assets.v1.DepositByAsset".


80-80: Change to repeated field in QueryOperatorAssetInfosResponse looks good.

The change from a map to a repeated field is consistent with the new structure. Ensure compatibility with existing clients.

Tools
GitHub Check: break-check

[failure] 80-80:
Field "1" on message "QueryOperatorAssetInfosResponse" changed type from "exocore.assets.v1.QueryOperatorAssetInfosResponse.AssetInfosEntry" to "exocore.assets.v1.AssetByID".

x/operator/keeper/usd_value_test.go (2)

77-79: Change to use AssetBasicInfo as a value in TestAVSUSDValue looks good.

The change simplifies the code by using a value instead of a pointer, aligning with the new handling of AssetBasicInfo.


135-137: Change to use AssetBasicInfo as a value in TestVotingPowerForDogFood looks good.

The change simplifies the code by using a value instead of dereferencing a pointer, aligning with the new handling of AssetBasicInfo.

x/operator/types/keys.go (1)

31-33: Clarify the purpose of AccAddressLength.

The constant AccAddressLength is used for parsing keys. Ensure that its usage is consistent throughout the codebase and that any assumptions about address length are well-documented.

Verification successful

Consistent Usage of AccAddressLength Verified

The constant AccAddressLength is used consistently across the codebase for slicing keys and validating their lengths. Its usage aligns with its intended purpose as described in the comments. Additionally, it is referenced in a test file, suggesting it is being tested for correctness. No further action is needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `AccAddressLength` across the codebase to ensure consistent application.

# Test: Search for occurrences of `AccAddressLength`. Expect: Consistent usage across the codebase.
rg --type go 'AccAddressLength'

Length of output: 1263

x/operator/keeper/operator.go (4)

195-203: Ensure atomicity in SetAllOptedInfo.

The function sets multiple opted states in a loop, which could lead to partial updates if an error occurs midway. Consider implementing a transaction mechanism to ensure atomicity.


205-220: LGTM! But verify method usage.

The method retrieves all opted states and returns them as a slice of operatortypes.OptedState. Ensure that the method is used appropriately and efficiently.

Verification successful

Method usage is appropriate.

The GetAllOptedInfo method is used correctly in genesis.go, with its results assigned to res.OptStates and errors properly handled. No issues found with its usage.

  • x/operator/keeper/genesis.go: Proper error handling and assignment to res.OptStates.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `GetAllOptedInfo` method are appropriate and efficient.

# Test: Search for method usage. Expect: All usages handle `operatortypes.OptedState`.
rg --type go 'GetAllOptedInfo\('

Length of output: 224


Script:

#!/bin/bash
# Check how the `GetAllOptedInfo` method is used in `genesis.go` and examine the context around its usage.
rg --type go -A 10 'GetAllOptedInfo\(' x/operator/keeper/genesis.go

Length of output: 294


25-25: Verify the removal of earnings address validation.

The removal of the validation check for the earnings address might lead to unintended consequences. Ensure that this change is intentional and verify that it does not introduce any issues.


76-89: LGTM! But verify method usage.

The change to return a slice of operatortypes.OperatorDetail enhances the method's functionality. Ensure that all usages of this method are updated to handle the new return type.

Verification successful

All usages of AllOperators correctly handle OperatorDetail.

The changes to the AllOperators method have been appropriately reflected in the codebase. The usages in genesis.go and operator_info_test.go correctly handle the OperatorDetail type. The gRPC-related methods are not affected by the change.

  • x/operator/keeper/genesis.go: Correctly assigns AllOperators result to res.Operators.
  • x/operator/keeper/operator_info_test.go: Tests confirm handling of OperatorDetail.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `AllOperators` method are updated to handle the new return type.

# Test: Search for method usage. Expect: All usages handle `operatortypes.OperatorDetail`.
rg --type go 'AllOperators\('

Length of output: 1776


Script:

#!/bin/bash
# Check how the `AllOperators` method is used in `genesis.go`.
rg --context 5 'AllOperators\(' x/operator/keeper/genesis.go

# Check how the `AllOperators` method is used in `operator_info_test.go`.
rg --context 5 'AllOperators\(' x/operator/keeper/operator_info_test.go

# Check the `QueryAllOperators` function in `grpc_query.go` to see if it handles `OperatorDetail`.
rg --context 5 'QueryAllOperators' x/operator/keeper/grpc_query.go

# Check the `QueryAllOperators` client call in `cli/query.go`.
rg --context 5 'QueryAllOperators' x/operator/client/cli/query.go

Length of output: 2468

proto/exocore/operator/v1/genesis.proto (9)

15-15: Field type change in GenesisState requires careful consideration.

The change from OperatorInfo to OperatorDetail indicates a more detailed structuring of operator data. Ensure all dependent code is updated and consider implications for data migration.


46-54: LGTM! But verify OperatorDetail usage.

The OperatorDetail message provides detailed operator information and aligns with the overall data model. Ensure that it is used appropriately throughout the codebase.

Verification successful

OperatorDetail Usage Verified in genesis.proto

The OperatorDetail message is appropriately used within the genesis.proto file as a repeated field to store multiple operator details. This aligns with its intended purpose for genesis state configuration.

  • File: proto/exocore/operator/v1/genesis.proto
    • repeated OperatorDetail operators = 1 [(gogoproto.nullable) = false];
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `OperatorDetail` message are appropriate.

# Test: Search for message usage. Expect: All usages align with the data model.
rg --type proto 'OperatorDetail'

Length of output: 62


Script:

#!/bin/bash
# Description: Verify all usages of `OperatorDetail` message are appropriate.

# Test: Search for message usage in .proto files. Expect: All usages align with the data model.
rg 'OperatorDetail' --glob '*.proto' -A 5

Length of output: 1361


75-86: LGTM! But verify OperatorUSDValue usage.

The OperatorUSDValue message stores USD values for operators and aligns with the overall data model. Ensure that it is used appropriately throughout the codebase.


66-73: LGTM! But verify AVSUSDValue usage.

The AVSUSDValue message stores USD values for AVS and aligns with the overall data model. Ensure that it is used appropriately throughout the codebase.


56-64: LGTM! But verify OptedState usage.

The OptedState message stores opted state information and aligns with the overall data model. Ensure that it is used appropriately throughout the codebase.

Verification successful

OptedState usage is appropriate.

The OptedState message is used in a repeated field, which aligns with its purpose of storing multiple opted states. This usage is consistent with the intended data model.

  • repeated OptedState opt_states = 3 [(gogoproto.nullable) = false];
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `OptedState` message are appropriate.

# Test: Search for message usage. Expect: All usages align with the data model.
rg --type proto 'OptedState'

Length of output: 58


Script:

#!/bin/bash
# Find all .proto files and search for the usage of `OptedState` within them.
fd --extension proto --exec rg 'OptedState' {}

Length of output: 222


88-96: LGTM! But verify OperatorSlashState usage.

The OperatorSlashState message stores slashing information and aligns with the overall data model. Ensure that it is used appropriately throughout the codebase.

Verification successful

Usage of OperatorSlashState is appropriate and well-integrated.

The OperatorSlashState message is used in various parts of the codebase, including genesis.go, genesis.pb.go, and operator_slash_state.go, indicating it is correctly integrated into the application logic for managing slashing information.

  • x/operator/types/genesis.go: Utilizes OperatorSlashState in slashing state management functions.
  • x/operator/keeper/operator_slash_state.go: Contains functions like SetAllSlashInfo and GetAllSlashInfo, which manage slashing data using OperatorSlashState.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `OperatorSlashState` message are appropriate.

# Test: Search for message usage. Expect: All usages align with the data model.
rg --type proto 'OperatorSlashState'

Length of output: 66


Script:

#!/bin/bash
# Description: Search for all usages of `OperatorSlashState` across the codebase.

# Search for references to `OperatorSlashState` in all files.
rg 'OperatorSlashState'

Length of output: 3833


111-117: LGTM! But verify OperatorKeyRemoval usage.

The OperatorKeyRemoval message tracks operators unbonding their keys and aligns with the overall data model. Ensure that it is used appropriately throughout the codebase.

Verification successful

Verification Successful: OperatorKeyRemoval Usage is Appropriate

The OperatorKeyRemoval message is used correctly as a repeated field in the proto file, aligning with its intended purpose to track operators unbonding their keys. The usage is consistent with the data model requirements.

  • Usage found in a repeated field: operator_key_removals = 8 [(gogoproto.nullable) = false];
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `OperatorKeyRemoval` message are appropriate.

# Test: Search for message usage. Expect: All usages align with the data model.
rg --type proto 'OperatorKeyRemoval'

Length of output: 66


Script:

#!/bin/bash
# Description: Find all .proto files and search for the usage of `OperatorKeyRemoval`.

# Find all .proto files and search for `OperatorKeyRemoval` within them.
fd --extension proto --exec rg 'OperatorKeyRemoval' {}

Length of output: 341


98-109: LGTM! But verify PrevConsKey usage.

The PrevConsKey message stores previous consensus keys and aligns with the overall data model. Ensure that it is used appropriately throughout the codebase.

Verification successful

To verify the usage of PrevConsKey, I'll adjust the search to correctly identify and search within .proto files.


Usage of PrevConsKey is appropriate.

The PrevConsKey message is used as a repeated field pre_cons_keys with gogoproto.nullable set to false, which aligns with the intended data model for storing multiple previous consensus keys.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `PrevConsKey` message are appropriate.

# Test: Search for message usage. Expect: All usages align with the data model.
rg --type proto 'PrevConsKey'

Length of output: 59


Script:

#!/bin/bash
# Find all .proto files and search for the usage of `PrevConsKey`
fd --extension proto --exec rg 'PrevConsKey' {}

Length of output: 300


119-127: LGTM! But verify OperatorConsKeyRecord usage.

The OperatorConsKeyRecord message contains operator address and chain details and aligns with the overall data model. Ensure that it is used appropriately throughout the codebase.

Verification successful

Usage of OperatorConsKeyRecord is appropriate and well-integrated.

The OperatorConsKeyRecord message is used consistently across functions, tests, and protobuf files, indicating proper integration into the system's logic.

  • Functions: Utilized in GetAllOperatorConsKeyRecords and other related functions.
  • Tests: Extensively used in genesis_test.go, ensuring its functionality is validated.
  • Protobuf: Defined and used in genesis.proto and genesis.pb.go.

These usages align with the data model and its intended purpose.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `OperatorConsKeyRecord` message are appropriate.

# Test: Search for message usage. Expect: All usages align with the data model.
rg --type proto 'OperatorConsKeyRecord'

Length of output: 69


Script:

#!/bin/bash
# Find all .proto files and search for the usage of `OperatorConsKeyRecord`.
fd --extension proto --exec rg 'OperatorConsKeyRecord' {}

Length of output: 227


Script:

#!/bin/bash
# Search for all occurrences of `OperatorConsKeyRecord` in the entire repository.
rg 'OperatorConsKeyRecord'

Length of output: 4297

app/ethtest_helper.go (6)

206-213: LGTM! But verify OperatorDetail usage.

The change to OperatorDetail enhances the clarity of the operator's identity. Ensure that all usages of this structure are updated to handle the new fields.

Verification successful

Verification Complete: OperatorDetail Usage is Consistent

The OperatorDetail structure is used consistently across the codebase, including in test files and protobuf-generated files. All usages appear to handle the fields appropriately. No issues were found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `OperatorDetail` structure are updated to handle new fields.

# Test: Search for structure usage. Expect: All usages handle new fields.
rg --type go 'OperatorDetail'

Length of output: 4016


252-252: LGTM! But verify consistency with intended logic.

The inclusion of the operator's account address in dogfoodGenesis should be consistent with the intended logic. Ensure that these changes align with the overall design.


235-242: LGTM! But verify StakersByOperator usage.

The StakersByOperator structure enhances the relationship tracking between operators and stakers. Ensure that it is used appropriately throughout the codebase.

Verification successful

Usage of StakersByOperator is appropriate and consistent.

The StakersByOperator structure is well-integrated into the codebase, with consistent usage across various modules and functions. It is used for managing staker information by operator, aligning with its intended purpose.

  • Files Involved:
    • x/delegation/types/genesis.go
    • x/delegation/keeper/delegation_state.go
    • x/delegation/types/genesis.pb.go

The integration seems robust, with both production and test code utilizing this structure effectively.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `StakersByOperator` structure are appropriate.

# Test: Search for structure usage. Expect: All usages align with the data model.
rg --type go 'StakersByOperator'

Length of output: 6790


243-243: LGTM! But verify consistency with intended logic.

The revision to the delegation genesis state reflects a more organized approach to delegations and associations. Ensure that these changes are consistent with the intended logic.

Verification successful

Consistent Usage of delegationGenesis Across Files

The delegationGenesis variable is consistently used across multiple files (testutil/utils.go, app/test_helpers.go, and app/ethtest_helper.go). In each case, it is created using the same method and parameters, and is marshaled into JSON for inclusion in the genesisState. This confirms that the changes are consistent with the intended logic.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistency of `delegationGenesis` changes with intended logic.

# Test: Search for references to `delegationGenesis`. Expect: Consistent usage.
rg --type go 'delegationGenesis'

Length of output: 740


192-193: LGTM! But verify consistency with intended logic.

The changes simplify the data structure and initialize StakingTotalAmount with actual deposit values. Ensure that these changes are consistent with the intended logic.

Verification successful

Verification Successful: Changes to AssetBasicInfo and StakingTotalAmount are consistent with the codebase logic.

The modifications in app/ethtest_helper.go align with the validation and usage patterns observed throughout the codebase, ensuring that StakingTotalAmount and AssetBasicInfo are set and used correctly. The presence of comprehensive test cases further supports the correctness of these changes.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistency of `AssetBasicInfo` and `StakingTotalAmount` changes with intended logic.

# Test: Search for references to `AssetBasicInfo` and `StakingTotalAmount`. Expect: Consistent usage.
rg --type go 'AssetBasicInfo|StakingTotalAmount'

Length of output: 9158


219-225: LGTM! But verify DelegationStates usage.

The change to DelegationStates introduces a more nuanced approach to managing delegation states. Ensure that all usages of this structure are updated to handle the new fields.

Verification successful

All usages of DelegationStates are updated.

The DelegationStates structure is consistently used across the codebase with the new fields properly handled, as verified in test cases and function implementations.

  • Files Checked:
    • x/delegation/types/genesis_test.go
    • x/delegation/types/genesis.go
    • x/delegation/keeper/genesis.go
    • x/delegation/types/genesis.pb.go
    • x/delegation/keeper/delegation_state.go
    • testutil/utils.go
    • cmd/exocored/testnet.go
    • app/test_helpers.go
    • app/ethtest_helper.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `DelegationStates` structure are updated to handle new fields.

# Test: Search for structure usage. Expect: All usages handle new fields.
rg --type go 'DelegationStates'

Length of output: 6969

x/delegation/keeper/delegation.go (1)

Line range hint 131-143:
Review the impact of changing UndelegationRecord from pointer to value.

Switching from a pointer to a value may affect memory usage and performance. Ensure that this change aligns with the intended behavior, especially if mutability of the record is required.

proto/exocore/assets/v1/tx.proto (1)

73-73: Enforcing non-nullability improves data integrity.

The addition of (gogoproto.nullable) = false ensures that asset_basic_info cannot be null, enhancing the robustness of the StakingAssetInfo message.

x/operator/keeper/slash.go (2)

45-47: Enhance error message for SlashProportion validation.

The error message could be more informative by explicitly stating the expected condition.

- return errorsmod.Wrapf(types.ErrValueIsNilOrZero, "SlashProportion: %+v", parameter.SlashProportion)
+ return errorsmod.Wrapf(types.ErrValueIsNilOrZero, "Invalid SlashProportion; expected non-nil and non-negative, got: %+v", parameter.SlashProportion)

Likely invalid or redundant comment.


86-87: LGTM! Verify impact of moving from pointers to value types.

The change simplifies memory management and improves performance. Ensure related code handles these changes correctly.

Also applies to: 135-135

Verification successful

Change from pointers to value types is safe and effective.

The transition from pointers to value types for SlashUndelegations and SlashAssetsPool aligns with best practices and does not introduce issues in the codebase. The usages in the code are consistent with this change, ensuring correct handling.

  • x/operator/keeper/slash.go: Initialization and usage of SlashUndelegations and SlashAssetsPool.
  • x/operator/keeper/slash_test.go: Tests confirm correct behavior with value types.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of changing from pointers to value types in `SlashAssets`.

# Test: Search for usages of `SlashExecutionInfo` to ensure correct handling of value types.
rg --type go 'SlashExecutionInfo'

Length of output: 2975


Script:

#!/bin/bash
# Description: Search for usages of `SlashUndelegations` and `SlashAssetsPool` to verify correct handling of value types.

# Test: Search for `SlashUndelegations` usage in the codebase.
rg --type go 'SlashUndelegations'

# Test: Search for `SlashAssetsPool` usage in the codebase.
rg --type go 'SlashAssetsPool'

Length of output: 3512

app/test_helpers.go (4)

228-243: LGTM! Verify impact of AssetsByOperator structure changes.

The new structure enhances granularity and clarity in asset management. Ensure consistency with related code.

Verification successful

Verification Successful: AssetsByOperator Structure Changes are Consistent

The AssetsByOperator structure changes are consistently applied across the codebase, including protobuf definitions, genesis state handling, and asset management functions. No inconsistencies were found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of changes to `AssetsByOperator` structure.

# Test: Search for usages of `AssetsByOperator` to ensure consistency.
rg --type go 'AssetsByOperator'

Length of output: 3482


247-257: LGTM! Verify impact of OperatorDetail structure changes.

The updated structure provides a more detailed representation of operator data. Ensure consistency with related code.


276-283: LGTM! Verify impact of stakersByOperator structure changes.

The new structure provides a clearer mapping of asset delegations. Ensure consistency with related code.

Verification successful

Verification of stakersByOperator Structure Changes

The stakersByOperator structure is used consistently across multiple files, including for creating genesis states and validation functions. Ensure that all related logic is tested and validated for consistency.

  • Files to Review:
    • x/delegation/types/genesis_test.go
    • x/delegation/types/genesis.go
    • x/delegation/keeper/delegation_state.go
    • app/test_helpers.go
    • app/ethtest_helper.go

Please verify that all related tests pass successfully and consider edge cases that might not be covered.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of changes to `stakersByOperator` structure.

# Test: Search for usages of `stakersByOperator` to ensure consistency.
rg --type go 'stakersByOperator'

Length of output: 3489


260-266: LGTM! Verify impact of DelegationStates structure changes.

The new structure streamlines delegation management. Ensure consistency with related code.

proto/exocore/operator/v1/tx.proto (1)

172-174: LGTM! Verify impact of non-nullable repeated fields.

The change ensures non-null lists, enhancing data integrity. Verify the impact on serialization and deserialization processes.

Verification successful

Non-nullable fields in SlashExecutionInfo are properly handled in serialization.

The SlashExecutionInfo struct and its methods in tx.pb.go confirm that the non-nullable fields are integrated into the serialization and deserialization processes. This ensures data integrity without adverse effects.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of non-nullable repeated fields in `SlashExecutionInfo`.

# Test: Search for usages of `SlashExecutionInfo` to ensure correct handling of non-nullable fields.
rg --type proto 'SlashExecutionInfo'

Length of output: 66


Script:

#!/bin/bash
# Description: Locate `.proto` files and search for usages of `SlashExecutionInfo`.

# Find all `.proto` files and search for `SlashExecutionInfo` within them.
fd --extension proto --exec rg 'SlashExecutionInfo' {}

Length of output: 261


Script:

#!/bin/bash
# Description: Search for `SlashExecutionInfo` in non-proto files to gather more context about its usage and handling.

# Find all files except `.proto` and search for `SlashExecutionInfo` within them.
rg 'SlashExecutionInfo' --type-not proto

Length of output: 70


Script:

#!/bin/bash
# Description: Search for `SlashExecutionInfo` in all files except `.proto` to gather more context about its usage and handling.

# Find all files, excluding `.proto`, and search for `SlashExecutionInfo` within them.
rg 'SlashExecutionInfo' --glob '!*.proto'

Length of output: 2983

x/operator/keeper/usd_value.go (2)

254-269: LGTM!

The function GetAllOperatorUSDValues is implemented correctly and efficiently retrieves all operator USD values.


281-296: LGTM!

The function GetAllAVSUSDValues is implemented correctly and efficiently retrieves all AVS USD values.

x/delegation/types/genesis.go (5)

16-25: LGTM!

The function NewGenesis correctly initializes the GenesisState with the provided parameters, enhancing the genesis state initialization.


30-31: LGTM!

The function DefaultGenesis correctly returns a default genesis state using NewGenesis.


34-61: Refactor error handling for consistency and clarity.

The error messages in ValidateIDAndOperator could be improved for consistency and clarity. Consider using a uniform error prefix and providing more context in the messages.


180-212: LGTM!

The function ValidateAssociations is implemented correctly and performs necessary validation checks for associations.


214-254: LGTM!

The function ValidateDelegationStates is implemented correctly and performs necessary validation checks for delegation states.

x/assets/types/genesis_test.go (1)

29-30: LGTM!

The changes to the TestValidateGenesis function streamline the test setup by using nil for empty slices and adjusting staking amounts. Ensure that the removal of certain test cases does not overlook any critical validation scenarios.

testutil/utils.go (4)

136-165: Verify initialization values for TotalShare and OperatorShare.

Ensure that the values for TotalShare and OperatorShare are correctly calculated and initialized. This is crucial for accurate asset management and distribution.

Verification successful

Initialization values for TotalShare and OperatorShare are correct.

The values for TotalShare and OperatorShare in testutil/utils.go are initialized using sdk.NewDecFromBigInt(depositAmount.BigInt()), which aligns with the expected behavior observed in other parts of the codebase. No issues found with the initialization.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the initialization values for `TotalShare` and `OperatorShare`.

# Test: Check if the values are correctly calculated and initialized.
rg --type go 'TotalShare|OperatorShare' -A 5

Length of output: 19809


Line range hint 231-271: Verify transition to delegationStates.

Ensure that all references to delegationsByStaker have been updated to delegationStates for consistency in delegation management.

Verification successful

Transition to delegationStates Verified Successfully

The transition from delegationsByStaker to delegationStates is complete and consistent across the codebase. All references have been updated appropriately. No further action is needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify transition to `delegationStates`.

# Test: Search for any remaining instances of `delegationsByStaker`.
rg --type go 'delegationsByStaker'

Length of output: 34


Script:

#!/bin/bash
# Description: Verify usage of `delegationStates`.

# Test: Search for instances of `delegationStates` to ensure it's being used consistently.
rg --type go 'delegationStates'

Length of output: 3220


227-227: Verify operatorGenesis initialization.

Ensure that the operatorGenesis initialization is correct and aligns with the new operator structure.

Verification successful

Let's verify the definition of NewGenesisState in operatortypes to ensure that the operatorGenesis initialization is correct.


Initialization of operatorGenesis is correct.

The initialization of operatorGenesis with operatorInfos and nil values for other parameters aligns with the expected signature of NewGenesisState in operatortypes. This confirms the correctness of the initialization across the codebase.

  • x/operator/types/genesis.go: NewGenesisState function definition confirms the parameter structure.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify `operatorGenesis` initialization.

# Test: Check the initialization of `operatorGenesis`.
rg --type go 'operatorGenesis'

Length of output: 696


Script:

#!/bin/bash
# Locate the definition of `NewGenesisState` in `operatortypes`.
ast-grep --lang go --pattern 'func NewGenesisState($_, $$$) $_'

Length of output: 1215


271-271: Verify delegationGenesis initialization.

Ensure that the delegationGenesis initialization is correct and aligns with the new delegation structure.

Verification successful

Initialization of delegationGenesis is correct.

The delegationGenesis initialization aligns with the NewGenesis function definition in x/delegation/types/genesis.go. The use of nil for undelegations is appropriate given the function's parameters. No issues found with the current setup.

  • x/delegation/types/genesis.go: NewGenesis function definition confirms expected parameters.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify `delegationGenesis` initialization.

# Test: Check the initialization of `delegationGenesis`.
rg --type go 'delegationGenesis'

Length of output: 740


Script:

#!/bin/bash
# Description: Investigate `delegationtypes.NewGenesis` function to verify parameters.

# Locate the definition of the `NewGenesis` function in `delegationtypes`.
ast-grep --lang go --pattern 'func NewGenesis($_, $_, $_, $_) { $$$ }'

Length of output: 72


Script:

#!/bin/bash
# Description: Search for the definition of the `NewGenesis` function in the codebase.

# Use ripgrep to locate the `NewGenesis` function definition.
rg 'func NewGenesis' --type go -A 5

Length of output: 2559

x/delegation/keeper/delegation_state.go (2)

17-32: Handle potential errors from MustUnmarshal.

To avoid panics, consider handling errors from the MustUnmarshal method. This will enhance robustness and prevent crashes in production.

- k.cdc.MustUnmarshal(iterator.Value(), &stateInfo)
+ if err := k.cdc.Unmarshal(iterator.Value(), &stateInfo); err != nil {
+     return nil, err
+ }

Likely invalid or redundant comment.


54-54: Approve the change to key parsing method.

The change to ParseStakerAssetIDAndOperator improves key handling. Ensure consistent usage across the codebase.

Verification successful

Consistent Usage of Key Parsing Method Verified

The old parsing method ParseStakerAssetIDAndOperatorAddrFromKey is not present in the codebase, confirming that the transition to ParseStakerAssetIDAndOperator has been completed successfully. The new method is consistently used for key handling.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent usage of `ParseStakerAssetIDAndOperator`.

# Test: Search for any remaining instances of the old parsing method.
rg --type go 'ParseStakerAssetIDAndOperatorAddrFromKey'

Length of output: 55


Script:

#!/bin/bash
# Re-run the search for the old parsing method to confirm its absence.
rg --type go 'ParseStakerAssetIDAndOperatorAddrFromKey'

Length of output: 55

local_node.sh (4)

99-99: Approve change to staking_total_amount.

The change to "5000" reflects a new initial staking balance. Verify consistency with other configurations.

Verification successful

Change to staking_total_amount is consistent.

The staking_total_amount is only referenced in local_node.sh, where it is set to "5000". No inconsistencies found with other configurations in the shell scripts.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistency of `staking_total_amount` with other configurations.

# Test: Search for occurrences of `staking_total_amount` to ensure consistency.
rg --type sh 'staking_total_amount'

Length of output: 179


116-121: Approve restructuring of operator_info.

The encapsulation of attributes enhances clarity. Verify consistent usage of operator_info.

Verification successful

Consistent usage of operator_info verified.

The operator_info structure is used consistently in the local_node.sh file, ensuring clarity and organization of operator-related attributes. No discrepancies were found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent usage of `operator_info`.

# Test: Search for occurrences of `operator_info` to ensure consistency.
rg --type sh 'operator_info'

Length of output: 958


124-126: Approve changes to delegation_states.

The new format provides a clearer view of delegation status. Verify consistent usage of delegation_states.

Verification successful

Consistent usage of delegation_states confirmed.

The delegation_states changes are isolated to local_node.sh, and there are no inconsistencies found in its usage across other shell scripts.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent usage of `delegation_states`.

# Test: Search for occurrences of `delegation_states` to ensure consistency.
rg --type sh 'delegation_states'

Length of output: 646


105-110: Approve changes to operator_assets.

The new entries enhance clarity and organization. Verify that the new entries are correctly initialized.

x/operator/types/genesis.go (11)

13-28: LGTM: Expanded function signature.

The NewGenesisState function has been expanded to include additional fields, which enhances its functionality. The initialization logic is correct.


34-34: LGTM: Updated default genesis initialization.

The DefaultGenesis function correctly initializes the new fields with nil, ensuring compatibility with the expanded GenesisState.


Line range hint 40-108: LGTM: Comprehensive operator validation.

The ValidateOperators function effectively checks for duplicate addresses, correct formats, and valid commission structures. The error handling is well-implemented.


114-170: LGTM: Effective consensus key record validation.

The ValidateOperatorConsKeyRecords function correctly validates consensus key records, ensuring no duplicates and correct formats. The logic is clear and well-structured.


172-213: LGTM: Thorough opted states validation.

The ValidateOptedStates function ensures operators are registered and validates the sequence of opted-in and opted-out heights. The logic is robust and clear.


215-249: LGTM: Comprehensive AVS USD values validation.

The ValidateAVSUSDValues function effectively checks for valid AVS addresses and ensures that monetary values are non-negative. The logic is clear and well-implemented.


251-324: LGTM: Robust operator USD values validation.

The ValidateOperatorUSDValues function ensures consistency between operator and AVS USD values and checks for nil and negative fields. The logic is well-structured.


326-429: LGTM: Comprehensive slash states validation.

The ValidateSlashStates function effectively validates slashing information, ensuring correct operator registration and valid slashing proportions. The logic is robust and clear.


431-476: LGTM: Effective previous consensus keys validation.

The ValidatePrevConsKeys function ensures correct key decoding and operator registration, maintaining the integrity of consensus keys. The logic is sound.


478-514: LGTM: Robust operator key removals validation.

The ValidateOperatorKeyRemovals function ensures correct key decoding and operator registration, maintaining the integrity of key removals. The logic is clear and well-implemented.


518-550: LGTM: Comprehensive genesis state validation.

The Validate function orchestrates the validation of the genesis state, ensuring each component is thoroughly checked. The error handling is well-implemented.

x/assets/types/genesis.go (6)

11-14: LGTM: New type TotalSupplyAndStaking.

The introduction of TotalSupplyAndStaking enhances clarity and encapsulation for handling staking and supply values.


15-27: LGTM: Expanded function signature for NewGenesis.

The inclusion of operatorAssets in the NewGenesis function allows for a more comprehensive initialization of the genesis state.


41-67: LGTM: Generic validation with CommonValidation.

The CommonValidation function enhances code reusability and maintainability by providing a generic mechanism for validating slices and checking for duplicates.


69-105: LGTM: Effective client chains validation.

The ValidateClientChains function ensures correct formats and no duplicates, with comprehensive checks for valid names, IDs, and address lengths.


288-346: LGTM: Comprehensive operator assets validation.

The ValidateOperatorAssets function ensures operator assets are correctly registered and values are non-negative. The logic is clear and well-implemented.


350-368: LGTM: Comprehensive genesis state validation.

The Validate function orchestrates the validation of the genesis state, ensuring each component is thoroughly checked. The error handling is well-implemented.

cmd/exocored/testnet.go (2)

Line range hint 398-469: LGTM: Enhanced data handling in getTestExocoreGenesis.

The restructuring of getTestExocoreGenesis enhances clarity and functionality in managing operator and delegation information. The changes align with the new data model.


398-398: Ensure proper resource cleanup in initTestnetFiles.

The function involves file and directory operations. Ensure resources are properly cleaned up in error scenarios to prevent leaks. Consider using defer statements for cleanup.

- if err := os.RemoveAll(args.outputDir); err != nil {
+ defer func() {
+   if err := os.RemoveAll(args.outputDir); err != nil {
+     cmd.PrintErr("Failed to clean up resources:", err)
+   }
+ }()

Likely invalid or redundant comment.

x/operator/keeper/consensus_keys.go (1)

551-580: Verify robustness of error handling in GetAllOperatorConsKeyRecords.

Ensure that error handling for ParseKeyForOperatorAndChainIDToConsKey is robust, as any failure in parsing could disrupt the function's logic.

Verification successful

Error handling in GetAllOperatorConsKeyRecords is robust.

The function ParseKeyForOperatorAndChainIDToConsKey checks for missing addresses and invalid key lengths, returning meaningful errors. These are correctly handled in GetAllOperatorConsKeyRecords. No issues found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the robustness of error handling in `GetAllOperatorConsKeyRecords`.

# Test: Search for usage and error handling of `ParseKeyForOperatorAndChainIDToConsKey`.
rg --type go 'ParseKeyForOperatorAndChainIDToConsKey'

Length of output: 310


Script:

#!/bin/bash
# Extract the implementation of `ParseKeyForOperatorAndChainIDToConsKey` to verify error handling.
ast-grep --lang go --pattern 'func ParseKeyForOperatorAndChainIDToConsKey($_) ($_, $_, error) { $$$ }'

Length of output: 104


Script:

#!/bin/bash
# Attempt to extract the implementation of `ParseKeyForOperatorAndChainIDToConsKey` again with a refined pattern.
ast-grep --lang go --pattern 'func ParseKeyForOperatorAndChainIDToConsKey(key []byte) (sdk.AccAddress, string, error) { $$$ }'

Length of output: 128


Script:

#!/bin/bash
# Use ripgrep to search for the function definition of `ParseKeyForOperatorAndChainIDToConsKey`.
rg 'func ParseKeyForOperatorAndChainIDToConsKey' --type go -A 10

Length of output: 858

app/app.go (1)

Line range hint 259-259: Verify impact of removing bApp.CreateQueryContext from OperatorKeeper.

Ensure that the removal of bApp.CreateQueryContext does not negatively impact the application's functionality, particularly in how query contexts are managed.

Verification successful

No impact from removing bApp.CreateQueryContext from OperatorKeeper.

The removal of bApp.CreateQueryContext does not affect the application's functionality, as there are no active references or usages related to OperatorKeeper. The only mention is in a commented-out section of a test file.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of removing `bApp.CreateQueryContext` from `OperatorKeeper`.

# Test: Search for references to `CreateQueryContext` in the codebase to ensure its removal does not affect functionality.
rg --type go 'CreateQueryContext'

Length of output: 250


Script:

#!/bin/bash
# Description: Search for references to `CreateQueryContext` in relation to `OperatorKeeper`.

# Test: Search for `CreateQueryContext` usage in the context of `OperatorKeeper`.
rg --type go 'OperatorKeeper' -A 10 | rg 'CreateQueryContext'

Length of output: 174

x/delegation/keeper/un_delegation_state.go Show resolved Hide resolved
x/delegation/keeper/genesis.go Outdated Show resolved Hide resolved
x/operator/keeper/genesis.go Outdated Show resolved Hide resolved
x/delegation/keeper/genesis.go Outdated Show resolved Hide resolved
x/operator/keeper/usd_value.go Outdated Show resolved Hide resolved
x/operator/keeper/operator_slash_state.go Outdated Show resolved Hide resolved
x/assets/types/genesis.go Outdated Show resolved Hide resolved
x/assets/types/genesis.go Outdated Show resolved Hide resolved
x/delegation/keeper/delegation_state.go Show resolved Hide resolved
x/delegation/keeper/delegation_state.go Show resolved Hide resolved
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: 1

Outside diff range, codebase verification and nitpick comments (2)
x/assets/types/genesis.go (2)

41-68: Enhance readability with inline comments.

Consider adding more inline comments to explain the parameters seenFieldValue and validation for better code readability.

+ // seenFieldValue extracts a unique field and its associated data from the element.
+ // validation performs custom validation logic on the element.

289-347: Enhance readability with inline comments.

Consider adding more inline comments to explain the validation logic within the ValidateOperatorAssets function for better code readability.

+ // Validate the operator's address format.
+ // Ensure the sum of operator's amounts does not exceed the total staking amount.
+ // Check that the operator's share does not exceed the total share.
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ede2cba and cc6ba25.

Files selected for processing (4)
  • proto/exocore/delegation/v1/genesis.proto (2 hunks)
  • x/assets/types/genesis.go (5 hunks)
  • x/delegation/types/genesis.go (2 hunks)
  • x/operator/types/genesis.go (2 hunks)
Additional context used
GitHub Check: break-check
proto/exocore/delegation/v1/genesis.proto

[failure] 17-17:
Field "1" with name "associations" on message "GenesisState" changed option "json_name" from "delegations" to "associations".


[failure] 17-17:
Field "1" on message "GenesisState" changed type from "exocore.delegation.v1.DelegationsByStaker" to "exocore.delegation.v1.StakerToOperator".


[failure] 17-17:
Field "1" on message "GenesisState" changed name from "delegations" to "associations".


[failure] 19-19:
Field "2" with name "delegation_states" on message "GenesisState" changed option "json_name" from "associations" to "delegationStates".

Additional comments not posted (24)
proto/exocore/delegation/v1/genesis.proto (4)

28-34: New Message Structure Approved.

The DelegationStates message is well-defined and enhances the functionality of the GenesisState. Ensure that it is correctly utilized in the codebase.


36-43: New Message Structure Approved.

The StakersByOperator message is well-defined and enhances the functionality of the GenesisState. Ensure that it is correctly utilized in the codebase.


17-23: Ensure Compatibility with Previous Versions.

The GenesisState message has undergone significant changes, including renaming and reordering fields. It's crucial to ensure that these changes are compatible with previous versions of the protocol and that any necessary migrations are handled appropriately.

Tools
GitHub Check: break-check

[failure] 17-17:
Field "1" with name "associations" on message "GenesisState" changed option "json_name" from "delegations" to "associations".


[failure] 17-17:
Field "1" on message "GenesisState" changed type from "exocore.delegation.v1.DelegationsByStaker" to "exocore.delegation.v1.StakerToOperator".


[failure] 17-17:
Field "1" on message "GenesisState" changed name from "delegations" to "associations".


[failure] 19-19:
Field "2" with name "delegation_states" on message "GenesisState" changed option "json_name" from "associations" to "delegationStates".


17-17: Verify Field Name and Type Changes.

The field associations in GenesisState has changed its name and type from delegations to associations. Ensure that these changes are correctly reflected throughout the codebase and that any dependent code is updated accordingly.

Tools
GitHub Check: break-check

[failure] 17-17:
Field "1" with name "associations" on message "GenesisState" changed option "json_name" from "delegations" to "associations".


[failure] 17-17:
Field "1" on message "GenesisState" changed type from "exocore.delegation.v1.DelegationsByStaker" to "exocore.delegation.v1.StakerToOperator".


[failure] 17-17:
Field "1" on message "GenesisState" changed name from "delegations" to "associations".

x/delegation/types/genesis.go (7)

13-25: Enhanced Initialization Approved.

The NewGenesis function now accepts additional parameters, enhancing the initialization of the GenesisState. Ensure these parameters are correctly integrated into the rest of the codebase.


31-31: Default Genesis State Updated.

The DefaultGenesis function has been updated to accommodate new parameters, ensuring compatibility with the updated GenesisState.


180-212: Association Validation Approved.

The ValidateAssociations function effectively checks for duplicate staker IDs and valid operator addresses, ensuring data integrity.


214-254: Delegation State Validation Approved.

The ValidateDelegationStates function ensures the integrity of delegation states by checking for nil and negative values.


256-311: Staker List Validation Approved.

The ValidateStakerList function effectively validates operator addresses and asset IDs, ensuring data consistency.


313-361: Undelegation Validation Approved.

The ValidateUndelegations function includes comprehensive checks for transaction hashes and logical consistency, enhancing data integrity.


Line range hint 363-550:
Comprehensive Validation Approved.

The Validate function orchestrates multiple specific validation functions, ensuring a comprehensive and error-resistant initialization of the GenesisState.

x/operator/types/genesis.go (10)

13-28: Enhanced Genesis State Initialization Approved.

The NewGenesisState function now includes additional parameters, enhancing the functionality of the GenesisState to encompass a broader range of operational data.


34-34: Default Genesis State Updated.

The DefaultGenesis function has been updated to accommodate new parameters, ensuring compatibility with the updated GenesisState.


Line range hint 37-108:
Operator Validation Approved.

The ValidateOperators function includes comprehensive validation checks, ensuring that operator addresses are valid and free of duplicates.


110-170: Consensus Key Record Validation Approved.

The ValidateOperatorConsKeyRecords function effectively validates operator consensus key records, ensuring data integrity.


172-213: Opted State Validation Approved.

The ValidateOptedStates function ensures that operators are registered and checks the consistency of opted-in and opted-out heights.


215-249: AVS USD Value Validation Approved.

The ValidateAVSUSDValues function checks for valid AVS addresses and ensures that values are not nil or negative, enhancing data integrity.


251-324: Operator USD Value Validation Approved.

The ValidateOperatorUSDValues function ensures that values are not nil or negative and checks for consistency with AVS USD values.


326-429: Slashing State Validation Approved.

The ValidateSlashStates function includes comprehensive checks for logical consistency and valid slashing proportions, enhancing data integrity.


431-476: Previous Consensus Key Validation Approved.

The ValidatePrevConsKeys function effectively validates previous consensus keys, ensuring data integrity.


478-514: Operator Key Removal Validation Approved.

The ValidateOperatorKeyRemovals function ensures that keys are correctly decoded and operators are registered, enhancing data integrity.

x/assets/types/genesis.go (3)

11-14: LGTM: New type TotalSupplyAndStaking.

The introduction of the TotalSupplyAndStaking type is clear and enhances data encapsulation for staking and supply values.


15-27: LGTM: Updated NewGenesis function.

The addition of operatorAssets to the NewGenesis function is appropriate and aligns with the PR's objectives to support genesis exporting.


348-369: LGTM: Refactored Validate function.

The refactor of the Validate function enhances the robustness and clarity of the genesis state validation process.

x/delegation/types/genesis.go Outdated Show resolved Hide resolved
@mikebraver mikebraver changed the title [feat] genesis exporting for assets, delegation and operator modules. feat(genesis export) genesis exporting for assets, delegation and operator modules. Aug 15, 2024
@mikebraver mikebraver changed the title feat(genesis export) genesis exporting for assets, delegation and operator modules. feat(genesis export): genesis exporting for assets, delegation and operator modules. Aug 16, 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.

Actionable comments posted: 10

Outside diff range, codebase verification and nitpick comments (4)
x/delegation/types/errors.go (1)

83-86: Clarify Error Message for Better Understandability

The error message "the block height to complete the unelegation is invalid" could be more descriptive. Consider specifying what makes the block height invalid.

- "the block height to complete the unelegation is invalid",
+ "the block height to complete the unelegation is invalid: must be greater than the current height",
x/operator/keeper/operator_info_test.go (1)

25-26: LGTM, but consider removing the print statement.

The code changes are approved. The print statement at line 26 is used for debugging purposes. Consider removing it before merging the PR.

Apply this diff to remove the print statement:

-	fmt.Println("the acc address length is:", len(suite.AccAddress))
x/delegation/keeper/un_delegation_state.go (1)

16-27: Consider adding error handling for unmarshalling.

While the MustUnmarshal function is used for simplicity, it might be beneficial to handle potential errors explicitly to improve robustness.

for ; iterator.Valid(); iterator.Next() {
	var undelegation types.UndelegationRecord
	err := k.cdc.Unmarshal(iterator.Value(), &undelegation)
	if err != nil {
		return nil, err
	}
	ret = append(ret, undelegation)
}
app/test_helpers.go (1)

276-283: Clarify the purpose and usage of the stakersByOperator data structure.

Please provide more context on how this new data structure is intended to be used within the delegation management functionality. Explain how it improves the efficiency or simplifies the logic of associating stakers with operators.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cc6ba25 and 45160c0.

Files ignored due to path filters (8)
  • x/assets/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/assets/types/query.pb.go is excluded by !**/*.pb.go
  • x/assets/types/tx.pb.go is excluded by !**/*.pb.go
  • x/delegation/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/delegation/types/types/query.pb.go is excluded by !**/*.pb.go
  • x/delegation/types/types/query.pb.gw.go is excluded by !**/*.pb.gw.go
  • x/operator/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/operator/types/tx.pb.go is excluded by !**/*.pb.go
Files selected for processing (51)
  • app/app.go (1 hunks)
  • app/ethtest_helper.go (4 hunks)
  • app/test_helpers.go (3 hunks)
  • cmd/exocored/root.go (4 hunks)
  • cmd/exocored/testnet.go (3 hunks)
  • local_node.sh (1 hunks)
  • precompiles/assets/tx.go (1 hunks)
  • precompiles/avs/query_test.go (2 hunks)
  • proto/exocore/assets/v1/genesis.proto (3 hunks)
  • proto/exocore/assets/v1/query.proto (4 hunks)
  • proto/exocore/assets/v1/tx.proto (2 hunks)
  • proto/exocore/delegation/v1/genesis.proto (2 hunks)
  • proto/exocore/operator/v1/genesis.proto (1 hunks)
  • proto/exocore/operator/v1/tx.proto (1 hunks)
  • testutil/utils.go (3 hunks)
  • x/assets/keeper/client_chain_and_asset_test.go (1 hunks)
  • x/assets/keeper/client_chain_asset.go (2 hunks)
  • x/assets/keeper/genesis.go (2 hunks)
  • x/assets/keeper/keeper.go (1 hunks)
  • x/assets/keeper/operator_asset.go (1 hunks)
  • x/assets/keeper/staker_asset.go (2 hunks)
  • x/assets/keeper/staker_asset_test.go (1 hunks)
  • x/assets/types/errors.go (1 hunks)
  • x/assets/types/genesis.go (5 hunks)
  • x/assets/types/genesis_test.go (5 hunks)
  • x/assets/types/keys.go (2 hunks)
  • x/delegation/keeper/delegation.go (2 hunks)
  • x/delegation/keeper/delegation_state.go (5 hunks)
  • x/delegation/keeper/genesis.go (2 hunks)
  • x/delegation/keeper/un_delegation_state.go (1 hunks)
  • x/delegation/types/errors.go (1 hunks)
  • x/delegation/types/genesis.go (2 hunks)
  • x/delegation/types/genesis_test.go (3 hunks)
  • x/delegation/types/keys.go (1 hunks)
  • x/operator/client/cli/tx.go (3 hunks)
  • x/operator/keeper/consensus_keys.go (2 hunks)
  • x/operator/keeper/genesis.go (1 hunks)
  • x/operator/keeper/keeper.go (3 hunks)
  • x/operator/keeper/operator.go (3 hunks)
  • x/operator/keeper/operator_info_test.go (3 hunks)
  • x/operator/keeper/operator_slash_state.go (1 hunks)
  • x/operator/keeper/slash.go (4 hunks)
  • x/operator/keeper/slash_test.go (1 hunks)
  • x/operator/keeper/usd_value.go (11 hunks)
  • x/operator/keeper/usd_value_test.go (2 hunks)
  • x/operator/types/expected_keepers.go (1 hunks)
  • x/operator/types/genesis.go (2 hunks)
  • x/operator/types/genesis_test.go (6 hunks)
  • x/operator/types/keys.go (5 hunks)
  • x/reward/keeper/claim_reward_test.go (1 hunks)
  • x/slash/keeper/execute_slash_test.go (1 hunks)
Files skipped from review due to trivial changes (2)
  • cmd/exocored/root.go
  • x/delegation/types/keys.go
Additional context used
Learnings (1)
x/delegation/keeper/un_delegation_state.go (1)
Learnt from: MaxMustermann2
PR: ExocoreNetwork/exocore#95
File: x/dogfood/keeper/unbonding.go:91-116
Timestamp: 2024-06-12T04:29:35.064Z
Learning: The `GetAllUndelegationsToMature` function in `x/dogfood/keeper/unbonding.go` uses an iterator that processes one record per iteration, and the record keys are stored efficiently as a key-value pair with the key being a prefix + big-endian epoch. This storage pattern provides direct and efficient access to the data.
buf
proto/exocore/delegation/v1/genesis.proto

5-5: import "exocore/delegation/v1/query.proto": file does not exist

(COMPILE)

proto/exocore/assets/v1/genesis.proto

4-4: import "cosmos_proto/cosmos.proto": file does not exist

(COMPILE)

GitHub Check: break-check
proto/exocore/delegation/v1/genesis.proto

[failure] 17-17:
Field "1" with name "associations" on message "GenesisState" changed option "json_name" from "delegations" to "associations".


[failure] 17-17:
Field "1" on message "GenesisState" changed type from "exocore.delegation.v1.DelegationsByStaker" to "exocore.delegation.v1.StakerToOperator".


[failure] 17-17:
Field "1" on message "GenesisState" changed name from "delegations" to "associations".


[failure] 19-19:
Field "2" with name "delegation_states" on message "GenesisState" changed option "json_name" from "associations" to "delegationStates".

proto/exocore/assets/v1/query.proto

[failure] 48-48:
Field "1" on message "QueryAllStakingAssetsInfoResponse" changed type from "exocore.assets.v1.QueryAllStakingAssetsInfoResponse.AllStakingAssetsInfoEntry" to "exocore.assets.v1.StakingAssetInfo".


[failure] 60-60:
Field "1" on message "QueryAssetInfoResponse" changed type from "exocore.assets.v1.QueryAssetInfoResponse.AssetInfosEntry" to "exocore.assets.v1.DepositByAsset".


[failure] 80-80:
Field "1" on message "QueryOperatorAssetInfosResponse" changed type from "exocore.assets.v1.QueryOperatorAssetInfosResponse.AssetInfosEntry" to "exocore.assets.v1.AssetByID".

Additional comments not posted (143)
x/assets/keeper/client_chain_and_asset_test.go (5)

29-30: LGTM!

The code changes are approved.


37-37: Verify the impact of adding the nil parameter.

Ensure that adding the nil parameter to the NewGenesis function call doesn't introduce any issues or unintended side effects.


43-43: Verify the test coverage.

Ensure that replacing the loop with a single assertion doesn't reduce the test coverage. Consider adding more assertions to cover all the client chains if necessary.


47-47: LGTM!

The code changes are approved.


52-52: Verify the test coverage.

Ensure that replacing the loop with a single assertion doesn't reduce the test coverage. Consider adding more assertions to cover all the assets if necessary.

x/assets/types/errors.go (1)

95-98: LGTM!

The new error declaration ErrParseJoinedKey is well-defined and follows the existing pattern in the file. The error message is clear and descriptive, and the error identifier is unique and incremental. This addition enhances the error handling capabilities of the module by providing a specific error for cases where parsing a joined key fails.

x/delegation/keeper/genesis.go (3)

34-47: Enhance error handling in InitGenesis.

The current implementation panics on error. Consider logging the error before panicking to provide more context for debugging.

- panic(err)
+ // Log the error before panicking
+ ctx.Logger().Error("Error initializing genesis", "err", err) 
+ panic(err)

52-52: LGTM!

The code change is approved.


53-77: Review error handling in ExportGenesis.

Similar to InitGenesis, consider logging errors before panicking to aid in debugging and provide more context.

- panic(err)
+ // Log the error before panicking
+ ctx.Logger().Error("Error exporting genesis", "err", err)
+ panic(err) 
x/assets/keeper/keeper.go (3)

50-50: LGTM!

The change from map to slice for the return type of GetAllStakingAssetsInfo is approved. It simplifies the return type and aligns with the other changes in the interface.


52-52: LGTM!

The change from map to slice for the return type of GetStakerAssetInfos is approved. It simplifies the return type and aligns with the other changes in the interface.


56-56: The existing comment is still valid and applicable to this change:

Proper integration of isGeneralInit flag, but consider alternative approaches for passing flags.

The addition of the isGeneralInit flag is well-documented. However, passing such flags through the context or command line as noted might be limiting. Consider using a configuration file or environment variables for greater flexibility and separation of concerns.

x/slash/keeper/execute_slash_test.go (1)

69-69: Use assets[assetID] instead of assets[0] to maintain the test's validity.

The change in the index used to access the assets slice is concerning because:

  • It makes the test dependent on the specific asset at index 0 rather than the asset corresponding to assetID.
  • It may no longer accurately reflect the intended behavior of the function being tested if assets[0] does not represent the same asset as assets[assetID].

To maintain the test's validity, use the original index assets[assetID] instead of assets[0]:

- suite.Equal(assets[0].StakingTotalAmount.Add(depositEvent.OpAmount).Sub(event.OpAmount), assetInfo.StakingTotalAmount)
+ suite.Equal(assets[assetID].StakingTotalAmount.Add(depositEvent.OpAmount).Sub(event.OpAmount), assetInfo.StakingTotalAmount)
proto/exocore/delegation/v1/genesis.proto (4)

19-19: LGTM!

The addition of the delegation_states field to the GenesisState message looks good. It seems to be part of the effort to improve the representation of delegation states in the genesis state.

Tools
GitHub Check: break-check

[failure] 19-19:
Field "2" with name "delegation_states" on message "GenesisState" changed option "json_name" from "associations" to "delegationStates".


28-34: LGTM!

The new DelegationStates message looks good. It seems to be a helper struct used to construct the genesis state and improve the representation of delegation states. The fields in the message are appropriately named and typed.


38-43: LGTM!

The new StakersByOperator message looks good. It seems to be a helper struct used to construct the genesis state and maintain a list of stakers associated with a specific operator. The fields in the message are appropriately named and typed.


17-17: Verify the impact of the breaking changes to the associations field.

The changes to the associations field in the GenesisState message are breaking changes as they modify the field name, type, and position. Please ensure that all the code that depends on this field is updated to reflect these changes.

Run the following script to find all the occurrences of the old field name and type in the codebase:

If you need help updating the affected code, please let me know and I'll be happy to assist you.

Tools
GitHub Check: break-check

[failure] 17-17:
Field "1" with name "associations" on message "GenesisState" changed option "json_name" from "delegations" to "associations".


[failure] 17-17:
Field "1" on message "GenesisState" changed type from "exocore.delegation.v1.DelegationsByStaker" to "exocore.delegation.v1.StakerToOperator".


[failure] 17-17:
Field "1" on message "GenesisState" changed name from "delegations" to "associations".

x/assets/keeper/genesis.go (3)

Line range hint 29-46: LGTM!

The code changes are approved. The loop correctly processes the deposits and updates the staker asset state. The comments provide a clear explanation, and the error handling is consistent with the existing code.


48-59: LGTM!

The code changes are approved. The nested loop correctly processes the operator assets and updates the operator asset state. The error handling is consistent with the existing code, and the #nosec G703 comment indicates that the Bech32 address has already been validated.


62-92: LGTM!

The code changes are approved. The ExportGenesis method correctly retrieves the necessary state information and populates the GenesisState structure. The error handling is consistent with the existing code, and the changes align with the updated function signature that now includes the context parameter.

x/operator/keeper/genesis.go (2)

12-53: ** Improve error handling in InitGenesis.**

The changes enhance the initialization logic by ensuring the earnings address is always populated and setting operator consensus keys for each chain. However, the function continues to panic on errors, which is not ideal for initialization logic.

As suggested in the previous review, consider returning errors and handling them gracefully at a higher level, especially in initialization logic where recovery might be preferred over termination.

- panic(err)
+ return err

57-103: ** Enhance error handling in ExportGenesis.**

The changes improve the export process by providing a more detailed export of the state. The function now constructs a GenesisState object that includes various elements such as operators, operator records, opted information, etc., retrieved through dedicated getter methods. This ensures that the exported state reflects the current state of the system accurately.

However, as pointed out in the previous review, the function continues to panic on errors, which is not ideal for export logic. Consider returning errors and handling them gracefully at a higher level, especially in export logic where recovery might be preferred over termination.

- panic(err)
+ return nil, err
x/operator/keeper/keeper.go (2)

16-17: LGTM!

The removal of the unused historicalCtx field simplifies the Keeper struct without affecting its core functionality.


Line range hint 30-36: LGTM!

The removal of the unused historicalCtx parameter simplifies the instantiation of the Keeper without affecting its core functionality.

x/operator/keeper/operator_info_test.go (1)

37-49: LGTM!

The code changes are approved. The usage of OperatorDetail struct aligns with the changes made to the OperatorInfo struct.

proto/exocore/assets/v1/genesis.proto (5)

7-7: LGTM!

The code changes are approved.


30-34: Address the previous review comment.

The previous review comment on this code segment is still valid and applicable.


36-45: LGTM!

The code changes are approved.


47-54: LGTM!

The code changes are approved.


Line range hint 61-76: LGTM!

The code changes are approved.

x/assets/keeper/client_chain_asset.go (2)

46-48: LGTM!

The new validation check for ensuring non-negative StakingTotalAmount is correctly implemented. It enhances the robustness of the function by preventing invalid staking amounts from being processed.


94-103: LGTM!

The changes to simplify the return type and internal logic of GetAllStakingAssetsInfo are correctly implemented. Using a slice instead of a map may improve performance and memory usage in scenarios where the number of assets is large.

The existing review comments suggesting error handling for corrupted data entries and ensuring test coverage for edge cases are still valid and applicable to the current implementation. Please address these suggestions.

x/assets/keeper/staker_asset.go (2)

15-45: LGTM!

The code changes are approved.


Line range hint 47-66: LGTM!

The code changes are approved.

x/operator/keeper/slash_test.go (2)

75-75: LGTM!

The code change is approved.


79-79: LGTM!

The code change is approved.

precompiles/assets/tx.go (1)

146-146: LGTM!

The code change is correct. Directly assigning the asset variable to the AssetBasicInfo field is the right approach since AssetBasicInfo is not a pointer field within the StakingAssetInfo struct.

x/assets/types/keys.go (2)

94-96: LGTM!

The code changes are approved.


102-102: LGTM!

The code changes are approved.

x/operator/types/expected_keepers.go (1)

28-28: The existing review comment is still valid and applicable to the current code segment. Skipping the generation of a similar comment.

x/assets/keeper/staker_asset_test.go (1)

88-116: LGTM!

The code changes in the TestGetStakerAssetInfos function are approved for the following reasons:

  1. The addition of the WaitUnbondingAmount field to the DeltaStakerSingleAsset struct expands the asset state representation to track unbonding amounts consistently across both asset types used in the test.

  2. The replacement of assetsInfo with getAssetsInfo when retrieving the staker asset information does not introduce any issues and suggests a shift in how the retrieved asset information is referenced in the assertions.

  3. The use of the Contains method in the assertions streamlines the test's readability by focusing on the presence of the expected data rather than its specific structure, improving the test's maintainability.

x/operator/types/genesis_test.go (6)

27-29: LGTM!

The code changes for generating keys and account addresses for testing are approved.


Line range hint 51-57: LGTM!

The test case for validating an invalid genesis state due to a non-bech32 operator address is approved.


Line range hint 62-72: LGTM!

The test case for validating an invalid genesis state due to a duplicate operator address is approved.


Line range hint 76-97: LGTM!

The test case for validating an invalid genesis state due to a duplicate lz chain id is approved.


99-220: LGTM!

The test cases for validating various invalid genesis states due to issues with the operator consensus key records are approved. The test cases cover the following scenarios:

  • Invalid consensus key operator address.
  • Unregistered operator in consensus key.
  • Duplicate operator in consensus key.
  • Invalid consensus key.
  • Duplicate consensus key for the same chain id.

These test cases enhance the robustness of the validation logic by ensuring that the genesis state adheres to stricter criteria, thereby improving the overall integrity of the system.


4-6: LGTM!

The remaining code changes related to importing packages and updating the OperatorInfo struct to OperatorDetail struct are approved. The changes are consistent with the alterations to the declarations of exported or public entities and are necessary for the new test cases and the overall functionality.

Also applies to: 27-29, 51-57, 62-72, 76-97, 99-220

x/assets/keeper/operator_asset.go (1)

Line range hint 46-59: LGTM!

The code changes are approved. The change in the return type from a map to a slice enhances the method's functionality by providing a more straightforward representation of the assets associated with an operator.

x/delegation/types/genesis_test.go (5)

33-42: LGTM!

The code changes are approved.


43-50: LGTM!

The code changes are approved.


70-70: LGTM!

The code changes are approved.


75-83: LGTM!

The code changes are approved.


86-95: LGTM!

The code changes are approved.

proto/exocore/assets/v1/query.proto (1)

7-7: New import statement for genesis.proto.

The addition of the genesis.proto import statement suggests that the changes in the data structures might be related to the genesis state of the assets, as mentioned in the AI-generated summary.

Could you provide more context on how the changes in the data structures are related to the genesis state? This would help in understanding the overall impact of the changes.

x/operator/keeper/usd_value_test.go (2)

77-77: LGTM!

The code change is approved as it simplifies the data structure usage by eliminating the pointer dereference, aligning with the overall approach to favor direct value references over pointers.


135-135: LGTM!

The code change is approved as it enhances readability and reduces the risk of nil pointer dereference errors, aligning with the overall approach to favor direct value references over pointers.

x/operator/types/keys.go (2)

31-33: LGTM!

The code changes are approved.


41-42: LGTM!

The code changes are approved.

Also applies to: 77-83

x/operator/client/cli/tx.go (4)

22-22: LGTM!

The new constant FlagEarningAddr is defined correctly and has a clear name.


79-82: LGTM!

The new flag FlagEarningAddr is defined correctly and has a clear description. It enhances the flexibility of the operator registration process by allowing operators to specify a distinct earning address.


118-122: LGTM!

The logic for setting the EarningsAddr has been updated correctly to use the value from the FlagEarningAddr instead of defaulting to the sender's address. This change ensures that the operator can explicitly define where their rewards should be sent, improving the functionality of the operator registration process.


127-127: LGTM!

The EarningsAddr field in the OperatorInfo struct is set correctly to the value of earningAddr. This change is consistent with the updated logic in the newBuildRegisterOperatorMsg function.

x/operator/keeper/operator_slash_state.go (2)

159-167: The past review comment is still valid.

The existing review comment suggesting to ensure atomicity by wrapping the loop in a transaction is still applicable to the current implementation.


169-184: The past review comment is still valid.

The existing review comment suggesting to optimize the retrieval logic if performance becomes an issue is still applicable to the current implementation.

x/operator/keeper/operator.go (3)

76-89: LGTM!

The code changes are approved. The modifications to the AllOperators method enhance its functionality by returning detailed operator information, improving usability for clients.


205-220: LGTM!

The code changes are approved. The new GetAllOptedInfo method provides a useful functionality to retrieve all opted states from the store, which can be beneficial for querying or processing opted states in bulk. The implementation follows the expected logic and looks good.


25-25: Verify the validation of the addr parameter.

Ensure that the addr parameter is properly validated before using it to derive the opAccAddr. If the validation is missing, it could lead to invalid addresses being accepted.

proto/exocore/operator/v1/genesis.proto (7)

20-24: LGTM!

The code changes are approved.


26-26: LGTM!

The code changes are approved.


28-31: LGTM!

The code changes are approved.


33-36: LGTM!

The code changes are approved.


38-38: LGTM!

The code changes are approved.


40-40: LGTM!

The code changes are approved.


43-43: LGTM!

The code changes are approved.

app/ethtest_helper.go (5)

192-193: LGTM!

The code changes are approved. Directly referencing the asset instead of using a pointer simplifies the initialization and improves readability.


195-195: LGTM!

The code changes are approved. The new StakingTotalAmount field provides useful information about the asset's staking state, and the initialization with depositAmount seems appropriate.


206-216: LGTM!

The code changes are approved. The new OperatorDetail struct and the nested OperatorInfo struct provide a clearer organization of the operator-related data in the genesis state. This restructuring enhances the clarity and maintainability of the code.


Line range hint 219-243: LGTM!

The code changes are approved. The modifications to the delegation handling in the genesis state introduce several improvements:

  1. The new delegationStates structure provides a more nuanced approach to managing delegation states by including fields for wait undelegation amount and undelegatable share.
  2. The change in the delegation key to a string representation of a joined store key suggests an optimization in how delegation data is indexed.
  3. The introduction of the stakersByOperator array enhances the organization by mapping operators to their respective stakers.

These changes reflect enhancements in the data organization and logic flow within the delegation genesis state initialization, leading to improved clarity and maintainability.


252-252: LGTM!

The code changes are approved. The modification to the OperatorAccAddr field in the GenesisValidator struct aligns it with the new OperatorDetail structure introduced earlier. By referencing the OperatorAddress instead of the EarningsAddr, the code ensures consistency with the updated operator data organization. This change is a necessary adaptation to the modifications made in the operator module's genesis state initialization.

x/delegation/keeper/delegation.go (1)

Line range hint 129-141: LGTM!

The code changes are approved for the following reasons:

  • The change from pointer type to value type for UndelegationRecord instantiation is a good practice as it avoids unnecessary memory allocation and simplifies the code.
  • The change in the argument type passed to SetUndelegationRecords is consistent with the change in the UndelegationRecord instantiation.
  • There are no apparent issues or side effects caused by these changes.
x/delegation/keeper/un_delegation_state.go (2)

16-27: LGTM!

The code changes are approved.


32-41: LGTM!

The code changes are approved.

precompiles/avs/query_test.go (2)

158-158: LGTM!

The code change is correct. The AssetBasicInfo field should be assigned the AssetInfo value directly, not a pointer to it.


247-247: LGTM!

The code change is correct for the same reason as the previous one.

proto/exocore/assets/v1/tx.proto (2)

73-73: LGTM!

The addition of the (gogoproto.nullable) = false option to the asset_basic_info field is a good change. It enforces that the AssetInfo must always be present when creating a StakingAssetInfo instance, enhancing data integrity.


120-121: LGTM!

The expanded comment for the total_amount field is a good change. It clarifies that the total amount of the asset deposited excludes the wait_unbonding_amount, improving the documentation and understanding of the field's purpose.

x/operator/keeper/slash.go (4)

50-50: LGTM!

The code change is approved.


86-87: LGTM!

The code change is approved. Initializing SlashUndelegations and SlashAssetsPool fields as slices instead of pointers simplifies the data structure management and aligns with the updated struct definition.


95-95: LGTM!

The code change is approved. Appending the dereferenced value of slashFromUndelegation to executionInfo.SlashUndelegations slice aligns with the new structure definition and streamlines the code.


135-138: LGTM!

The code change is approved. Appending a SlashFromAssetsPool instance to executionInfo.SlashAssetsPool slice using value types aligns with the new structure definition and streamlines the code.

app/test_helpers.go (5)

228-243: LGTM!

The code changes for initializing the AssetsByOperator field in the assets genesis state are approved.


284-284: LGTM!

The code changes for initializing the delegation genesis state with the updated data structures are approved.


260-269: Verify the consistency of the delegationStates change across the codebase.

Ensure that the shift from delegationsByStaker to delegationStates and the new key-value pairing approach is consistently applied across the codebase. Verify that it does not introduce any bugs or unintended behavior in the delegation management functionality.

Verification successful

The transition to delegationStates is consistently applied across the codebase.

The delegationStates is used in multiple files, and there is no occurrence of delegationsByStaker, indicating a complete transition. This change appears to be well-integrated and tested within the codebase.

  • Files with delegationStates usage include genesis.pb.go, genesis.go, genesis_test.go, delegation_state.go, utils.go, ethtest_helper.go, and testnet.go.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `delegationStates` and `DelegationStates` type.
# Expect: Consistent usage of `delegationStates` and no usage of `delegationsByStaker`.

# Search for usage of `delegationStates`
rg --type go --glob '!test_helpers.go' $'delegationStates'

# Search for usage of `delegationsByStaker`  
rg --type go --glob '!test_helpers.go' $'delegationsByStaker'

Length of output: 3105


247-257: Verify the impact of changing the operatorInfos type and nesting the OperatorInfo struct.

Ensure that this structural change is consistently applied across the codebase and does not break any existing functionality related to operator information handling.


223-223: Verify the impact of changing from a pointer to a direct reference for the asset information.

Ensure that this change does not introduce any unintended side effects or bugs in how the asset data is accessed and manipulated within the function and other parts of the codebase that interact with this genesis state.

Verification successful

Verification successful: No pointer-specific operations found for AssetBasicInfo.

The change from a pointer to a direct reference for AssetBasicInfo does not introduce any unintended side effects or bugs related to pointer manipulation in the codebase. The usage of AssetBasicInfo is consistent with the change.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `AssetBasicInfo` field. 
# Expect: No dereferences using `&` operator.

# Search for pointer dereferences of `AssetBasicInfo` field
rg --type go --glob '!test_helpers.go' $'AssetBasicInfo: \&'

Length of output: 61


Script:

#!/bin/bash
# Description: Verify the usage of `AssetBasicInfo` field for any pointer-specific operations.
# Expect: No pointer-specific operations like dereferencing.

# Search for any pointer-specific operations on `AssetBasicInfo`
rg --type go --glob '!test_helpers.go' 'AssetBasicInfo\.\*'

Length of output: 61

proto/exocore/operator/v1/tx.proto (2)

172-172: LGTM!

The change to enforce non-null slash_undelegations field is approved.


174-174: LGTM!

The change to enforce non-null slash_assets_pool field is approved.

x/delegation/types/genesis.go (7)

15-25: LGTM!

The changes to the NewGenesis function are approved. The addition of new parameters and their inclusion in the returned GenesisState enhance the function's capability to initialize the genesis state with more comprehensive data.


30-31: LGTM!

The changes to the DefaultGenesis function are approved. Calling NewGenesis with nil values for the new parameters ensures that the function can still return a valid genesis state even when no specific data is provided.


180-212: LGTM!

The new ValidateAssociations method is approved. It enhances the validation logic for the Associations field by checking for duplicate staker IDs and validating operator addresses.


214-254: LGTM!

The new ValidateDelegationStates method is approved. It enhances the validation logic for the DelegationStates field by ensuring that delegation states are not nil and do not contain negative values.


256-311: LGTM!

The new ValidateStakerList method is approved. It enhances the validation logic for the StakersByOperator field by validating the operator address, asset ID, and the list of stakers for each operator.


313-361: LGTM!

The new ValidateUndelegations method is approved. It enhances the validation logic for the Undelegations field by validating the staker ID, asset ID, operator address, transaction hash, and other fields of each undelegation record.


365-382: LGTM!

The changes to the Validate method are approved. Calling the new validation functions centralizes the validation process and improves code organization.

x/assets/types/genesis_test.go (1)

29-30: LGTM!

The changes to the TestValidateGenesis function look good:

  • Simplifying the NewGenesis function call by using nil values for slices.
  • Updating the StakingTotalAmount to a non-zero value for testing.
  • Removing some test cases that are no longer relevant.

The test cases cover a wide range of scenarios to ensure the robustness of the genesis validation logic.

Also applies to: 54-55

testutil/utils.go (5)

136-165: LGTM!

The initialization of operatorAssets with detailed information for each operator's assets looks good. It provides a more granular representation and improves clarity.


166-174: Approved.

The initialization of assetsGenesis with the updated operatorAssets and total staking amounts looks good.


204-219: Looks good!

The initialization of operatorInfos using the new OperatorDetail structure enhances the encapsulation of operator-related data. The changes are implemented correctly.


231-245: Approved.

The initialization of delegationStates with detailed information for each delegation looks good. The changes provide a more refined representation and improve the overall organization of delegation data.


257-271: LGTM!

The initialization of stakersByOperator with a mapping of operators to their respective stakers enhances the organization of delegation data. The delegationGenesis is properly initialized with the updated structures.

x/delegation/keeper/delegation_state.go (3)

383-396: LGTM!

The code changes are approved.


296-304: Handle potential errors from MustMarshal.

To prevent data corruption or crashes, handle errors during the marshalling process.

- bz := k.cdc.MustMarshal(&delegationtype.StakerList{Stakers: singleElement.Stakers})
+ bz, err := k.cdc.Marshal(&delegationtype.StakerList{Stakers: singleElement.Stakers})
+ if err != nil {
+     return err
+ }

Likely invalid or redundant comment.


34-42: Handle potential errors from MustMarshal.

To prevent data corruption or crashes, handle errors during the marshalling process.

- bz := k.cdc.MustMarshal(&singleElement.States)
+ bz, err := k.cdc.Marshal(&singleElement.States)
+ if err != nil {
+     return err
+ }

Likely invalid or redundant comment.

local_node.sh (5)

99-99: LGTM!

The change to set the staking_total_amount to "5000" for the first token in the assets module looks good.


105-110: LGTM! Verify if the financial metrics are intended for testing purposes only.

The new entry under operator_assets looks good. However, please confirm if setting all the financial metrics to "5000" is intended for testing purposes only and not meant to reflect real-world scenarios.


116-121: LGTM!

The restructuring of the operator-related information under operator_info enhances clarity and organization. The change looks good.


124-126: LGTM!

The change to replace the delegations structure with delegation_states in the delegation module enhances clarity and organization. The inclusion of keys and states provides a clearer representation of the delegation data. The change looks good.


129-130: LGTM!

The new entry under stakers_by_operator in the delegation module looks good. It provides a way to organize and retrieve stakers by operator and asset, enhancing the data structure.

x/operator/keeper/usd_value.go (2)

25-25: LGTM!

The store prefix update from KeyPrefixVotingPowerForOperator to KeyPrefixUSDValueForOperator is consistent with the overall changes in the file.


149-149: LGTM!

The store prefix update from KeyPrefixVotingPowerForAVS to KeyPrefixUSDValueForAVS is consistent with the overall changes in the file.

x/operator/types/genesis.go (9)

13-34: LGTM!

The changes to NewGenesisState and DefaultGenesis look good. The additional parameters provide more flexibility in initializing the genesis state.


Line range hint 37-108: LGTM!

The ValidateOperators function performs important validation checks on the list of operators. The checks for duplicate addresses, bech32 format, and commission rates help ensure the integrity of the genesis state.


110-170: LGTM!

The ValidateOperatorConsKeyRecords function performs important validation checks on the operator consensus key records. The checks for bech32 format, duplicate addresses, and consensus key format help ensure the integrity of the genesis state.


172-213: LGTM!

The ValidateOptedStates function performs important validation checks on the opted states. The checks for registered operators, opted-in and opted-out heights, and AVS addresses help ensure the integrity of the genesis state.


215-249: LGTM!

The ValidateAVSUSDValues function performs important validation checks on the AVS USD values. The checks for valid AVS addresses, opted-in AVS addresses, and non-negative USD values help ensure the integrity of the genesis state.


251-324: LGTM!

The ValidateOperatorUSDValues function performs important validation checks on the operator USD values. The checks for non-negative USD values, registered operators, and consistency with AVS USD values help ensure the integrity of the genesis state.


326-429: LGTM!

The ValidateSlashStates function performs important validation checks on the slash states. The checks for registered operators, opted-in AVS addresses, valid slash proportions, and valid slashing execution information help ensure the integrity of the genesis state.


431-476: LGTM!

The ValidatePrevConsKeys function performs important validation checks on the previous consensus keys. The checks for valid key format, registered operators, and valid consensus keys help ensure the integrity of the genesis state.


478-550: LGTM!

The ValidateOperatorKeyRemovals function performs important validation checks on the operator key removals. The checks for valid key format and registered operators help ensure the integrity of the genesis state. The updated Validate function ensures that all the validation checks are performed on the genesis state.

x/operator/keeper/consensus_keys.go (3)

504-533: LGTM!

The code changes are approved.


445-458: Correct error handling in SetAllPrevConsKeys.

The error handling for decoding failures is incorrect. The function should return the error instead of nil to prevent silent failures.

-    return nil
+    return err

Likely invalid or redundant comment.


477-488: Correct error handling in SetAllOperatorKeyRemovals.

The error handling for decoding failures is incorrect. The function should return the error instead of nil to prevent silent failures.

-    return nil
+    return err

Likely invalid or redundant comment.

x/assets/types/genesis.go (6)

41-68: LGTM: Generic and reusable validation utility.

The CommonValidation function is a well-structured and reusable utility for validating input data and checking for duplicates. The use of generics allows it to be used with different types of input slices and validation logic. The function correctly builds a map of unique field values and returns an error if any duplicates are found or if the validation function returns an error for any element.


70-106: LGTM: Comprehensive validation of client chains.

The ValidateClientChains function performs thorough validation of the ClientChains field in the GenesisState struct. It checks for the presence of required fields such as Name, LayerZeroChainID, and AddressLength, ensuring that the data is well-formed. Additionally, it leverages the CommonValidation function to detect and prevent duplicate entries based on the LayerZeroChainID. The function is well-structured and effectively ensures the integrity of the client chains data.


108-180: LGTM: Robust validation of tokens.

The ValidateTokens function provides a comprehensive validation of the Tokens field in the GenesisState struct. It ensures that each StakingAssetInfo has a registered LayerZeroChainID, a valid hex address, non-negative StakingTotalAmount, and non-negative TotalSupply. The function leverages the CommonValidation utility to detect and prevent duplicate entries based on the AssetID field. Additionally, it includes a safeguard check to ensure that the StakingTotalAmount does not exceed the TotalSupply for each token. The validation logic is thorough and effectively maintains the integrity of the tokens data.


182-287: LGTM: Comprehensive validation of deposits.

The ValidateDeposits function provides a thorough validation of the Deposits field in the GenesisState struct. It ensures that each DepositsByStaker has a valid StakerID with a registered LayerZeroChainID and uses the CommonValidation utility to detect and prevent duplicate entries based on the StakerID field. For each DepositByAsset within a DepositsByStaker, the function checks that the AssetID is registered, matches the StakerID's LayerZeroChainID, and has non-negative deposit amounts. Additionally, it includes a safeguard check to ensure that the total deposit amount does not exceed the total staking amount for each asset. The validation logic is comprehensive and effectively maintains the integrity of the deposits data.


289-347: LGTM: Thorough validation of operator assets.

The ValidateOperatorAssets function provides a robust validation of the OperatorAssets field in the GenesisState struct. It ensures that each AssetsByOperator has a valid Operator address and uses the CommonValidation utility to detect and prevent duplicate entries based on the Operator field. For each AssetByID within an AssetsByOperator, the function checks that the AssetID is registered and includes safeguard checks to ensure that the sum of the operator's total amount and wait unbonding amount does not exceed the total staking amount for that asset, and that the operator's share does not exceed the total share for each asset. The validation logic is thorough and effectively maintains the integrity of the operator assets data.


352-369: LGTM: Comprehensive validation of GenesisState.

The refactored Validate method of the GenesisState struct provides a thorough and well-structured validation process. It sequentially calls the newly introduced validation functions ValidateClientChains, ValidateTokens, ValidateDeposits, and ValidateOperatorAssets, ensuring that all the required fields and relationships are properly validated. The method also includes the validation of the Params field, which is a good practice. By leveraging the specialized validation functions, the Validate method maintains a clear and modular structure, enhancing the overall readability and maintainability of the codebase.

cmd/exocored/testnet.go (4)

398-398: LGTM!

The code change is approved. The change in the type of operatorInfos aligns with the AI-generated summary.


399-399: LGTM!

The code change is approved. The introduction of the delegationStates variable aligns with the AI-generated summary.


400-401: LGTM!

The code changes are approved. The introduction of the associations and stakersByOperator variables aligns with the AI-generated summary.


423-449: LGTM!

The code changes are approved. The appending of data to the new variables within the loop aligns with the AI-generated summary.

app/app.go (1)

Line range hint 1009-1009: Verify the impact of removing bApp.CreateQueryContext from OperatorKeeper instantiation.

The removal of the bApp.CreateQueryContext argument suggests that the OperatorKeeper no longer relies on this method from bApp for handling queries. This change may impact how queries are handled within the application, particularly for the OperatorKeeper.

Please verify that:

  1. The OperatorKeeper can still function correctly without this argument.
  2. There are no unintended consequences due to this change.

Consider adding unit tests to ensure the expected behavior of the OperatorKeeper after this change.

x/reward/keeper/claim_reward_test.go Show resolved Hide resolved
proto/exocore/assets/v1/genesis.proto Show resolved Hide resolved
x/assets/keeper/operator_asset.go Show resolved Hide resolved
proto/exocore/assets/v1/query.proto Show resolved Hide resolved
proto/exocore/assets/v1/query.proto Show resolved Hide resolved
x/operator/keeper/operator.go Outdated Show resolved Hide resolved
x/delegation/keeper/delegation_state.go Show resolved Hide resolved
x/delegation/keeper/delegation_state.go Show resolved Hide resolved
x/operator/keeper/consensus_keys.go Outdated Show resolved Hide resolved
x/operator/keeper/consensus_keys.go Outdated Show resolved Hide resolved
@cloud8little cloud8little added this to the Testnet V6 milestone Sep 10, 2024
@cloud8little cloud8little mentioned this pull request Sep 10, 2024
13 tasks
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: 4

Outside diff range, codebase verification and nitpick comments (5)
x/delegation/types/genesis.go (1)

Line range hint 63-178: Suggestion: Remove the commented-out ValidateDelegations function.

The ValidateDelegations function is commented out and not used in the current implementation. It seems to be replaced by the new validation functions introduced in this diff. To improve code cleanliness and maintainability, consider removing the commented-out function entirely.

x/delegation/keeper/delegation_state.go (4)

17-32: Efficient retrieval of all delegation states.

The AllDelegationStates function is implemented efficiently, iterating over the stored delegation information and constructing a slice of DelegationStates to return. Consider handling errors from the MustUnmarshal method to enhance robustness.

- k.cdc.MustUnmarshal(iterator.Value(), &stateInfo)
+ if err := k.cdc.Unmarshal(iterator.Value(), &stateInfo); err != nil {
+     return nil, err
+ }

34-42: Ensure error handling during delegation state setting.

The SetAllDelegationStates function correctly sets each delegation state in the store. However, it is crucial to handle errors during the marshalling process to prevent data corruption or crashes.

- bz := k.cdc.MustMarshal(&singleElement.States)
+ bz, err := k.cdc.Marshal(&singleElement.States)
+ if err != nil {
+     return err
+ }

279-294: Efficient retrieval of all staker lists.

The AllStakerList function is implemented efficiently, iterating over the stored staker information and constructing a slice of StakersByOperator to return. Consider handling errors from the MustUnmarshal method to enhance robustness.

- k.cdc.MustUnmarshal(iterator.Value(), &stakers)
+ if err := k.cdc.Unmarshal(iterator.Value(), &stakers); err != nil {
+     return nil, err
+ }

296-304: Ensure error handling during staker list setting.

The SetAllStakerList function correctly sets each staker list in the store. However, it is crucial to handle errors during the marshalling process to prevent data corruption or crashes.

- bz := k.cdc.MustMarshal(&delegationtype.StakerList{Stakers: singleElement.Stakers})
+ bz, err := k.cdc.Marshal(&delegationtype.StakerList{Stakers: singleElement.Stakers})
+ if err != nil {
+     return err
+ }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 45160c0 and 44ba24b.

Files ignored due to path filters (8)
  • x/assets/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/assets/types/query.pb.go is excluded by !**/*.pb.go
  • x/assets/types/tx.pb.go is excluded by !**/*.pb.go
  • x/delegation/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/delegation/types/types/query.pb.go is excluded by !**/*.pb.go
  • x/delegation/types/types/query.pb.gw.go is excluded by !**/*.pb.gw.go
  • x/operator/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/operator/types/tx.pb.go is excluded by !**/*.pb.go
Files selected for processing (53)
  • app/app.go (1 hunks)
  • app/ethtest_helper.go (4 hunks)
  • app/test_helpers.go (3 hunks)
  • cmd/exocored/root.go (4 hunks)
  • cmd/exocored/testnet.go (3 hunks)
  • local_node.sh (1 hunks)
  • precompiles/assets/tx.go (1 hunks)
  • precompiles/avs/query_test.go (2 hunks)
  • proto/exocore/assets/v1/genesis.proto (3 hunks)
  • proto/exocore/assets/v1/query.proto (4 hunks)
  • proto/exocore/assets/v1/tx.proto (2 hunks)
  • proto/exocore/delegation/v1/genesis.proto (2 hunks)
  • proto/exocore/dogfood/v1/genesis.proto (1 hunks)
  • proto/exocore/operator/v1/genesis.proto (1 hunks)
  • proto/exocore/operator/v1/tx.proto (1 hunks)
  • testutil/utils.go (3 hunks)
  • x/assets/keeper/client_chain_and_asset_test.go (1 hunks)
  • x/assets/keeper/client_chain_asset.go (2 hunks)
  • x/assets/keeper/genesis.go (3 hunks)
  • x/assets/keeper/keeper.go (1 hunks)
  • x/assets/keeper/operator_asset.go (1 hunks)
  • x/assets/keeper/staker_asset.go (2 hunks)
  • x/assets/keeper/staker_asset_test.go (1 hunks)
  • x/assets/types/errors.go (1 hunks)
  • x/assets/types/genesis.go (5 hunks)
  • x/assets/types/genesis_test.go (5 hunks)
  • x/assets/types/keys.go (2 hunks)
  • x/delegation/keeper/delegation.go (2 hunks)
  • x/delegation/keeper/delegation_state.go (5 hunks)
  • x/delegation/keeper/genesis.go (2 hunks)
  • x/delegation/keeper/un_delegation_state.go (1 hunks)
  • x/delegation/types/errors.go (1 hunks)
  • x/delegation/types/genesis.go (2 hunks)
  • x/delegation/types/genesis_test.go (3 hunks)
  • x/delegation/types/keys.go (1 hunks)
  • x/operator/client/cli/tx.go (3 hunks)
  • x/operator/keeper/consensus_keys.go (2 hunks)
  • x/operator/keeper/genesis.go (2 hunks)
  • x/operator/keeper/keeper.go (3 hunks)
  • x/operator/keeper/operator.go (3 hunks)
  • x/operator/keeper/operator_info_test.go (3 hunks)
  • x/operator/keeper/operator_slash_state.go (1 hunks)
  • x/operator/keeper/opt.go (2 hunks)
  • x/operator/keeper/slash.go (4 hunks)
  • x/operator/keeper/slash_test.go (1 hunks)
  • x/operator/keeper/usd_value.go (11 hunks)
  • x/operator/keeper/usd_value_test.go (2 hunks)
  • x/operator/types/expected_keepers.go (1 hunks)
  • x/operator/types/genesis.go (2 hunks)
  • x/operator/types/genesis_test.go (6 hunks)
  • x/operator/types/keys.go (5 hunks)
  • x/reward/keeper/claim_reward_test.go (1 hunks)
  • x/slash/keeper/execute_slash_test.go (1 hunks)
Files skipped from review due to trivial changes (4)
  • cmd/exocored/root.go
  • proto/exocore/dogfood/v1/genesis.proto
  • x/delegation/types/keys.go
  • x/operator/keeper/keeper.go
Additional context used
Learnings (4)
x/assets/keeper/client_chain_asset.go (1)
Learnt from: TimmyExogenous
PR: ExocoreNetwork/exocore#108
File: x/assets/keeper/client_chain_asset.go:94-103
Timestamp: 2024-09-09T06:07:43.713Z
Learning: In the Exocore project, corrupted data handling is not required in functions like `GetAllStakingAssetsInfo` because the node won't function properly if the data is corrupted, following the Cosmos-SDK's design philosophy.
x/operator/keeper/operator.go (1)
Learnt from: TimmyExogenous
PR: ExocoreNetwork/exocore#108
File: x/operator/keeper/operator.go:195-203
Timestamp: 2024-09-10T07:16:15.358Z
Learning: The `SetAllOptedInfo` function is only used in the `InitGenesis` function, which panics on errors, making additional error handling unnecessary in this specific context.
x/delegation/keeper/un_delegation_state.go (2)
Learnt from: MaxMustermann2
PR: ExocoreNetwork/exocore#95
File: x/dogfood/keeper/unbonding.go:91-116
Timestamp: 2024-06-12T04:29:35.064Z
Learning: The `GetAllUndelegationsToMature` function in `x/dogfood/keeper/unbonding.go` uses an iterator that processes one record per iteration, and the record keys are stored efficiently as a key-value pair with the key being a prefix + big-endian epoch. This storage pattern provides direct and efficient access to the data.
Learnt from: TimmyExogenous
PR: ExocoreNetwork/exocore#108
File: x/delegation/keeper/un_delegation_state.go:32-41
Timestamp: 2024-09-09T02:21:06.463Z
Learning: The completion of undelegation can occur at the current block height, meaning that the `CompleteBlockNumber` can be equal to the current height in the `SetUndelegationRecords` function.
x/operator/keeper/usd_value.go (1)
Learnt from: TimmyExogenous
PR: ExocoreNetwork/exocore#108
File: x/operator/keeper/usd_value.go:266-274
Timestamp: 2024-09-09T06:42:40.462Z
Learning: The Cosmos SDK's KVStore doesn't support batch operations for setting multiple states.
buf
proto/exocore/delegation/v1/genesis.proto

5-5: import "exocore/delegation/v1/query.proto": file does not exist

(COMPILE)

proto/exocore/assets/v1/genesis.proto

4-4: import "cosmos_proto/cosmos.proto": file does not exist

(COMPILE)

Additional comments not posted (115)
x/reward/keeper/claim_reward_test.go (1)

46-46: Verify if assets[0] is the correct asset being tested.

Thanks for clarifying that the assets type has been changed from a map to a list, so accessing by assetID is no longer possible.

However, just to ensure correctness, is it guaranteed that the first asset in the list (assets[0]) is always the one being tested in this case? If not, we might need to find the correct asset in the list based on some property, such as assetID, to ensure we are validating the expected asset.

To verify if assets[0] is the correct asset being tested, you can add an assertion to check if assets[0].AssetID matches the assetID used in the test. Here's a script to find the usage of assetID in the test:

#!/bin/bash
# Description: Find the usage of `assetID` in the test file.

# Test: Search for the declaration and usage of `assetID`. 
# Expect: `assetID` is declared and used in the test.
rg --type go -A 5 $'assetID\s*:?=' x/reward/keeper/claim_reward_test.go

If assetID is not being used to set up the test case, then assets[0] might not be the correct asset to validate against. In that case, consider finding the asset in the list that matches the assetID.

x/delegation/types/errors.go (1)

83-86: Enhance the error message to clarify the reason for the invalid block height.

The new error variable ErrInvalidCompletedHeight improves error handling by signaling the specific error condition. However, consider making the error message more descriptive by specifying what makes the block height invalid, as suggested in the past review comment:

- "the block height to complete the undelegation is invalid",
+ "the block height to complete the undelegation is invalid: must be greater than the current height",

This will provide more context to the user about the reason for the error.

x/assets/keeper/client_chain_and_asset_test.go (5)

29-30: Verify if the StakingTotalAmount initialization aligns with the expected staking behavior.

The initialization of StakingTotalAmount has been changed from math.NewInt(0) to math.NewIntWithDecimal(201, 6). This change may affect subsequent calculations or assertions related to staking amounts.

Could you provide some context on the reason for using this specific decimal value? It's important to ensure that this value aligns with the expected behavior of the staking mechanism being tested.

To verify if the StakingTotalAmount initialization aligns with the expected staking behavior, you can:

  1. Check if there are any calculations or assertions in the test that rely on the StakingTotalAmount value. If so, ensure that the expected results are updated to match the new initialization value.

  2. Review the staking mechanism's specifications or requirements to confirm if the chosen value is appropriate for testing the desired scenarios.

  3. Consider adding assertions to validate if the StakingTotalAmount is correctly used in the relevant parts of the staking flow being tested.


37-37: Clarify the reason for setting DepositsByStaker to nil and verify its impact.

The DepositsByStaker parameter of defaultGensisState is now explicitly set to nil. This change could impact how deposits are processed or initialized in the genesis state.

Could you provide some context on the reason behind this change? It's important to understand its implications on the behavior of the staking mechanism and ensure that it aligns with the expected functionality.

Please verify if this change is intended and if it aligns with the expected deposit handling in the genesis state. If necessary, consider adding assertions to validate the correct behavior of deposits after this change.

To verify the impact of setting DepositsByStaker to nil, you can:

  1. Review the code that processes deposits from the genesis state. Check if there are any assumptions or conditions that rely on DepositsByStaker being non-nil.

  2. Analyze the staking mechanism's specifications or requirements to understand the expected behavior of deposits in the genesis state. Confirm if setting DepositsByStaker to nil aligns with these expectations.

  3. Consider adding test cases to cover scenarios where DepositsByStaker is nil and validate if the staking mechanism behaves correctly under these conditions.


43-43: Consider the impact of validating only the first client chain on the test's coverage.

The assertion logic has been simplified to check if the clientChains slice contains the first client chain from defaultGensisState.ClientChains, rather than iterating through all client chains.

While this change simplifies the test, it may reduce the coverage of the assertion. It's important to consider if validating only the first client chain is sufficient for the test's purpose.

Could you provide some context on the reason for this change? If the test aims to validate the presence of all client chains, it might be beneficial to keep the iteration logic to ensure comprehensive coverage.

To verify if validating only the first client chain is sufficient, you can:

  1. Review the purpose and scope of this specific test case. Determine if the test is intended to validate the presence of all client chains or if focusing on the first client chain serves the test's objective.

  2. Analyze the code that populates the clientChains slice. Check if there are any assumptions or guarantees about the order or content of the slice that justify validating only the first element.

  3. Consider the potential risks or edge cases that may be missed by not validating all client chains. Assess if these risks are acceptable within the context of the test.

If the test's purpose requires validating all client chains, consider reverting the change and keeping the iteration logic to ensure comprehensive coverage.


47-47: Consider the impact of comparing only the first client chain on the test's coverage.

The comparison logic has been updated to compare the chainInfo with the first element of the clientChains slice, instead of iterating through all client chains.

This change aligns with the simplified assertion logic discussed in the previous comment. However, it may have the same impact on the test's coverage. It's important to consider if comparing only the first client chain is sufficient for the test's purpose.

Could you provide some context on the reason for this change? If the test aims to validate the equality of chainInfo with all client chains, it might be beneficial to keep the iteration logic to ensure comprehensive coverage.

To verify if comparing only the first client chain is sufficient, you can:

  1. Review the purpose and scope of this specific test case. Determine if the test is intended to validate the equality of chainInfo with all client chains or if focusing on the first client chain serves the test's objective.

  2. Analyze the code that retrieves the chainInfo from the keeper. Check if there are any assumptions or guarantees about the order or content of the clientChains slice that justify comparing only the first element.

  3. Consider the potential risks or edge cases that may be missed by not comparing all client chains. Assess if these risks are acceptable within the context of the test.

If the test's purpose requires validating the equality of chainInfo with all client chains, consider reverting the change and keeping the iteration logic to ensure comprehensive coverage.


52-52: **Consider the impact

x/assets/types/errors.go (1)

95-98: LGTM!

The addition of the new error variable ErrParseJoinedKey is a good practice for improving error handling and reporting. The error message is clear and concise.

x/slash/keeper/execute_slash_test.go (1)

69-69: Use the correct index based on the assetID.

The change in the index used to access the assets slice from assets[assetID] to assets[0] in the test case is concerning. This change means that the test will now always use the first asset in the assets slice regardless of the value of assetID, which may not accurately reflect the intended behavior of the GetStakingAssetInfo method when different asset IDs are involved.

Use the correct index based on the assetID to ensure that the test accurately reflects the intended behavior of the GetStakingAssetInfo method:

-suite.Equal(assets[0].StakingTotalAmount.Add(depositEvent.OpAmount).Sub(event.OpAmount), assetInfo.StakingTotalAmount)
+suite.Equal(assets[assetID].StakingTotalAmount.Add(depositEvent.OpAmount).Sub(event.OpAmount), assetInfo.StakingTotalAmount)

Likely invalid or redundant comment.

proto/exocore/delegation/v1/genesis.proto (3)

28-34: Approved: New DelegationStates message.

The addition of the DelegationStates message is approved. It provides a structured way to store delegation states, enhancing the tracking of delegations within the system.


38-43: Approved: New StakersByOperator message.

The addition of the StakersByOperator message is approved. It provides a structured way to store staker associations with operators, enhancing the tracking of staker relationships within the system.


17-23: LGTM, but verify the impact on the codebase.

The changes to the GenesisState message are approved. The restructuring provides a more comprehensive tracking of delegations and staker relationships.

However, ensure that the removal of the delegations field and the addition of new fields do not break any existing functionality. Thoroughly test the changes and update any code that relies on the previous structure of GenesisState.

Run the following script to verify the usage of the GenesisState message:

x/delegation/keeper/genesis.go (2)

52-77: Approved: Enhanced ExportGenesis function with improved error handling.

The changes to the ExportGenesis function are approved. The function now gathers and returns a more comprehensive state, including associations, delegation states, staker lists, and undelegations.

The enhanced error handling is a significant improvement. By logging errors with context if any of the retrievals fail, the function provides meaningful messages that aid in debugging and maintenance.


34-47: Verify the impact of the changes on the initialization process.

The changes to the InitGenesis function reflect a significant shift in how delegations are initialized. The removal of the nested loop structure that processed delegations suggests a move towards a more streamlined approach to handling delegation data.

Ensure that the new logic for initializing the state from the general exporting genesis file is thoroughly tested and covers all necessary scenarios. Verify that the removal of the delegation processing logic does not introduce any gaps in the initialization process.

Run the following script to verify the initialization process:

Verification successful

Verify the implementation of new initialization functions.

The old delegation processing logic has been removed, and new functions (SetAllDelegationStates, SetAllStakerList, SetUndelegationRecords) have been introduced to handle the initialization of delegation data. These functions are present and used in the codebase, indicating a shift towards a more streamlined initialization process.

  • Ensure that the implementation of these new functions is thoroughly reviewed to verify that they cover all necessary scenarios and do not introduce any gaps in the initialization process.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the initialization process in `InitGenesis`.

# Test: Search for the usage of the removed delegation processing logic. Expect: No occurrences.
rg --type go 'for _, delegation := range gs.Delegations'

# Test: Search for the usage of the new initialization logic. Expect: Occurrences in relevant code.
rg --type go 'SetAllDelegationStates'
rg --type go 'SetAllStakerList'
rg --type go 'SetUndelegationRecords'

Length of output: 1142

x/assets/keeper/genesis.go (3)

19-19: Approved: Enhanced error handling in InitGenesis.

The changes to the error handling in the InitGenesis function are approved. By wrapping the original errors with context-specific messages using the errorsmod.Wrap function, the clarity of error reporting is improved, making it easier to diagnose issues during execution.

This is a positive change that contributes to better maintainability and reliability of the code.

Also applies to: 26-26, 44-44


56-56: Approved: Enhanced error handling when setting operator asset info.

The change to the error handling when setting operator asset info in the InitGenesis function is approved. By wrapping the original error with a context-specific message using the errorsmod.Wrap function, the clarity of error reporting is improved, making it easier to diagnose issues during execution.

This is a positive change that contributes to better maintainability and reliability of the code.


63-93: Approved: Enhanced ExportGenesis function with improved error handling.

The changes to the ExportGenesis function are approved. The inclusion of the receiver variable k in the function signature aligns with the Go best practices.

The enhanced error handling is a significant improvement. By logging errors with context if any of the retrievals fail, including parameters, client chains, staking assets, deposits, and operator assets, the function provides meaningful messages that aid in debugging and maintenance.

These changes contribute to better maintainability and reliability of the code.

x/operator/keeper/operator_info_test.go (2)

Line range hint 4-33: LGTM!

The test changes are approved:

  • Printing the account address length is helpful for debugging.
  • Updating the Commission field to use sdk.ZeroDec() aligns with the latest SDK conventions.

37-49: LGTM!

The test changes are approved:

  • The test correctly sets the operator info and queries all operators.
  • The test reflects the new OperatorDetail struct and updates the assertions accordingly.
proto/exocore/assets/v1/genesis.proto (3)

30-34: Approve the changes to the GenesisState message.

The addition of the operator_assets field of type AssetsByOperator in the GenesisState message provides a clearer structure for managing operator assets.


36-54: Approve the new messages AssetsByOperator and AssetByID.

The new messages AssetsByOperator and AssetByID are well-defined and serve their purpose of managing operator assets effectively.


4-4: Fix the invalid import statement.

The import statement for cosmos_proto/cosmos.proto is incorrect as the file does not exist.

Remove the invalid import statement:

-import "cosmos_proto/cosmos.proto";

Likely invalid or redundant comment.

Tools
buf

4-4: import "cosmos_proto/cosmos.proto": file does not exist

(COMPILE)

x/operator/keeper/genesis.go (2)

13-19: Approve the changes to InitGenesis.

The changes to InitGenesis enhance the initialization process:

  • Setting the EarningsAddr to OperatorAddress if it's empty ensures that all operators have a valid earnings address.
  • Handling operator records by setting consensus keys for each operator based on their chain details adds a layer of functionality that was previously absent.

Also applies to: 20-29


58-104: Approve the changes to ExportGenesis.

The changes to ExportGenesis significantly enhance its functionality and robustness:

  • Including a context parameter in the function signature aligns it with the standard practice in the SDK.
  • Constructing a GenesisState object by aggregating various operator-related data enhances the functionality of the method.
  • Logging errors during the fetch operations instead of causing a panic improves error handling and makes the system more resilient.
x/assets/keeper/client_chain_asset.go (2)

46-48: LGTM!

The new validation check for negative staking amounts enhances the robustness of the input validation process.


94-103: LGTM!

The changes to the return type and internal logic simplify the data structure and may improve performance and memory usage.

x/assets/keeper/staker_asset.go (2)

14-45: LGTM!

The new AllDeposits function provides a useful method for retrieving all deposits associated with stakers, which can be beneficial for generating reports or performing bulk operations on deposits.


Line range hint 47-64: LGTM!

The changes to the return type and internal logic reflect a more streamlined approach to managing deposits by structuring and accessing asset information differently.

x/operator/keeper/slash_test.go (1)

75-79: Verify the impact of removing the dereferencing operator.

The changes involve removing the dereferencing operator (*) from the elements accessed in the SlashUndelegations and SlashAssetsPool slices of the slashInfo.ExecutionInfo structure. This suggests a shift in the handling of these data structures.

Please ensure that the removal of the dereferencing operator does not introduce any unintended side effects or alter the behavior of the test. Verify that the elements in these slices are no longer expected to be pointers or that the dereferencing was unnecessary.

Run the following script to verify the usage of SlashUndelegations and SlashAssetsPool in the codebase:

Verification successful

Dereferencing operator removal is consistent and safe.

The removal of the dereferencing operator from SlashUndelegations and SlashAssetsPool in slash_test.go is consistent with their usage throughout the codebase. These fields are treated as non-pointer types, and the change does not introduce any unintended side effects.

  • x/operator/keeper/slash_test.go: Direct access without dereferencing.
  • x/operator/types/tx.pb.go: Methods like MarshalToSizedBuffer and Unmarshal treat them as non-pointer types.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `SlashUndelegations` and `SlashAssetsPool` in the codebase.

# Test: Search for the usage of `SlashUndelegations` and `SlashAssetsPool`. 
# Expect: No occurrences of dereferencing these fields.
rg --type go $'SlashUndelegations\[.*\]\.' 
rg --type go $'SlashAssetsPool\[.*\]\.'

Length of output: 859

x/operator/types/expected_keepers.go (1)

28-28: ****

x/assets/keeper/staker_asset_test.go (2)

Line range hint 11-86:


88-116: LGTM!

The changes to the TestGetStakerAssetInfos function are approved:

  • The WaitUnbondingAmount field is correctly added to the DeltaStakerSingleAsset struct for both ethUniInitialChangeValue and ethUsdtInitialChangeValue.
  • The assetsInfo variable is renamed to getAssetsInfo, which is more descriptive.
  • The assertions are simplified to use suite.Contains to check if the expected asset information is present in the returned getAssetsInfo, which is more concise and readable.
x/operator/types/genesis_test.go (1)

Line range hint 27-220: LGTM!

The changes to the TestValidateGenesis function are approved:

  • The Operators field in the GenesisState struct is correctly changed from []types.OperatorInfo to []types.OperatorDetail, which reflects the shift in how operator-related data is represented.
  • The EarningsAddr field is renamed to OperatorAddress, which is a more explicit naming convention that aligns with the new structure.
  • New test cases are added to validate the genesis state against various conditions, such as invalid operator addresses, unregistered operators, and duplicate entries in the consensus key records. These new test cases enhance the robustness of the validation logic by ensuring that the genesis state adheres to stricter criteria.
x/assets/keeper/operator_asset.go (2)

14-44: LGTM!

The new AllOperatorAssets function is approved:

  • It correctly retrieves all operator assets from the store using a key-value store iterator.
  • It groups assets by operator and constructs a slice of AssetsByOperator, which includes the operator's address and a list of associated asset states.
  • It handles potential errors during key parsing and unmarshalling of asset information.
  • The function follows the best practices for iterating over a key-value store and grouping assets by operator.

Line range hint 46-59: LGTM!

The changes to the GetOperatorAssetInfos function are approved:

  • The return type is correctly changed from a map to a slice of AssetByID, reflecting the shift in how asset information is structured and returned.
  • The internal logic is updated to accommodate the new return type, using an append operation to build the result slice instead of directly assigning values to a map.
  • The changes are consistent with the new structure and improve the clarity of the function.
precompiles/assets/tx.go (1)

146-146: LGTM!

The change from passing asset by reference to passing it by value looks good. This change should not cause any issues.

x/delegation/types/genesis_test.go (11)

33-41: LGTM!

The initialization of delegationStates looks good.


43-50: LGTM!

The initialization of stakersByOperator looks good.


70-70: LGTM!

The initialization of the genesis state using NewGenesis with the new delegationStates and stakersByOperator variables looks good.


78-79: LGTM!

The modification of the Key field to an invalid value is correctly setting up the test case for an invalid staker ID.


82-82: LGTM!

The restoration of the Key field to the original value in the unmalleate function looks good.


90-90: LGTM!

Appending a duplicate of the first element in DelegationStates is correctly setting up the test case for duplicate state keys.


93-93: LGTM!

Restoring DelegationStates to its original state in the unmalleate function looks good.


101-102: LGTM!

Modifying the Key field to a value with an invalid asset ID is correctly setting up the test case for an invalid asset ID.


105-105: LGTM!

Restoring the Key field to the original value in the unmalleate function looks good.


116-117: LGTM!

Modifying the Key field to a value with a different asset ID is correctly setting up the test case for asset ID mismatch.


120-120: LGTM!

Restoring the Key field to the original value in the unmalleate function looks good.

x/operator/keeper/usd_value_test.go (2)

77-77: LGTM!

The change from a pointer reference to a direct reference for AssetBasicInfo simplifies the code and is approved.


135-135: LGTM!

The change from dereferencing a pointer to directly assigning the value for asset simplifies the code and is approved.

x/operator/types/keys.go (1)

135-156: LGTM!

The new function ParseKeyForOperatorAndChainIDToConsKey is well-implemented. It correctly extracts the operator address and chain ID from the key while validating the key length and handling errors appropriately.

x/operator/keeper/operator_slash_state.go (2)

159-167: Based on the learnings, the SetAllSlashInfo function is only used in the InitGenesis function, which panics on errors. Therefore, additional error handling is unnecessary in this context.


169-184: LGTM!

The code changes are approved.

proto/exocore/operator/v1/genesis.proto (9)

15-44: Based on the past comments, the impact of the field type change in the GenesisState message has been addressed. Additionally, the data migration concerns are mitigated due to the upcoming Testnet launch using Bootstrap.


46-54: LGTM!

The code changes are approved.


56-64: LGTM!

The code changes are approved.


66-73: LGTM!

The code changes are approved.


75-86: LGTM!

The code changes are approved.


88-96: LGTM!

The code changes are approved.


98-109: LGTM!

The code changes are approved.


111-117: LGTM!

The code changes are approved.


119-137: LGTM!

The code changes are approved.

x/operator/keeper/operator.go (3)

25-28: The changes to the SetOperatorInfo function address the concern raised in the past comments about the lack of robust validation for the operator address. The function now attempts to parse the addr directly into an account address and returns a wrapped error if the parsing fails.


79-92: The changes to the AllOperators function enhance the information returned by the method, allowing for more comprehensive data retrieval regarding operators. However, the concern raised in the past comments about potential performance issues due to not efficiently handling large data volumes still remains unaddressed.


198-206: Based on the learnings, the SetAllOptedInfo function is only used in the InitGenesis function, which panics on errors. Therefore, additional error handling is unnecessary in this context.

app/ethtest_helper.go (3)

192-193: LGTM!

The change to initialize StakingTotalAmount using the depositAmount instead of a fixed zero value is approved. This enhances the flexibility of asset initialization.


206-213: LGTM!

The change to replace the OperatorInfo structure with OperatorDetail is approved. This improves the clarity and maintainability of the code by using a more comprehensive structure for operator details.


Line range hint 219-243: LGTM!

The changes to the delegation handling in the genesis state setup are approved. These changes, including the introduction of DelegationStates, stakersByOperator, and the updated delegationGenesis initialization, enhance the functionality and clarity of the genesis state setup, allowing for more dynamic and detailed management of delegations within the system.

x/delegation/keeper/delegation.go (1)

Line range hint 129-141: LGTM!

The change to instantiate the UndelegationRecord as a value type instead of a pointer type is approved. This simplifies the handling of records within the function by eliminating the need for dereferencing pointers when marshaling the records.

x/delegation/keeper/un_delegation_state.go (2)

16-27: LGTM!

The new AllUndelegations function is approved. This function enhances the functionality of the Keeper by allowing for the retrieval of all undelegation records in a single call using a prefix iterator.


32-41: LGTM!

The changes to the SetUndelegationRecords function are approved. These changes, including accepting a slice of types.UndelegationRecord instead of a slice of pointers and adding a validation check against the current block height, simplify the handling of records within the function and enforce stricter validation on undelegation records being set, thereby enhancing the overall integrity of the undelegation process.

precompiles/avs/query_test.go (2)

158-158: Verify the impact of passing usdcClientChainAsset by value instead of reference.

The change involves removing the address-of operator (&) when assigning usdcClientChainAsset to AssetBasicInfo in the SetStakingAssetInfo method call.

This indicates a shift from passing a pointer to passing the value directly, which may affect how the data is handled within the SetStakingAssetInfo method.

Verify that the SetStakingAssetInfo method correctly handles the AssetBasicInfo field when passed by value and ensure that the change does not alter the expected behavior of the TestAVSUSDValue test.


247-247: Verify the impact of passing usdcClientChainAsset by value instead of reference.

The change involves removing the address-of operator (&) when assigning usdcClientChainAsset to AssetBasicInfo in the SetStakingAssetInfo method call.

This indicates a shift from passing a pointer to passing the value directly, which may affect how the data is handled within the SetStakingAssetInfo method.

Verify that the SetStakingAssetInfo method correctly handles the AssetBasicInfo field when passed by value and ensure that the change does not alter the expected behavior of the TestGetOperatorOptedUSDValue test.

proto/exocore/assets/v1/tx.proto (2)

73-73: LGTM!

The addition of the (gogoproto.nullable) = false option to the asset_basic_info field enhances data integrity by ensuring that an asset's basic information must always be provided when creating an instance of StakingAssetInfo.


120-121: LGTM!

The updated comment for the total_amount field improves the documentation and understanding of the field's purpose by clarifying that it excludes the wait_unbonding_amount.

x/operator/keeper/slash.go (2)

45-47: LGTM!

The additional validation for the SlashProportion parameter enhances the robustness of the input validation process by ensuring it is neither nil nor negative.

The updated error wrapping using Wrapf improves the clarity of error messages by providing a more structured output.

Also applies to: 50-50


86-87: LGTM!

The modifications to the handling of SlashUndelegations and SlashAssetsPool simplify the data structure management by using values directly instead of pointers.

Appending a dereferenced value of slashFromUndelegation to SlashUndelegations and directly appending a SlashFromAssetsPool value to SlashAssetsPool streamlines the code and potentially improves performance by reducing memory allocation overhead associated with pointers.

Also applies to: 95-95, 135-138

app/test_helpers.go (1)

223-243: Approved: The changes improve code structure and clarity.

The modifications to the GenesisStateWithValSet function enhance the logical structure and clarity of the code:

  • Directly referencing assets may improve performance by reducing indirection.
  • The new AssetsByOperator structure enhances the organization of asset management.
  • The OperatorDetail structure provides clearer identification of the operator.
  • The DelegationStates structure simplifies the representation of delegation states.
  • The StakersByOperator structure allows for better management of staker information.

Also applies to: 247-257, 260-283, 284-285

proto/exocore/operator/v1/tx.proto (1)

172-172: Approved: The changes improve data integrity.

The modifications to the SlashExecutionInfo message enforce that the slash_undelegations and slash_assets_pool fields cannot be null by including the (gogoproto.nullable) = false option. This improves data integrity and ensures that any instances of SlashExecutionInfo will always contain valid lists for these fields.

Also applies to: 174-174

x/delegation/types/genesis.go (4)

17-19: Approved: The changes enhance genesis state management functionality.

The modifications to the NewGenesis function reflect a broader scope of data being handled during genesis state initialization. The function now accepts additional parameters: delegationStates, stakersByOperator, and undelegations, which are included in the returned GenesisState. This enhances the functionality related to genesis state management in a blockchain context.

Also applies to: 22-25


31-31: Approved: The changes maintain consistency with the NewGenesis function.

The adjustment to the DefaultGenesis function accommodates the new parameters introduced in the NewGenesis function. This ensures that the DefaultGenesis function can still return a valid genesis state with the new structure, maintaining consistency between the two functions.


34-61: Approved: The new validation functions ensure data integrity.

The introduction of the new validation functions: ValidateIDAndOperator, ValidateAssociations, ValidateDelegationStates, ValidateStakerList, and ValidateUndelegations, improves the overall validation logic by providing comprehensive checks for each data structure. These functions ensure that the genesis state adheres to the expected format and constraints, enhancing data integrity.

  • ValidateIDAndOperator validates the operator address and checks that the staker and asset IDs belong to the same client chain.
  • ValidateAssociations ensures that each staker ID is associated with a unique operator and checks for valid addresses.
  • ValidateDelegationStates validates the delegation states, ensuring that no nil or negative values are present.
  • ValidateStakerList checks the integrity of the staker list against the operator and asset IDs.
  • ValidateUndelegations verifies the correctness of undelegation records, including checks for pending status and valid transaction hashes.

Also applies to: 180-212, 214-254, 256-311, 313-361


366-382: Approved: The changes improve control flow and ensure comprehensive validation.

The modifications to the Validate method of the GenesisState enhance the control flow and ensure comprehensive validation of the genesis state. The method now sequentially calls each validation function introduced earlier: ValidateAssociations, ValidateDelegationStates, ValidateStakerList, and ValidateUndelegations, returning errors if any checks fail. This modular approach improves code readability and maintainability while ensuring thorough validation of the genesis state.

x/assets/types/genesis_test.go (2)

29-30: Simplify types.NewGenesis function parameters.

The changes to replace empty slices with nil when calling types.NewGenesis simplify the function call and improve readability.


54-55: Verify the impact of updating StakingTotalAmount.

The StakingTotalAmount for the stakingInfo variable has been updated from math.NewInt(0) to math.NewInt(100). Ensure that this change does not adversely affect the expected behavior of the test cases.

testutil/utils.go (3)

136-175: Enhance the genesis setup process for assets.

The introduction of the operatorAssets structure and the modifications to the genesis state construction for assets using NewGenesis enhance the clarity and functionality of the genesis setup process. The changes allow for a more detailed and structured representation of asset states.

Verify the correctness of the operatorAssets structure and its usage in the genesis setup process. Ensure that the asset states are accurately captured and that the NewGenesis method is called with the appropriate parameters.


203-219: Improve operator registration using OperatorDetail.

The operator registration process has been updated to utilize the OperatorDetail structure instead of OperatorInfo. This change reflects a more structured approach to managing operator data, enhancing clarity in the operator's identification.


Line range hint 231-271: Revise delegation handling with delegationStates.

The delegation handling has been revised, replacing the delegationsByStaker structure with delegationStates. This simplifies the representation of delegation information and aligns with the updated logic for managing delegations in the genesis state.

Verify that the delegationStates structure accurately captures the necessary delegation information and that the delegationGenesis state is created correctly using the new structures.

x/delegation/keeper/delegation_state.go (3)

54-54: Verify the correctness of the key parsing change.

The IterateDelegationsForStakerAndAsset function now uses ParseStakerAssetIDAndOperator instead of ParseStakerAssetIDAndOperatorAddrFromKey to parse keys. Ensure that this change is correct and aligns with the updated key structure or interpretation.


74-74: Verify the correctness of the key parsing change.

The IterateDelegationsForStaker function now uses ParseStakerAssetIDAndOperator instead of ParseStakerAssetIDAndOperatorAddrFromKey to parse keys. Ensure that this change is correct and aligns with the updated key structure or interpretation.


383-396: Efficient retrieval of all associations.

The GetAllAssociations function is implemented efficiently, iterating over the stored association information and constructing a slice of StakerToOperator to return. The implementation follows a similar pattern to other retrieval functions in the file.

x/operator/types/genesis.go (10)

12-18: LGTM!

The changes to the NewGenesisState function are approved. The updated signature and initialization are consistent with the modifications made to the GenesisState struct.

Also applies to: 21-27


33-33: LGTM!

The change to the DefaultGenesis function is approved. It now returns a GenesisState initialized with multiple nil slices, which is consistent with the updated NewGenesisState function signature.


Line range hint 36-107: Reminder: Add unit tests for ValidateOperators.

The ValidateOperators function performs critical validation checks on the list of operators in the genesis state. However, no unit tests were found for this function.

Please add comprehensive unit tests to ensure the robustness of this function.


109-169: LGTM!

The ValidateOperatorConsKeyRecords function is well-implemented and performs important validation checks on the operator consensus key records in the genesis state.


171-212: Reminder: Add unit tests for ValidateOptedStates.

The ValidateOptedStates function performs critical validation checks on the opted states in the genesis state. However, no unit tests were found for this function.

Please add comprehensive unit tests to ensure the reliability of this function and maintain state integrity.


214-248: LGTM!

The ValidateAVSUSDValues function is well-implemented and performs important validation checks on the AVS USD values in the genesis state.


250-323: LGTM!

The ValidateOperatorUSDValues function is well-implemented and performs important validation checks on the operator USD values in the genesis state.


325-428: Reminder: Add unit tests for ValidateSlashStates.

The ValidateSlashStates function performs critical validation checks on the slash states in the genesis state. However, no unit tests were found for this function.

Please add comprehensive unit tests to ensure the correctness and robustness of this function.


430-468: Reminder: Add unit tests for ValidatePrevConsKeys.

The ValidatePrevConsKeys function performs critical validation checks on the previous consensus keys in the genesis state. However, no unit tests were found for this function.

Please add unit tests for the ValidatePrevConsKeys function in x/operator/types/genesis_test.go to ensure the integrity and reliability of the codebase.


470-495: LGTM!

The ValidateOperatorKeyRemovals function is well-implemented and performs an important validation check on the operator key removals in the genesis state.

x/operator/keeper/usd_value.go (4)

266-274: Acknowledged: Batch operation not supported by Cosmos SDK's KVStore.

The SetAllOperatorUSDValues function sets USD values for all operators in a loop, which is a valid approach given the limitations of the Cosmos SDK's KVStore.

Thanks for clarifying that the Cosmos SDK's KVStore doesn't support batch operations for setting multiple states. No further changes are needed here.


276-291: LGTM!

The GetAllOperatorUSDValues function is well-implemented and retrieves USD values for all operators by iterating over the store and unmarshaling the data.


293-301: Acknowledged: Batch operation not supported by Cosmos SDK's KVStore.

The SetAllAVSUSDValues function sets USD values for all AVS in a loop, which is a valid approach given the limitations of the Cosmos SDK's KVStore.

Thanks for clarifying that the Cosmos SDK's KVStore doesn't support batch operations for setting multiple states. No further changes are needed here.


303-318: LGTM!

The GetAllAVSUSDValues function is well-implemented and retrieves USD values for all AVS by iterating over the store and unmarshaling the data.

x/assets/types/genesis.go (2)

290-347: LGTM: Comprehensive operator assets validation.

The ValidateOperatorAssets function ensures that operator addresses are valid, assets are registered, and the operator's asset amounts do not exceed the total staking amount. The logic is clear and well-implemented, covering critical aspects of operator assets validation.


352-369: LGTM: Refactored Validate function.

The refactored Validate function sequentially calls the new validation methods, ensuring that all aspects of the genesis state are validated before finalizing the state. This refactoring enhances the modularity and clarity of the validation process, allowing for easier maintenance and potential future extensions.

x/operator/keeper/consensus_keys.go (4)

525-554: LGTM: Comprehensive operator consensus key records retrieval.

The GetAllOperatorConsKeyRecords function collects all operator consensus key records, organizing them by operator address. It utilizes a prefix iterator to gather data and constructs a structured response that groups consensus keys by operator. The logic is clear and well-implemented, enhancing the keeper's capabilities in managing and retrieving operator-related data.


446-465: Do you want me to generate the unit testing code or open a GitHub issue to track this task?


467-486: Do you want me to generate the unit testing code or open a GitHub issue to track this task?


506-523: Do you want me to generate the unit testing code or open a GitHub issue to track this task?

cmd/exocored/testnet.go (1)

Line range hint 398-449: LGTM: Enhanced operator and delegation management.

The changes in the getTestExocoreGenesis function involve significant modifications to the data structures used for managing operator and delegation information. The original code utilized OperatorInfo and DelegationsByStaker, which have been replaced with OperatorDetail and DelegationStates, respectively. This indicates a shift in how operator details are encapsulated, with OperatorDetail now containing an embedded OperatorInfo, suggesting a more structured approach to operator data.

Additionally, new data structures StakerToOperator and StakersByOperator have been introduced, enhancing the relationships between stakers and operators. The logic for appending to these new structures has been implemented, indicating a more complex handling of delegation states and associations.

The overall control flow remains similar, but the internal data handling has been enriched, allowing for more detailed tracking of operators and their associated stakers. The changes suggest an enhancement in the functionality related to staking and delegation management, likely aimed at improving the clarity and efficiency of these operations.

app/app.go (1)

Line range hint 1293-1300: Streamlined OperatorKeeper initialization. Verify that it functions correctly without the query context.

The removal of the bApp.CreateQueryContext argument from the call to operatorKeeper.NewKeeper streamlines the initialization of the OperatorKeeper by reducing its dependencies.

To verify that the OperatorKeeper can still function correctly without the query context, run the following script:

Verification successful

Verification Successful: OperatorKeeper Initialization Simplified

The removal of the bApp.CreateQueryContext argument from the operatorKeeper.NewKeeper call does not impact the functionality of OperatorKeeper. The broader search confirmed that there are no dependencies on a query context within the OperatorKeeper usage. This change effectively streamlines the initialization process without affecting functionality.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the `OperatorKeeper` can function without the query context.

# Test: Search for `OperatorKeeper` function calls that use the query context. 
# Expect: No occurrences of `OperatorKeeper` functions using the query context.
rg --type go -A 5 $'OperatorKeeper\\.\\w+\\(ctx' app/

Length of output: 51


Script:

#!/bin/bash
# Description: Re-verify that the `OperatorKeeper` can function without the query context.

# Test: Search for any usage of `OperatorKeeper` functions that might imply dependency on a query context.
# Use a broader pattern to ensure no relevant occurrences are missed.
rg --type go -A 5 'OperatorKeeper' app/

Length of output: 2617

x/operator/keeper/opt.go (1)

23-23: Improved error handling.

The change from directly returning the delegationtypes.ErrOperatorNotExist error to wrapping it using errorsmod.Wrapf is a good practice. It enhances the error message by including contextual information about the operator address that triggered the error.

The wrapped error provides better traceability and debugging capabilities, as it now conveys not only the type of error but also the specific operator address involved in the failure.

x/assets/types/keys.go (2)

94-96: New utility function for identifying joined store keys.

The addition of the IsJoinedStoreKey function is a useful utility that checks if a given key string contains the "/" character. This function may improve the handling of keys within the system, allowing for more robust key validation or processing.


102-102: Improved error handling in ParseJoinedStoreKey.

The update to the error returned when the expected length of the key does not match the actual length, from ErrParseAssetsStateKey to ErrParseJoinedKey, is a good change. It reflects a more accurate representation of the error context and aligns the error message with the function's purpose of parsing joined keys.

x/assets/keeper/keeper.go Show resolved Hide resolved
x/assets/keeper/keeper.go Show resolved Hide resolved
x/assets/keeper/keeper.go Show resolved Hide resolved
x/assets/types/genesis.go Outdated Show resolved Hide resolved
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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 44ba24b and a12fc91.

Files ignored due to path filters (8)
  • x/assets/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/assets/types/query.pb.go is excluded by !**/*.pb.go
  • x/assets/types/tx.pb.go is excluded by !**/*.pb.go
  • x/delegation/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/delegation/types/types/query.pb.go is excluded by !**/*.pb.go
  • x/delegation/types/types/query.pb.gw.go is excluded by !**/*.pb.gw.go
  • x/operator/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/operator/types/tx.pb.go is excluded by !**/*.pb.go
Files selected for processing (52)
  • app/app.go (1 hunks)
  • app/ethtest_helper.go (4 hunks)
  • app/test_helpers.go (3 hunks)
  • cmd/exocored/root.go (4 hunks)
  • cmd/exocored/testnet.go (3 hunks)
  • local_node.sh (1 hunks)
  • precompiles/assets/tx.go (1 hunks)
  • precompiles/avs/query_test.go (2 hunks)
  • proto/exocore/assets/v1/genesis.proto (3 hunks)
  • proto/exocore/assets/v1/query.proto (4 hunks)
  • proto/exocore/assets/v1/tx.proto (2 hunks)
  • proto/exocore/delegation/v1/genesis.proto (2 hunks)
  • proto/exocore/dogfood/v1/genesis.proto (1 hunks)
  • proto/exocore/operator/v1/genesis.proto (1 hunks)
  • proto/exocore/operator/v1/tx.proto (1 hunks)
  • testutil/utils.go (3 hunks)
  • x/assets/keeper/client_chain_and_asset_test.go (1 hunks)
  • x/assets/keeper/client_chain_asset.go (2 hunks)
  • x/assets/keeper/genesis.go (3 hunks)
  • x/assets/keeper/keeper.go (1 hunks)
  • x/assets/keeper/operator_asset.go (1 hunks)
  • x/assets/keeper/staker_asset.go (2 hunks)
  • x/assets/keeper/staker_asset_test.go (1 hunks)
  • x/assets/types/errors.go (1 hunks)
  • x/assets/types/genesis.go (5 hunks)
  • x/assets/types/genesis_test.go (5 hunks)
  • x/assets/types/keys.go (2 hunks)
  • x/delegation/keeper/delegation.go (2 hunks)
  • x/delegation/keeper/delegation_state.go (5 hunks)
  • x/delegation/keeper/genesis.go (2 hunks)
  • x/delegation/keeper/un_delegation_state.go (1 hunks)
  • x/delegation/types/errors.go (1 hunks)
  • x/delegation/types/genesis.go (2 hunks)
  • x/delegation/types/genesis_test.go (3 hunks)
  • x/delegation/types/keys.go (1 hunks)
  • x/operator/client/cli/tx.go (3 hunks)
  • x/operator/keeper/consensus_keys.go (2 hunks)
  • x/operator/keeper/genesis.go (2 hunks)
  • x/operator/keeper/keeper.go (3 hunks)
  • x/operator/keeper/operator.go (3 hunks)
  • x/operator/keeper/operator_info_test.go (3 hunks)
  • x/operator/keeper/operator_slash_state.go (1 hunks)
  • x/operator/keeper/slash.go (4 hunks)
  • x/operator/keeper/slash_test.go (1 hunks)
  • x/operator/keeper/usd_value.go (11 hunks)
  • x/operator/keeper/usd_value_test.go (2 hunks)
  • x/operator/types/expected_keepers.go (1 hunks)
  • x/operator/types/genesis.go (2 hunks)
  • x/operator/types/genesis_test.go (6 hunks)
  • x/operator/types/keys.go (5 hunks)
  • x/reward/keeper/claim_reward_test.go (1 hunks)
  • x/slash/keeper/execute_slash_test.go (1 hunks)
Files skipped from review due to trivial changes (4)
  • proto/exocore/dogfood/v1/genesis.proto
  • x/assets/types/errors.go
  • x/delegation/types/keys.go
  • x/operator/keeper/keeper.go
Files skipped from review as they are similar to previous changes (36)
  • app/app.go
  • app/ethtest_helper.go
  • app/test_helpers.go
  • cmd/exocored/root.go
  • cmd/exocored/testnet.go
  • local_node.sh
  • precompiles/assets/tx.go
  • precompiles/avs/query_test.go
  • proto/exocore/assets/v1/query.proto
  • proto/exocore/assets/v1/tx.proto
  • proto/exocore/operator/v1/tx.proto
  • x/assets/keeper/client_chain_and_asset_test.go
  • x/assets/keeper/client_chain_asset.go
  • x/assets/keeper/genesis.go
  • x/assets/keeper/keeper.go
  • x/assets/keeper/staker_asset_test.go
  • x/assets/types/genesis.go
  • x/assets/types/genesis_test.go
  • x/assets/types/keys.go
  • x/delegation/keeper/delegation.go
  • x/delegation/keeper/delegation_state.go
  • x/delegation/keeper/un_delegation_state.go
  • x/delegation/types/errors.go
  • x/operator/client/cli/tx.go
  • x/operator/keeper/consensus_keys.go
  • x/operator/keeper/genesis.go
  • x/operator/keeper/operator.go
  • x/operator/keeper/operator_info_test.go
  • x/operator/keeper/operator_slash_state.go
  • x/operator/keeper/slash.go
  • x/operator/keeper/slash_test.go
  • x/operator/keeper/usd_value_test.go
  • x/operator/types/expected_keepers.go
  • x/operator/types/genesis.go
  • x/operator/types/keys.go
  • x/reward/keeper/claim_reward_test.go
Additional context used
Learnings (1)
x/operator/keeper/usd_value.go (1)
Learnt from: TimmyExogenous
PR: ExocoreNetwork/exocore#108
File: x/operator/keeper/usd_value.go:266-274
Timestamp: 2024-09-09T06:42:40.462Z
Learning: The Cosmos SDK's KVStore doesn't support batch operations for setting multiple states.
buf
proto/exocore/delegation/v1/genesis.proto

5-5: import "exocore/delegation/v1/query.proto": file does not exist

(COMPILE)

proto/exocore/assets/v1/genesis.proto

4-4: import "cosmos_proto/cosmos.proto": file does not exist

(COMPILE)

Additional comments not posted (42)
x/slash/keeper/execute_slash_test.go (1)

69-69: Use dynamic index based on assetID to ensure test's validity.

The change from using a dynamic index assets[assetID] to a static index assets[0] when comparing the asset state after a slash event could potentially affect the validity of the test.

Using a static index means the test will always use the first asset in the assets slice, regardless of the value of assetID. This may not accurately reflect the intended behavior of the GetStakingAssetInfo method when different asset IDs are involved.

To ensure the test's validity, consider using the dynamic index based on assetID:

-suite.Equal(assets[0].StakingTotalAmount.Add(depositEvent.OpAmount).Sub(event.OpAmount), assetInfo.StakingTotalAmount)
+suite.Equal(assets[assetID].StakingTotalAmount.Add(depositEvent.OpAmount).Sub(event.OpAmount), assetInfo.StakingTotalAmount)

Likely invalid or redundant comment.

proto/exocore/delegation/v1/genesis.proto (2)

17-23: LGTM! The changes to the GenesisState message enhance the data model.

The modifications to the GenesisState message, including:

  • Removing the delegations field
  • Moving the associations field to the first position
  • Adding new fields delegation_states, stakers_by_operator, and undelegations

These changes reflect a significant enhancement in the data model, allowing for more comprehensive tracking of delegations and staker relationships within the system.


26-43: LGTM! The new message types provide more detailed information.

The addition of two new message types, DelegationStates and StakersByOperator, enhances the structure of the genesis state by providing more detailed information about delegation states and staker associations.

x/delegation/keeper/genesis.go (2)

34-47: LGTM! The changes in InitGenesis improve the clarity and functionality.

The modifications to the InitGenesis function, including:

  • Removing the nested loop structure that processed delegations
  • Adding new logic to set all delegation states, staker lists, and undelegation records using the keeper methods

These changes reflect a significant restructuring of the initialization process, with a focus on improving the clarity and functionality of state management within the delegation module. The removal of the nested loop structure suggests a shift towards a more streamlined approach to handling delegation data.


52-77: LGTM! The enhancements in ExportGenesis ensure comprehensive state export.

The enhancements in the ExportGenesis function, including:

  • Gathering and returning the current state of associations, delegation states, staker lists, and undelegations
  • Constructing a GenesisState object by retrieving these states from the keeper
  • Handling errors by logging them and populating the GenesisState accordingly

These changes indicate a more comprehensive approach to exporting the module's state, ensuring that all relevant data is captured and returned.

proto/exocore/assets/v1/genesis.proto (5)

4-4: Fix the invalid import statement.

The import statement for cosmos_proto/cosmos.proto is incorrect as the file does not exist.

Remove the invalid import statement:

-import "cosmos_proto/cosmos.proto";
Tools
buf

4-4: import "cosmos_proto/cosmos.proto": file does not exist

(COMPILE)


30-34: Clarify the use of operator_assets in the GenesisState.

The addition of operator_assets in the GenesisState message (line 33) is crucial for tracking assets by operator. However, the current implementation does not show any handling of operator_assets in the InitGenesis and ExportGenesis functions. Please ensure that these functions are updated to properly handle the operator_assets field.

Run the following script to verify the handling of operator_assets during genesis import and export:

#!/bin/bash
# Verify the handling of `operator_assets` during genesis import and export.
rg 'operator_assets' --type go

36-45: LGTM!

The AssetsByOperator message is used to store the operator and its assets state in the genesis state. The operator field is the address of the operator and the assets_state field is the list of assets state, indexed by the asset id.


47-54: LGTM!

The AssetByID message is a helper struct used to store the asset id and its info for an operator in the genesis state. It is named AssetByID since it is indexed by the asset_id.


61-61: LGTM!

The change is a minor renaming of the staker field to StakerID in the DepositsByStaker message and does not affect the functionality.

x/assets/keeper/staker_asset.go (2)

14-45: LGTM!

The AllDeposits function is a useful addition to retrieve all deposits associated with stakers. The implementation looks correct and efficient. It utilizes a prefix iterator to traverse the store and aggregates deposits by staker ID, returning a slice of DepositsByStaker structures. The logic includes checks to group deposits under the correct staker ID and constructs a list of deposits for each staker.


Line range hint 47-64: LGTM!

The modification to the GetStakerAssetInfos function reflects a shift in how asset information is structured and accessed, emphasizing a more streamlined approach to managing deposits. The changes look correct and the new return type []assetstype.DepositByAsset is more suitable for the purpose of the function compared to the previous map[string]*assetstype.StakerAssetInfo.

x/operator/types/genesis_test.go (5)

6-9: LGTM!

The new import statements are required for the changes introduced in the test cases. They provide necessary dependencies for generating keys, addresses, and encoding.


28-30: LGTM!

The generation of a new key and account addresses is necessary for setting up the test cases. The changes look correct and use the appropriate functions from the imported packages.


Line range hint 52-68: LGTM!

The changes reflect a shift in how operator-related data is represented, likely enhancing the clarity and functionality of the operator details being validated. The test case has been updated to use the new OperatorDetail structure and the OperatorAddress field, which aligns with the new structure. The changes look correct and maintain the purpose of the test case.


Line range hint 77-98: LGTM!

The new test case enhances the robustness of the validation logic by ensuring that the genesis state does not contain duplicate lz chain ids. The test case is well-structured and uses appropriate values to simulate the scenario. The changes look correct and add value to the test suite.


100-115: LGTM!

The new test case ensures that the genesis state validation checks for invalid operator addresses in the OperatorRecords. The test case is well-structured and uses an invalid address to simulate the scenario. The changes look correct and enhance the validation coverage.

x/assets/keeper/operator_asset.go (2)

14-44: LGTM!

The AllOperatorAssets function correctly retrieves all operator assets from the store and groups them by operator. The grouping logic ensures that assets are aggregated correctly for each operator, and the function handles potential errors during key parsing and unmarshalling of asset information.

The code changes are approved.


46-52: LGTM!

The modifications to the GetOperatorAssetInfos function correctly retrieve asset information for the specified operator. The change in the return type from a map to a slice of AssetByID reflects a shift in how asset information is structured and returned. The internal logic has been updated to accommodate the new return type, ensuring that the result is built correctly using an append operation.

The code changes are approved.

x/delegation/types/genesis_test.go (1)

Line range hint 33-154: LGTM!

The modifications to the TestValidateGenesis function enhance the clarity and functionality of the genesis state validation process. The changes align the validation logic with the new delegation model, transitioning from using a DelegationsByStaker structure to a DelegationStates structure.

The updated test cases ensure comprehensive test coverage for various edge cases, including invalid staker IDs, duplicate entries, and mismatched asset IDs. The malleate and unmalleate functions have been updated to align with the new data structure, ensuring that the tests accurately reflect the expected behavior of the genesis state under different conditions.

The code changes are approved.

proto/exocore/operator/v1/genesis.proto (7)

48-54: LGTM!

The new OperatorDetail message provides a structured way to store operator information in the genesis state. It contains an operator_address field representing the address of the operator and an operator_info field containing detailed information about the operator. The inclusion of both the operator address and detailed information allows for a comprehensive representation of operators.

The code changes are approved.


58-64: LGTM!

The new OptedState message provides a structured way to store opted state information in the genesis state. The combination of the operator address and AVS address in the key field allows for unique identification of opted states, while the opt_info field encapsulates the undelegation state for the corresponding key.

The code changes are approved.


68-73: LGTM!

The new AVSUSDValue message provides a structured way to store USD values for AVS addresses in the genesis state. The avs_addr field uniquely identifies the AVS, while the value field holds the corresponding USD value.

The code changes are approved.


77-86: LGTM!

The new OperatorUSDValue message provides a structured way to store USD values for operator and AVS combinations in the genesis state. The key field uniquely identifies the operator and AVS combination, while the opted_usd_value field holds the corresponding USD value states.

The code changes are approved.


90-96: LGTM!

The new OperatorSlashState message provides a structured way to store slash information in the genesis state. The key field uniquely identifies the combination of operator, AVS, and slashID, while the info field holds the corresponding voting power value.

The code changes are approved.


101-109: LGTM!

The new PrevConsKey message provides a structured way to store previous consensus keys in the genesis state. The key field uniquely identifies the combination of chainID and operator address, while the consensus_key field holds the corresponding consensus key.

It's important to note that the consensus_key field is expected to be a hex encoding of a 32-byte key, and this length constraint must be enforced outside of protobuf.

The code changes are approved.


114-117: LGTM!

The new OperatorKeyRemoval message provides a structured way to store information about operators who are in the process of unbonding their keys in the genesis state. The key field uniquely identifies the combination of operator address and chainID.

The code changes are approved.

x/delegation/types/genesis.go (8)

34-61: LGTM!

The code changes are approved.


180-212: LGTM!

The code changes are approved.


214-254: LGTM!

The code changes are approved.


256-311: LGTM!

The code changes are approved.


313-361: LGTM!

The code changes are approved.


15-26: LGTM!

The code changes are approved.


29-31: LGTM!

The code changes are approved.


365-382: LGTM!

The code changes are approved.

testutil/utils.go (1)

136-174: LGTM!

The code changes are approved.

Also applies to: 257-271

x/operator/keeper/usd_value.go (6)

276-291: LGTM!

The code changes are approved.


303-318: LGTM!

The code changes are approved.


25-25: LGTM!

The code changes are approved.


60-60: LGTM!

The code changes are approved.


85-85: LGTM!

The code changes are approved.


97-97: LGTM!

The code changes are approved.

proto/exocore/delegation/v1/genesis.proto Show resolved Hide resolved
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: 10

Outside diff range and nitpick comments (4)
x/operator/types/genesis_test.go (1)

Line range hint 28-221: Great job on expanding the test suite!

The test suite now covers a wide range of scenarios related to the genesis state validation, including invalid operator addresses, duplicate entries, invalid consensus keys, and more. The test cases are well-defined and provide good coverage for the validation logic.

For future improvements, consider adding test cases for any remaining edge cases or scenarios that are not currently covered. Additionally, consider adding test cases for the positive scenarios to ensure that valid genesis states are accepted.

proto/exocore/assets/v1/query.proto (1)

7-7: New import added: genesis.proto.

The addition of the genesis.proto import suggests new functionalities or dependencies related to genesis data. Could you provide more context on how genesis.proto is being used in this module?

x/delegation/types/genesis.go (1)

125-125: Remove Extra Space in Error Message

There's an extra space between "state" and "for" in the error message, which could affect readability.

Apply this diff to correct the error message:

-    				"negative delegation state  for %s: %+v",
+    				"negative delegation state for %s: %+v",
x/operator/types/genesis.go (1)

513-547: Re-evaluate the validation flow in Validate function

The Validate function sequentially calls multiple validation functions. While this modular approach enhances readability, consider adding checks to ensure that data dependencies between these functions are intelligently handled. For instance, if ValidateOperators fails, subsequent validations relying on its output may also fail or cause unintended errors. Implementing early returns or conditional checks can improve robustness.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f5befcb and 6fe680e.

Files ignored due to path filters (9)
  • x/assets/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/assets/types/query.pb.go is excluded by !**/*.pb.go
  • x/assets/types/tx.pb.go is excluded by !**/*.pb.go
  • x/delegation/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/delegation/types/types/query.pb.go is excluded by !**/*.pb.go
  • x/delegation/types/types/query.pb.gw.go is excluded by !**/*.pb.gw.go
  • x/dogfood/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/operator/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/operator/types/tx.pb.go is excluded by !**/*.pb.go
Files selected for processing (69)
  • app/app.go (0 hunks)
  • app/ethtest_helper.go (4 hunks)
  • app/test_helpers.go (3 hunks)
  • cmd/exocored/root.go (4 hunks)
  • cmd/exocored/testnet.go (3 hunks)
  • local_node.sh (1 hunks)
  • precompiles/assets/tx.go (1 hunks)
  • precompiles/avs/query_test.go (2 hunks)
  • proto/exocore/assets/v1/genesis.proto (3 hunks)
  • proto/exocore/assets/v1/query.proto (4 hunks)
  • proto/exocore/assets/v1/tx.proto (2 hunks)
  • proto/exocore/delegation/v1/genesis.proto (2 hunks)
  • proto/exocore/dogfood/v1/genesis.proto (1 hunks)
  • proto/exocore/operator/v1/genesis.proto (1 hunks)
  • proto/exocore/operator/v1/tx.proto (1 hunks)
  • testutil/utils.go (6 hunks)
  • utils/utils.go (4 hunks)
  • utils/utils_test.go (1 hunks)
  • x/assets/keeper/client_chain_and_asset_test.go (1 hunks)
  • x/assets/keeper/client_chain_asset.go (2 hunks)
  • x/assets/keeper/genesis.go (3 hunks)
  • x/assets/keeper/keeper.go (1 hunks)
  • x/assets/keeper/operator_asset.go (1 hunks)
  • x/assets/keeper/staker_asset.go (2 hunks)
  • x/assets/keeper/staker_asset_test.go (1 hunks)
  • x/assets/types/errors.go (1 hunks)
  • x/assets/types/general.go (3 hunks)
  • x/assets/types/genesis.go (6 hunks)
  • x/assets/types/genesis_test.go (5 hunks)
  • x/assets/types/keys.go (3 hunks)
  • x/avs/keeper/avs.go (2 hunks)
  • x/avs/keeper/keeper.go (1 hunks)
  • x/avs/keeper/query.go (1 hunks)
  • x/avs/types/types.go (1 hunks)
  • x/delegation/keeper/delegation.go (2 hunks)
  • x/delegation/keeper/delegation_state.go (5 hunks)
  • x/delegation/keeper/genesis.go (1 hunks)
  • x/delegation/keeper/un_delegation_state.go (1 hunks)
  • x/delegation/types/errors.go (1 hunks)
  • x/delegation/types/genesis.go (2 hunks)
  • x/delegation/types/genesis_test.go (3 hunks)
  • x/delegation/types/keys.go (1 hunks)
  • x/dogfood/keeper/genesis.go (2 hunks)
  • x/dogfood/keeper/impl_epochs_hooks.go (1 hunks)
  • x/dogfood/keeper/impl_epochs_hooks_test.go (6 hunks)
  • x/dogfood/keeper/msg_server.go (1 hunks)
  • x/dogfood/keeper/opt_out_test.go (3 hunks)
  • x/dogfood/keeper/unbonding_test.go (4 hunks)
  • x/dogfood/types/expected_keepers.go (1 hunks)
  • x/dogfood/types/genesis.go (0 hunks)
  • x/operator/client/cli/tx.go (3 hunks)
  • x/operator/keeper/consensus_keys.go (5 hunks)
  • x/operator/keeper/genesis.go (2 hunks)
  • x/operator/keeper/keeper.go (1 hunks)
  • x/operator/keeper/operator.go (4 hunks)
  • x/operator/keeper/operator_info_test.go (3 hunks)
  • x/operator/keeper/operator_slash_state.go (1 hunks)
  • x/operator/keeper/opt_test.go (0 hunks)
  • x/operator/keeper/slash.go (10 hunks)
  • x/operator/keeper/slash_test.go (2 hunks)
  • x/operator/keeper/usd_value.go (13 hunks)
  • x/operator/keeper/usd_value_test.go (4 hunks)
  • x/operator/types/expected_keepers.go (2 hunks)
  • x/operator/types/genesis.go (2 hunks)
  • x/operator/types/genesis_test.go (6 hunks)
  • x/operator/types/keys.go (5 hunks)
  • x/operator/types/keys_test.go (1 hunks)
  • x/reward/keeper/claim_reward_test.go (1 hunks)
  • x/slash/keeper/execute_slash_test.go (1 hunks)
Files not reviewed due to no reviewable changes (3)
  • app/app.go
  • x/dogfood/types/genesis.go
  • x/operator/keeper/opt_test.go
Files skipped from review due to trivial changes (1)
  • proto/exocore/dogfood/v1/genesis.proto
Files skipped from review as they are similar to previous changes (49)
  • app/ethtest_helper.go
  • cmd/exocored/root.go
  • cmd/exocored/testnet.go
  • precompiles/assets/tx.go
  • precompiles/avs/query_test.go
  • proto/exocore/assets/v1/tx.proto
  • proto/exocore/operator/v1/tx.proto
  • utils/utils.go
  • utils/utils_test.go
  • x/assets/keeper/client_chain_and_asset_test.go
  • x/assets/keeper/client_chain_asset.go
  • x/assets/keeper/genesis.go
  • x/assets/keeper/keeper.go
  • x/assets/keeper/staker_asset_test.go
  • x/assets/types/errors.go
  • x/assets/types/general.go
  • x/assets/types/genesis.go
  • x/assets/types/genesis_test.go
  • x/assets/types/keys.go
  • x/avs/keeper/avs.go
  • x/avs/keeper/keeper.go
  • x/avs/keeper/query.go
  • x/avs/types/types.go
  • x/delegation/keeper/delegation.go
  • x/delegation/keeper/delegation_state.go
  • x/delegation/keeper/un_delegation_state.go
  • x/delegation/types/errors.go
  • x/delegation/types/keys.go
  • x/dogfood/keeper/genesis.go
  • x/dogfood/keeper/impl_epochs_hooks.go
  • x/dogfood/keeper/impl_epochs_hooks_test.go
  • x/dogfood/keeper/msg_server.go
  • x/dogfood/keeper/opt_out_test.go
  • x/dogfood/keeper/unbonding_test.go
  • x/dogfood/types/expected_keepers.go
  • x/operator/client/cli/tx.go
  • x/operator/keeper/consensus_keys.go
  • x/operator/keeper/keeper.go
  • x/operator/keeper/operator.go
  • x/operator/keeper/operator_info_test.go
  • x/operator/keeper/operator_slash_state.go
  • x/operator/keeper/slash.go
  • x/operator/keeper/slash_test.go
  • x/operator/keeper/usd_value_test.go
  • x/operator/types/expected_keepers.go
  • x/operator/types/keys.go
  • x/operator/types/keys_test.go
  • x/reward/keeper/claim_reward_test.go
  • x/slash/keeper/execute_slash_test.go
Additional context used
Learnings (2)
x/delegation/keeper/genesis.go (3)
Learnt from: TimmyExogenous
PR: ExocoreNetwork/exocore#108
File: x/delegation/keeper/genesis.go:52-73
Timestamp: 2024-09-17T14:45:22.028Z
Learning: In the `ExportGenesis` function, panicking on errors without additional logging is acceptable as panic provides detailed context for debugging.
Learnt from: TimmyExogenous
PR: ExocoreNetwork/exocore#108
File: x/delegation/keeper/genesis.go:34-47
Timestamp: 2024-09-17T14:44:23.781Z
Learning: In the `InitGenesis` function, panicking on errors without additional logging is acceptable as panic provides detailed context for debugging.
Learnt from: TimmyExogenous
PR: ExocoreNetwork/exocore#108
File: x/operator/keeper/genesis.go:63-96
Timestamp: 2024-09-17T14:46:25.700Z
Learning: In the `ExportGenesis` function, panicking on errors is acceptable because the node is offline during genesis export.
x/operator/keeper/genesis.go (3)
Learnt from: TimmyExogenous
PR: ExocoreNetwork/exocore#108
File: x/delegation/keeper/genesis.go:52-73
Timestamp: 2024-09-17T14:45:22.028Z
Learning: In the `ExportGenesis` function, panicking on errors without additional logging is acceptable as panic provides detailed context for debugging.
Learnt from: TimmyExogenous
PR: ExocoreNetwork/exocore#108
File: x/operator/keeper/genesis.go:63-96
Timestamp: 2024-09-17T14:46:25.700Z
Learning: In the `ExportGenesis` function, panicking on errors is acceptable because the node is offline during genesis export.
Learnt from: TimmyExogenous
PR: ExocoreNetwork/exocore#108
File: x/delegation/keeper/genesis.go:34-47
Timestamp: 2024-09-17T14:44:23.781Z
Learning: In the `InitGenesis` function, panicking on errors without additional logging is acceptable as panic provides detailed context for debugging.
buf
proto/exocore/assets/v1/genesis.proto

4-4: import "cosmos_proto/cosmos.proto": file does not exist

(COMPILE)

proto/exocore/delegation/v1/genesis.proto

5-5: import "exocore/delegation/v1/query.proto": file does not exist

(COMPILE)

GitHub Check: break-check
proto/exocore/assets/v1/query.proto

[failure] 48-48:
Field "1" on message "QueryAllStakingAssetsInfoResponse" changed type from "exocore.assets.v1.QueryAllStakingAssetsInfoResponse.AllStakingAssetsInfoEntry" to "exocore.assets.v1.StakingAssetInfo".


[failure] 60-60:
Field "1" on message "QueryAssetInfoResponse" changed type from "exocore.assets.v1.QueryAssetInfoResponse.AssetInfosEntry" to "exocore.assets.v1.DepositByAsset".


[failure] 80-80:
Field "1" on message "QueryOperatorAssetInfosResponse" changed type from "exocore.assets.v1.QueryOperatorAssetInfosResponse.AssetInfosEntry" to "exocore.assets.v1.AssetByID".

proto/exocore/delegation/v1/genesis.proto

[failure] 17-17:
Field "1" with name "associations" on message "GenesisState" changed option "json_name" from "delegations" to "associations".


[failure] 17-17:
Field "1" on message "GenesisState" changed type from "exocore.delegation.v1.DelegationsByStaker" to "exocore.delegation.v1.StakerToOperator".


[failure] 17-17:
Field "1" on message "GenesisState" changed name from "delegations" to "associations".


[failure] 19-19:
Field "2" with name "delegation_states" on message "GenesisState" changed option "json_name" from "associations" to "delegationStates".

Additional comments not posted (76)
x/delegation/keeper/genesis.go (2)

34-47: The error handling in this function has been previously discussed and accepted. Panicking on errors without additional logging is acceptable in the InitGenesis function as it provides detailed context for debugging.


52-73: The error handling in this function has been previously discussed and accepted. Panicking on errors without additional logging is acceptable in the ExportGenesis function as it provides detailed context for debugging.

x/operator/keeper/genesis.go (2)

10-55: LGTM!

The changes to the InitGenesis function are well-structured and improve the initialization logic for the operator module. Key improvements include:

  1. Defaulting the EarningsAddr to the OperatorAddress if not provided, ensuring all operators have a valid earnings address.
  2. Processing operator records more comprehensively by iterating through the OperatorRecords slice and setting consensus keys for each operator based on their chain details.
  3. Initializing various other state variables from the genesis state.

These enhancements facilitate better management of operator data during the genesis initialization phase.


58-98: Excellent refactoring of the ExportGenesis function!

The modifications to the ExportGenesis function significantly improve its structure, readability, and error handling. Notable enhancements include:

  1. Aligning the function signature with standard SDK practices by including a context parameter.
  2. Constructing a GenesisState object to aggregate various operator-related data points.
  3. Utilizing dedicated getter methods for retrieving each data point, promoting modularity and maintainability.
  4. Handling errors encountered during data retrieval by panicking with wrapped error messages, providing more informative error handling.

These changes contribute to a more robust and maintainable implementation of the genesis export functionality for the operator module.

proto/exocore/assets/v1/genesis.proto (6)

30-34: LGTM!

The addition of the operator_assets field to the GenesisState message is a crucial change for tracking assets by operator. The past review comment raised a valid concern about ensuring the proper handling of this field in the InitGenesis and ExportGenesis functions.

Since the developer has confirmed that the necessary handling has been implemented, I consider this concern resolved. Great work!


36-45: Excellent addition of the AssetsByOperator message type!

The introduction of the AssetsByOperator message type is a great enhancement for managing operator assets within the genesis state. It provides a clear and organized structure for associating an operator with their list of assets.

The use of the AssetByID message type for the assets_state field is also a smart choice, as it allows for efficient indexing of assets by their ID.

Overall, this addition improves the clarity and maintainability of the codebase. Well done!


47-54: Great addition of the AssetByID message type!

The introduction of the AssetByID message type is a helpful addition to be used in the genesis state. It provides a structured way to store the asset ID and its corresponding information for an operator.

The use of the OperatorAssetInfo message type for the info field is a good design choice, as it ensures that all relevant asset information is encapsulated within the AssetByID message.

This addition enhances the clarity and organization of the asset data within the genesis state. Nice work!


61-61: Minor change to the staker field.

The modification to the staker field in the DepositsByStaker message is a minor change that adds a custom name annotation using the gogoproto extension. This annotation allows for customizing the generated Go code for this field, specifically setting the field name to StakerID.

This change does not have any significant impact on the functionality or behavior of the code. It's a small adjustment for code generation purposes.


74-74: Minor formatting change.

The modification to the DepositByAsset message is a minor formatting change that removes extra spaces before the message name. This change does not have any impact on the functionality or behavior of the code.

It is purely a cosmetic adjustment to improve code readability and consistency. Good catch!


76-76: Minor change to the asset_id field.

The modification to the asset_id field in the DepositByAsset message is a minor change that adds a custom name annotation using the gogoproto extension. This annotation allows for customizing the generated Go code for this field, specifically setting the field name to AssetID.

This change does not have any significant impact on the functionality or behavior of the code. It's a small adjustment for code generation purposes.

x/assets/keeper/staker_asset.go (2)

14-45: LGTM!

The AllDeposits function looks good. It efficiently retrieves all deposits grouped by staker ID using a prefix iterator. The logic for grouping deposits by staker ID and constructing the result slice is correct. The error handling and defer of iterator close follow best practices.


Line range hint 47-66: Looks good!

The modifications to the GetStakerAssetInfos function are appropriate. Changing the return type from a map to a slice simplifies the code and aligns with the new data structure for representing asset infos. The internal logic has been correctly updated to construct and return a slice of DepositByAsset. The error handling and defer of iterator close remain in place.

x/operator/types/genesis_test.go (8)

Line range hint 52-58: LGTM!

The test case correctly checks for an invalid operator address in the genesis state and expects the validation to fail.


Line range hint 63-73: LGTM!

The test case correctly checks for duplicate operator addresses in the genesis state and expects the validation to fail.


Line range hint 77-99: LGTM!

The test case correctly checks for duplicate lz chain ids in the client chain earning address list and expects the validation to fail.


100-115: LGTM!

The test case correctly checks for an invalid operator address in the consensus key records and expects the validation to fail.


116-131: LGTM!

The test case correctly checks for an unregistered operator in the consensus key records and expects the validation to fail.


132-165: LGTM!

The test case correctly checks for duplicate operators in the consensus key records and expects the validation to fail.


166-187: LGTM!

The test case correctly checks for an invalid consensus key in the consensus key records and expects the validation to fail.


188-221: LGTM!

The test case correctly checks for duplicate consensus keys for the same chain id in the consensus key records and expects the validation to fail.

x/assets/keeper/operator_asset.go (2)

14-44: LGTM!

The AllOperatorAssets function correctly retrieves all operator assets from the store and groups them by operator. It handles errors appropriately and returns the expected slice of AssetsByOperator.


46-52: LGTM!

The modifications to the GetOperatorAssetInfos function, including the change in return type from a map to a slice of AssetByID, are implemented correctly. The internal logic has been updated appropriately to use an append operation to build the result slice, and the function returns the expected slice of AssetByID.

x/delegation/types/genesis_test.go (12)

33-42: LGTM!

The changes to the genesis state structure, specifically the introduction of DelegationStates and StakersByOperator, are correctly implemented in the test setup.


70-70: LGTM!

The NewGenesis function call has been updated to use the new genesis state structure, which is correct.


78-82: LGTM!

The malleate and unmalleate functions for the "invalid staker id" test case have been correctly updated to modify the new genesis state structure.


86-95: LGTM!

The new "duplicate state key" test case is a valid addition to ensure that the genesis state validation logic catches duplicate entries in the DelegationStates slice.


98-107: LGTM!

The malleate and unmalleate functions for the "invalid asset id" test case have been correctly updated to modify the new genesis state structure.


110-122: LGTM!

The malleate and unmalleate functions for the "asset id mismatch" test case have been correctly updated to modify the new genesis state structure.


124-133: LGTM!

The new "nil wrapped undelegatable share" test case is a valid addition to ensure that the genesis state validation logic catches nil values for the UndelegatableShare field in the DelegationAmounts struct.


135-144: LGTM!

The new "nil wrapped unbonding amount" test case is a valid addition to ensure that the genesis state validation logic catches nil values for the WaitUndelegationAmount field in the DelegationAmounts struct.


146-155: LGTM!

The new "negative wrapped undelegatable share" test case is a valid addition to ensure that the genesis state validation logic catches negative values for the UndelegatableShare field in the DelegationAmounts struct.


158-167: LGTM!

The malleate and unmalleate functions for the "invalid operator address" test case have been correctly updated to modify the new genesis state structure.


Line range hint 170-182: LGTM!

The new "duplicate stakerID in associations" test case is a valid addition to ensure that the genesis state validation logic catches duplicate entries in the Associations slice.


Line range hint 185-195: LGTM!

The new "one stakerID in associations" test case is a valid addition to ensure that the genesis state validation logic allows a single entry in the Associations slice.

proto/exocore/operator/v1/genesis.proto (10)

15-15: ** Field type change in GenesisState requires careful consideration.**

The change from OperatorInfo to OperatorDetail in the GenesisState message indicates a more detailed structuring of operator data. This change could affect serialization and deserialization logic, so ensure all dependent code is updated.


23-43: New fields in GenesisState enhance the data model.

The addition of several new fields, such as operator_records, opt_states, avs_usd_values, operator_usd_values, slash_states, pre_cons_keys, and operator_key_removals, allows for more comprehensive tracking of operator and AVS data. This expansion reflects a substantial enhancement in the data model, enabling more robust handling of operator-related information.


48-54: OperatorDetail message provides a structured way to store operator information.

The introduction of the OperatorDetail message is a good design choice. It encapsulates the operator's address and detailed information (OperatorInfo) in a modular and reusable manner, enhancing the overall structure of the genesis state.


58-64: OptedState message efficiently stores opted state information.

The OptedState message is well-designed, using a composite key (key field) to store the combination of operator address and AVS address. This allows for efficient lookup and retrieval of opted state data. The opt_info field, of type OptedInfo, encapsulates the details of the opted state, promoting a modular and maintainable structure.


68-73: AVSUSDValue message effectively stores USD value for AVS addresses.

The AVSUSDValue message is a suitable choice for storing USD value information associated with an AVS address (avs_addr field). The use of DecValueField for the value field allows for precise storage of decimal values, ensuring accurate representation of USD values.


77-86: OperatorUSDValue message efficiently stores USD value for operator and AVS combinations.

The OperatorUSDValue message is well-structured, using a composite key (key field) to store the combination of operator and AVS address. This enables efficient lookup and retrieval of USD value data for specific operator and AVS pairs. The opted_usd_value field, of type OperatorOptedUSDValue, encapsulates the details of the opted USD value, promoting a modular and maintainable design.


90-96: OperatorSlashState message efficiently stores slash information.

The OperatorSlashState message is well-designed, using a composite key (key field) to store the combination of operator address, AVS address, and slashID. This allows for efficient lookup and retrieval of slash state data. The info field, of type OperatorSlashInfo, encapsulates the details of the slash information, promoting a modular and maintainable structure.


101-109: PrevConsKey message efficiently stores previous consensus key information.

The PrevConsKey message is well-structured, using a composite key (key field) to store the combination of chainID and operator address. This enables efficient lookup and retrieval of previous consensus key data. The consensus_key field stores the hex-encoded 32-byte consensus key value.

Ensure that the length of the consensus_key is exactly 32 bytes and is enforced outside of protobuf, as mentioned in the comments.


114-117: OperatorKeyRemoval message efficiently stores operator key removal information.

The OperatorKeyRemoval message is well-designed, using a composite key (key field) to store the combination of operator address and chainID. This allows for efficient lookup and retrieval of information about operators in the process of unbonding their keys for specific chainIDs.


121-137: OperatorConsKeyRecord and ChainDetails messages provide a modular structure for storing operator and chain information.

The introduction of the OperatorConsKeyRecord and ChainDetails messages as helper structures for the genesis state is a good design choice. The OperatorConsKeyRecord message encapsulates the operator address and a list of associated chain details, while the ChainDetails message contains the chain id and consensus key information. This modular structure promotes maintainability and reusability of the codebase.

app/test_helpers.go (3)

219-239: LGTM!

The changes to the assets module initialization improve the organization and clarity of asset management by:

  • Using AssetBasicInfo directly instead of a pointer, which may improve performance by reducing indirection.
  • Introducing a new structure AssetsByOperator to encapsulate operator-specific asset states, including total amounts and shares.

243-253: LGTM!

The changes to the operator module initialization enhance the clarity and organization of operator data by:

  • Using OperatorDetail instead of OperatorInfo, reflecting a more comprehensive encapsulation of operator data.
  • Adding the OperatorAddress field to provide clearer identification of the operator.
  • Nesting the existing fields within an OperatorInfo structure to promote better organization of related data.

Line range hint 256-280: LGTM!

The changes to the delegation module initialization simplify the representation of delegation states and enhance the clarity of the delegation logic by:

  • Replacing the DelegationsByStaker structure with DelegationStates, which consolidates related fields.
  • Introducing StakersByOperator to allow for a more structured approach to managing staker information associated with operators.
local_node.sh (6)

98-99: LGTM!

The changes correctly configure the token address and chain ID for the assets module in the genesis state.


100-100: LGTM!

The change correctly initializes the total staking amount for the token in the genesis state.


106-111: LGTM!

The changes correctly initialize a new operator asset entry with the specified operator address and asset ID. The asset state values are being initialized appropriately.


118-123: LGTM!

The changes correctly configure the operator address, earnings address, meta info, and commission rates for the first operator entry. Setting the commission rates to 0.0 effectively disables commissions for this operator.


126-128: LGTM!

The changes correctly initialize a new delegation state entry with the specified key. The undelegatable_share is set to 5000, indicating the initial delegation amount, and the wait_undelegation_amount is set to 0, indicating no pending undelegations.


131-132: LGTM!

The changes correctly initialize a new entry in the stakers_by_operator field, which maps operators and assets to their associated stakers. The specified staker ID is being added to the list of stakers for the given operator and asset.

x/operator/keeper/usd_value.go (11)

Line range hint 25-57: LGTM!

The function correctly updates the USD share for the specified operator and AVS based on the provided delta values. The error handling and store interactions are implemented properly.


Line range hint 60-78: LGTM!

The function correctly initializes the USD value for the specified operator and AVS if it doesn't already exist in the store. The error handling and store interactions are implemented properly.


Line range hint 85-94: LGTM!

The function correctly deletes the USD share related to the specified operator and AVS from the store. The error handling for empty operatorAddr is implemented properly.


Line range hint 97-105: LGTM!

The function correctly deletes all operators' USD values for the specified AVS by iterating over the keys with the AVS prefix and deleting each key-value pair from the store. The iterator is properly closed using defer.


Line range hint 123-136: LGTM!

The function correctly retrieves the USD share of the specified operator and AVS. It handles the case when the operator has not opted-in by returning zero values. The error handling for empty operatorAddr and missing key in the store is implemented properly.


Line range hint 149-163: LGTM!

The function correctly updates the total USD share of the specified AVS based on the provided opAmount. The error handling and store interactions are implemented properly.


Line range hint 171-177: LGTM!

The function correctly sets the total USD share of the specified AVS using the provided amount. The error handling for nil amount is implemented properly.


Line range hint 180-184: LGTM!

The function correctly deletes the USD share of the specified AVS from the store using the avsAddr as the key.


Line range hint 192-203: LGTM!

The function correctly retrieves the USD share of the specified AVS from the store using the avsAddr as the key. The error handling for missing key in the store is implemented properly.


Line range hint 208-230: LGTM!

The function correctly iterates over the operators of the specified AVS, unmarshals the values, and calls the provided opFunc for each operator. If isUpdate is true, it updates the values back in the store. The iterator is properly closed using defer, and error handling is implemented for any errors encountered during the iteration process.


Line range hint 234-249: LGTM!

The function correctly retrieves the vote power for the specified chain ID by checking if it corresponds to an AVS and retrieving the OperatorOptedUSDValue for each operator. The truncation of ActiveUSDValue to int64 and error handling for unknown chain ID and retrieval errors are implemented properly.

proto/exocore/delegation/v1/genesis.proto (2)

26-34: Definition of DelegationStates message is appropriate

The introduction of the DelegationStates message enhances the data model, and the fields are well-documented. This addition aligns with the goal of providing more detailed tracking of delegation states.


36-43: Definition of StakersByOperator message is well-structured

The StakersByOperator message is correctly defined to store the list of stakers for each operator. The clear documentation aids in understanding its purpose within the genesis state.

x/delegation/types/genesis.go (2)

227-227: Correct Non-Standard Colon Character in Error Message

The error message uses a non-standard colon character ':' (full-width colon) instead of the standard ':' (colon). This might cause issues in log parsing or display.

Apply this diff to correct the colon character:

-    				ErrInvalidGenesisData, "the block number to complete shouldn't be less than the submitted , undelegation:%v",
+    				ErrInvalidGenesisData, "the block number to complete shouldn't be less than the submitted , undelegation:%v",

Likely invalid or redundant comment.


233-233: Correct Non-Standard Colon Character in Error Message

The error message uses a non-standard colon character ':' (full-width colon) instead of the standard ':' (colon). This might cause issues in log parsing or display.

Apply this diff to correct the colon character:

-    				ErrInvalidGenesisData, "the completed amount shouldn't be greater than the submitted amount , undelegation:%v",
+    				ErrInvalidGenesisData, "the completed amount shouldn't be greater than the submitted amount , undelegation:%v",

Likely invalid or redundant comment.

testutil/utils.go (8)

7-8: Import statement for avstypes added correctly.

The addition of the avstypes import is appropriate and necessary for the subsequent code changes.


140-179: Initialization of operatorAssets is properly structured.

The operatorAssets slice is correctly initialized with the relevant operator information and asset states. The data aligns with the expected genesis configuration.


207-223: operatorInfos are correctly initialized.

The operatorInfos slice accurately captures the operator details, including addresses and commission settings.


231-247: operatorConsKeys are set appropriately.

The consensus keys for each operator are correctly assigned, ensuring proper validation and consensus operations.


252-286: Initialization of optStates and operatorUSDValues is accurate.

The optStates and operatorUSDValues slices are properly populated, reflecting the operators' opted-in statuses and their respective USD values.


287-296: avsUSDValues and operatorGenesis are configured correctly.

The total USD value for the AVS address is accurately calculated, and the operatorGenesis state is constructed with all necessary components.


298-314: delegationStates initialization is sound.

The delegationStates slice correctly represents the delegation amounts for each staker-operator pair, ensuring accurate tracking of undelegatable shares.


325-338: stakersByOperator slice is properly set up.

The mapping of stakers to operators is accurately established, facilitating correct delegation relationships.

proto/exocore/assets/v1/query.proto Show resolved Hide resolved
proto/exocore/assets/v1/query.proto Show resolved Hide resolved
proto/exocore/assets/v1/query.proto Show resolved Hide resolved
// associations represents the association between a staker and an operator.
repeated StakerToOperator associations = 2 [(gogoproto.nullable) = false];
repeated StakerToOperator associations = 1 [(gogoproto.nullable) = false];
Copy link
Contributor

Choose a reason for hiding this comment

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

Changing field numbers and types may cause backward compatibility issues

Changing field number 1 in GenesisState from delegations of type DelegationsByStaker to associations of type StakerToOperator can lead to backward compatibility problems. Reusing field numbers with different types or names in Protocol Buffers may cause old clients or persisted data to misinterpret the data.

Consider assigning a new, unused field number to the associations field and deprecate the old delegations field if necessary. This approach preserves backward compatibility and prevents potential deserialization issues.

Tools
GitHub Check: break-check

[failure] 17-17:
Field "1" with name "associations" on message "GenesisState" changed option "json_name" from "delegations" to "associations".


[failure] 17-17:
Field "1" on message "GenesisState" changed type from "exocore.delegation.v1.DelegationsByStaker" to "exocore.delegation.v1.StakerToOperator".


[failure] 17-17:
Field "1" on message "GenesisState" changed name from "delegations" to "associations".

proto/exocore/delegation/v1/genesis.proto Show resolved Hide resolved
x/delegation/types/genesis.go Show resolved Hide resolved
testutil/utils.go Show resolved Hide resolved
x/operator/types/genesis.go Show resolved Hide resolved
x/operator/types/genesis.go Show resolved Hide resolved
x/operator/types/genesis.go Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment