Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: captains genesis and key naming. #39

Merged
merged 4 commits into from
May 17, 2024

Conversation

towerkyoto
Copy link
Contributor

@towerkyoto towerkyoto commented May 17, 2024

This PR refactors genesis export/import logic of cpatains module. It also renames key and related functions for better readability.

Summary by CodeRabbit

  • New Features

    • Introduced new messages for managing computing power, emissions, and pledges.
    • Added new functions for cumulative and claimed emissions.
  • Bug Fixes

    • Improved clarity and consistency in function and message naming.
  • Refactor

    • Renamed multiple functions and messages for better readability and consistency.
    • Updated key generation functions and constants for data storage.
  • Tests

    • Updated test cases to reflect new function names and structures.
    • Improved test case clarity and structure.
  • Chores

    • Enhanced validation functions for various data entities.
    • Adjusted the order and definitions of default parameters.

Copy link
Contributor

coderabbitai bot commented May 17, 2024

Walkthrough

The recent updates introduce significant restructuring and renaming across various components of the captains and claims modules. Key changes include renaming messages and functions related to emissions, computing power, and pledges to enhance clarity and consistency. New messages and validation functions have been added, and test cases have been updated to reflect these changes. Overall, the updates aim to improve the codebase's readability and maintainability.

Changes

Files/Paths Change Summary
proto/tabi/captains/v1/captains.proto Renamed and added messages related to emissions, computing power, and pledges.
proto/tabi/captains/v1/genesis.proto Added new fields to GenesisState message.
proto/tabi/captains/v1/report.proto Added a new message BatchBase for batch information.
x/captains/exported/exported.go Renamed and redefined methods in the Captains interface.
x/captains/keeper/abci.go Renamed functions related to computing power and epoch data management.
x/captains/keeper/computing_power.go Renamed and updated functions related to computing power sums and claimable computing power.
x/captains/keeper/emission.go Renamed key names and functions associated with emission calculations and management.
x/captains/keeper/epoch.go Renamed function setEndEpoch to setEndOnEpoch.
x/captains/keeper/genesis.go Updated ExportGenesis and added new functions for BaseState.
x/captains/keeper/grpc_query.go Renamed CalcNodeHistoricalEmissionByEpoch to CalcNodeCumulativeEmissionByEpoch.
x/captains/keeper/integration_test.go Updated method calls in test scenarios to reflect new names.
x/captains/keeper/msg_server.go Modified function call m.k.CommitComputingPower and updated return values.
x/captains/keeper/nodes.go Renamed functions related to claimable computing power and removed some functions.
x/captains/keeper/pledge_ratio.go Renamed functions related to emission and pledge sums, added new functions for global and owner pledges.
x/captains/keeper/pledge_ratio_test.go Renamed functions in test cases related to emission and pledge sums.
x/captains/keeper/report.go Renamed functions related to pledge sums, report digest, and cumulative emissions.
x/captains/types/genesis.go Updated NewGenesisState and DefaultGenesisState, added new validation functions.
x/captains/types/genesis_test.go Updated test cases with new names and structure.
x/captains/types/keys.go Updated key generation functions and constants for storage operations.
x/captains/types/params.go Moved and redefined the DefaultParams function.
x/claims/keeper/claims.go Updated method calls related to historical and claimed emissions.
x/claims/keeper/mock_captains_test.go Renamed functions in MockCaptains struct related to cumulative and claimed emissions.
x/claims/types/expected_keepers.go Renamed and redefined functions related to node emission calculations and updates in CaptainsKeeper interface.

In the land of code, where captains steer,
Emissions and pledges now crystal clear.
Nodes and epochs, computing might,
Renamed and structured, shining bright.
A rabbit's joy, in lines so neat,
Hopping through changes, a coder's feat! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

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

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

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • 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.

@sheldonleedev
Copy link

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented May 17, 2024

Actions Performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 8

Out of diff range and nitpick comments (2)
x/captains/keeper/computing_power.go (1)

96-100: Consider using atomic operations for thread safety.

The function CommitComputingPower modifies the claimable computing power in a non-atomic way, which could lead to race conditions in a concurrent environment. Consider using atomic operations or transactional mechanisms provided by the datastore if applicable.

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

Line range hint 70-122: Validate the DefaultDivision function and ensure it meets future requirements.

The TODO comment suggests that the default computing power bounds need to be updated. It would be beneficial to address this to ensure the defaults remain relevant.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between dc2d8a5 and d844a82.
Files ignored due to path filters (3)
  • x/captains/types/captains.pb.go is excluded by !**/*.pb.go
  • x/captains/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/captains/types/report.pb.go is excluded by !**/*.pb.go
Files selected for processing (24)
  • proto/tabi/captains/v1/captains.proto (1 hunks)
  • proto/tabi/captains/v1/genesis.proto (1 hunks)
  • proto/tabi/captains/v1/report.proto (1 hunks)
  • x/captains/exported/exported.go (1 hunks)
  • x/captains/keeper/abci.go (1 hunks)
  • x/captains/keeper/computing_power.go (2 hunks)
  • x/captains/keeper/emission.go (3 hunks)
  • x/captains/keeper/epoch.go (2 hunks)
  • x/captains/keeper/genesis.go (1 hunks)
  • x/captains/keeper/genesis_test.go (1 hunks)
  • x/captains/keeper/grpc_query.go (1 hunks)
  • x/captains/keeper/integration_test.go (16 hunks)
  • x/captains/keeper/msg_server.go (1 hunks)
  • x/captains/keeper/nodes.go (3 hunks)
  • x/captains/keeper/pledge_ratio.go (4 hunks)
  • x/captains/keeper/pledge_ratio_test.go (2 hunks)
  • x/captains/keeper/report.go (8 hunks)
  • x/captains/types/genesis.go (3 hunks)
  • x/captains/types/genesis_test.go (2 hunks)
  • x/captains/types/keys.go (7 hunks)
  • x/captains/types/params.go (2 hunks)
  • x/claims/keeper/claims.go (2 hunks)
  • x/claims/keeper/mock_captains_test.go (3 hunks)
  • x/claims/types/expected_keepers.go (1 hunks)
Files skipped from review due to trivial changes (2)
  • x/captains/keeper/genesis_test.go
  • x/claims/keeper/mock_captains_test.go
Additional comments not posted (68)
x/captains/keeper/abci.go (2)

11-11: Ensure that the deletion of global computing power for the previous epoch is correctly handled in all relevant parts of the application.

Verification successful

The function delGlobalComputingPowerOnEpoch is correctly implemented to delete the global computing power for a given epoch from the key-value store. It is invoked in x/captains/keeper/abci.go to handle the deletion of computing power for the previous epoch.

  • x/captains/keeper/computing_power.go:37-41: Implementation of delGlobalComputingPowerOnEpoch.
  • x/captains/keeper/abci.go:11: Invocation of delGlobalComputingPowerOnEpoch.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the deletion of global computing power is correctly handled.
# Test: Search for the function usage. Expect: Proper handling in all relevant parts.
rg --type python $'delGlobalComputingPowerOnEpoch'

Length of output: 80



Script:

#!/bin/bash
# Description: Verify that the deletion of global computing power is correctly handled.
# Test: Search for the function usage. Expect: Proper handling in all relevant parts.
rg --type go 'delGlobalComputingPowerOnEpoch'

Length of output: 359



Script:

#!/bin/bash
# Description: Extract the implementation of delGlobalComputingPowerOnEpoch.
# Test: Ensure the function correctly handles the deletion of global computing power.
rg --type go --context 10 'func (k Keeper) delGlobalComputingPowerOnEpoch' x/captains/keeper/computing_power.go

Length of output: 113



Script:

#!/bin/bash
# Description: Extract the implementation of delGlobalComputingPowerOnEpoch using ast-grep.
# Test: Ensure the function correctly handles the deletion of global computing power.
ast-grep --lang go --pattern $'func (k Keeper) delGlobalComputingPowerOnEpoch($_, $_) {
  $$$
}' x/captains/keeper/computing_power.go

Length of output: 530


14-14: Ensure that the deletion of report digest is correctly handled in all relevant parts of the application.

x/captains/exported/exported.go (3)

17-18: Ensure that the new method CalcAndGetNodeCumulativeEmissionByEpoch is implemented correctly and used consistently across the application.

Verification successful

The method CalcAndGetNodeCumulativeEmissionByEpoch is implemented and used consistently across the codebase. Here are the relevant locations:

  • Declaration: x/captains/exported/exported.go
  • Implementation: x/captains/keeper/emission.go
  • Usage: x/claims/keeper/claims.go
  • Mock for testing: x/claims/keeper/mock_captains_test.go

This confirms that the method is correctly integrated into the application.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the new method is implemented and used consistently.
# Test: Search for the function implementation and usage. Expect: Consistent implementation and usage.
rg --type python $'CalcAndGetNodeCumulativeEmissionByEpoch'

Length of output: 89



Script:

#!/bin/bash
# Description: Verify that the new method is implemented and used consistently.
# Test: Search for the function implementation and usage. Expect: Consistent implementation and usage.
rg --type go 'CalcAndGetNodeCumulativeEmissionByEpoch'

Length of output: 1179


20-21: Ensure that the new method GetNodeClaimedEmission is implemented correctly and used consistently across the application.

Verification successful

The method GetNodeClaimedEmission is implemented and used consistently across the codebase

The method GetNodeClaimedEmission is implemented in x/captains/keeper/emission.go and is used in multiple files, including x/captains/keeper/emission.go, x/claims/types/expected_keepers.go, and x/claims/keeper/claims.go. This confirms that the method is implemented and used consistently across the application.

  • Implementation:

    • x/captains/keeper/emission.go: func (k Keeper) GetNodeClaimedEmission(ctx sdk.Context, nodeID string) sdk.Dec
  • Usage:

    • x/captains/keeper/emission.go
    • x/claims/types/expected_keepers.go
    • x/claims/keeper/claims.go
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the new method is implemented and used consistently.
# Test: Search for the function implementation and usage. Expect: Consistent implementation and usage.
rg --type python $'GetNodeClaimedEmission'

Length of output: 72



Script:

#!/bin/bash
# Description: Verify that the new method is implemented and used consistently.
# Test: Search for the function implementation and usage. Expect: Consistent implementation and usage.

# Search for the implementation of GetNodeClaimedEmission in Go files
ast-grep --lang go --pattern 'func ($_ GetNodeClaimedEmission) $_' 

# Search for the usage of GetNodeClaimedEmission in Go files
rg 'GetNodeClaimedEmission' --type go

Length of output: 1391


23-24: Ensure that the new method UpdateGlobalAndNodeClaimedEmission is implemented correctly and used consistently across the application.

Verification successful

The method UpdateGlobalAndNodeClaimedEmission is implemented and used consistently across the codebase. Here are the relevant locations:

  • Implementation:

    • x/captains/keeper/emission.go: func (k Keeper) UpdateGlobalAndNodeClaimedEmission(ctx sdk.Context, nodeID string) error
  • References:

    • x/captains/exported/exported.go
    • x/claims/types/expected_keepers.go
    • x/claims/keeper/mock_captains_test.go
    • x/claims/keeper/claims.go
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the new method is implemented and used consistently.
# Test: Search for the function implementation and usage. Expect: Consistent implementation and usage.
rg --type python $'UpdateGlobalAndNodeClaimedEmission'

Length of output: 84



Script:

#!/bin/bash
# Description: Verify that the new method is implemented and used consistently.
# Test: Search for the function implementation and usage. Expect: Consistent implementation and usage.

# Search for the implementation of the method in Go files
rg --type go 'func UpdateGlobalAndNodeClaimedEmission'

# Search for the usage of the method in Go files
rg --type go 'UpdateGlobalAndNodeClaimedEmission'

Length of output: 1183

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

20-52: Ensure that the new test cases for the genesis state validation are comprehensive and cover all new fields and scenarios introduced in the genesis state.

Verification successful

The test cases in x/captains/types/genesis_test.go appear to cover various scenarios for the genesis state validation, including both successful and failure cases. The test cases include:

  • Default genesis state validation.
  • Base state validation with specific parameters.

These test cases seem to address different aspects of the genesis state, ensuring that both valid and invalid states are tested.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the test cases are comprehensive.
# Test: Review the test cases and ensure they cover all scenarios.
rg --type python $'TestValidateGenesis'

Length of output: 69



Script:

#!/bin/bash
# Description: Verify that the test cases are comprehensive.
# Test: Review the test cases and ensure they cover all scenarios.
rg --type go 'func Test' --context 10

Length of output: 94900

x/captains/keeper/epoch.go (1)

32-33: Ensure that the new method setEndOnEpoch is implemented correctly and used consistently across the application.

Verification successful

The function setEndOnEpoch is implemented in epoch.go and used in both report.go and genesis.go. The context around its usage in these files indicates that it is being used consistently to mark the end of an epoch.

  • In genesis.go, it is called within the SetBaseState method when bs.IsEpochEnd is true.
  • In report.go, it is called to mark readiness for the next epoch after checking if the report is completed.

These usages align with the intended purpose of setting the end epoch.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the new method is implemented and used consistently.
# Test: Search for the function implementation and usage. Expect: Consistent implementation and usage.
rg --type python $'setEndOnEpoch'

Length of output: 63



Script:

#!/bin/bash
# Description: Verify that the new method is implemented and used consistently.
# Test: Search for the function implementation and usage. Expect: Consistent implementation and usage.
rg --type go 'setEndOnEpoch'

Length of output: 307



Script:

#!/bin/bash
# Extract lines around the usage of setEndOnEpoch in report.go and genesis.go for context.
rg --type go --context 5 'setEndOnEpoch' x/captains/keeper/report.go x/captains/keeper/genesis.go

Length of output: 1340

proto/tabi/captains/v1/genesis.proto (1)

5-39: Ensure that the new protobuf definitions for the genesis state are correctly implemented and used consistently across the application.

proto/tabi/captains/v1/report.proto (1)

62-67: Ensure that the new protobuf definition BatchBase is correctly implemented and used consistently across the application.

Verification successful

BatchBase is implemented and used consistently across the codebase

The BatchBase protobuf definition is correctly implemented and used in various parts of the codebase, including:

  • x/captains/types/report.pb.go
  • x/captains/types/genesis.pb.go
  • x/captains/types/genesis.go
  • x/captains/keeper/report.go
  • proto/tabi/captains/v1/genesis.proto
  • proto/tabi/captains/v1/report.proto

These references indicate that the BatchBase message is integrated and utilized as expected.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the new protobuf definition is implemented and used consistently.
# Test: Search for the protobuf usage. Expect: Consistent implementation and usage.
rg --type python $'BatchBase'

Length of output: 59



Script:

#!/bin/bash
# Description: Verify that the new protobuf definition is implemented and used consistently.
# Test: Search for the protobuf usage. Expect: Consistent implementation and usage.
rg --type py 'BatchBase'

Length of output: 173



Script:

#!/bin/bash
# Description: Verify that the new protobuf definition is implemented and used consistently.
# Test: Search for the protobuf usage. Expect: Consistent implementation and usage.
rg 'BatchBase'

Length of output: 2758

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

38-38: Ensure that the new method UpdateGlobalAndNodeClaimedEmission is implemented correctly and used consistently across the application.

Verification successful

Implementation and Usage of UpdateGlobalAndNodeClaimedEmission Verified

The method UpdateGlobalAndNodeClaimedEmission is implemented and used consistently across the codebase. Here are the relevant locations:

  • Implementation:

    • x/captains/keeper/emission.go: The method is implemented in the Keeper struct.
    • x/claims/keeper/mock_captains_test.go: A mock implementation for testing purposes.
  • Usage:

    • x/claims/keeper/claims.go: The method is called within the claims processing logic.
    • x/captains/exported/exported.go: The method is declared in an interface.
    • x/claims/types/expected_keepers.go: The method is declared in an interface.

The method is correctly implemented and used in the appropriate contexts, ensuring that node emissions are updated as expected.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the new method is implemented and used consistently.
# Test: Search for the function implementation and usage. Expect: Consistent implementation and usage.
rg --type python $'UpdateGlobalAndNodeClaimedEmission'

Length of output: 84



Script:

#!/bin/bash
# Description: Verify that the new method is implemented and used consistently.
# Test: Search for the function implementation and usage. Expect: Consistent implementation and usage.
rg --type go 'UpdateGlobalAndNodeClaimedEmission'

Length of output: 1126



Script:

#!/bin/bash
# Extract the implementation and usage of the method for detailed review.
rg --type go --context 5 'UpdateGlobalAndNodeClaimedEmission' x/captains/keeper/emission.go x/claims/keeper/mock_captains_test.go x/claims/keeper/claims.go x/captains/exported/exported.go x/claims/types/expected_keepers.go

Length of output: 4315


75-77: Ensure that the new methods CalcAndGetNodeCumulativeEmissionByEpoch and GetNodeClaimedEmission are implemented correctly and used consistently across the application.

Verification successful

The methods CalcAndGetNodeCumulativeEmissionByEpoch and GetNodeClaimedEmission are implemented and used consistently across the codebase. Here are the relevant locations:

  • Implementation:

    • x/captains/exported/exported.go
    • x/captains/keeper/emission.go
  • Usage:

    • x/claims/keeper/claims.go
    • x/claims/keeper/mock_captains_test.go
    • x/claims/types/expected_keepers.go

These methods are correctly implemented and used consistently across the application.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the new methods are implemented and used consistently.
# Test: Search for the function implementation and usage. Expect: Consistent implementation and usage.
rg --type python $'CalcAndGetNodeCumulativeEmissionByEpoch|GetNodeClaimedEmission'

Length of output: 114



Script:

#!/bin/bash
# Description: Verify that the new methods are implemented and used consistently.
# Test: Search for the function implementation and usage. Expect: Consistent implementation and usage.
rg --type go 'CalcAndGetNodeCumulativeEmissionByEpoch|GetNodeClaimedEmission'

Length of output: 2489

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

62-69: Ensure that the new methods CalcAndGetNodeCumulativeEmissionByEpoch, GetNodeClaimedEmission, and UpdateGlobalAndNodeClaimedEmission are implemented correctly and used consistently across the application.

Verification successful

The new methods CalcAndGetNodeCumulativeEmissionByEpoch, GetNodeClaimedEmission, and UpdateGlobalAndNodeClaimedEmission are implemented and used consistently across the codebase. The implementations are found in x/captains/keeper/emission.go, and they are used in x/claims/keeper/claims.go. Additionally, they are defined in x/captains/exported/exported.go and mocked in x/claims/keeper/mock_captains_test.go.

  • CalcAndGetNodeCumulativeEmissionByEpoch: Implemented in x/captains/keeper/emission.go and used in x/claims/keeper/claims.go.
  • GetNodeClaimedEmission: Implemented in x/captains/keeper/emission.go and used in x/claims/keeper/claims.go.
  • UpdateGlobalAndNodeClaimedEmission: Implemented in x/captains/keeper/emission.go and used in x/claims/keeper/claims.go.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the new methods are implemented and used consistently.
# Test: Search for the function implementation and usage. Expect: Consistent implementation and usage.
rg --type python $'CalcAndGetNodeCumulativeEmissionByEpoch|GetNodeClaimedEmission|UpdateGlobalAndNodeClaimedEmission'

Length of output: 149



Script:

#!/bin/bash
# Description: Verify that the new methods are implemented and used consistently.
# Test: Search for the function implementation and usage. Expect: Consistent implementation and usage.
rg --type go 'CalcAndGetNodeCumulativeEmissionByEpoch|GetNodeClaimedEmission|UpdateGlobalAndNodeClaimedEmission'

Length of output: 3601

x/captains/types/params.go (1)

43-55: The updated default parameters in DefaultParams are clear and well-defined.

x/captains/keeper/pledge_ratio_test.go (1)

39-39: The test cases have been correctly updated to reflect the new function names and logic for global and node-specific pledge calculations.

Also applies to: 46-47, 54-55, 62-63, 96-96, 104-104, 112-112, 120-120

proto/tabi/captains/v1/captains.proto (1)

67-83: The new protobuf messages and fields are clearly defined and enhance the data structure's clarity and consistency.

Also applies to: 85-93, 95-97, 104-106, 109-112, 119-121, 128-131, 138-140, 147-155

x/captains/keeper/grpc_query.go (1)

117-117: The update in the NodeLastEpochInfo function to use CalcNodeCumulativeEmissionByEpoch is appropriate and aligns with the renaming objective of the PR.

x/captains/keeper/pledge_ratio.go (1)

16-16: The updates in the pledge ratio calculation functions are consistent with the new function names and logic introduced in the PR.

Also applies to: 21-21, 38-38, 106-106, 117-117, 124-124, 131-131

x/captains/keeper/nodes.go (1)

71-71: The update in the UpdateNode function to use GetClaimableComputingPower and the logic for decrementing claimable computing power are appropriate and align with the renaming and logic restructuring objectives of the PR.

Also applies to: 93-93

x/captains/keeper/computing_power.go (5)

11-19: Ensure proper handling of potential errors from MustNewDecFromStr.

While the function MustNewDecFromStr is used to convert a string to a Dec type, it panics if the conversion fails. Consider adding error handling to prevent potential runtime panics.

- return sdk.MustNewDecFromStr(string(bz))
+ dec, err := sdk.NewDecFromStr(string(bz))
+ if err != nil {
+     return sdk.ZeroDec() // or handle the error appropriately
+ }
+ return dec

29-33: LGTM! Good use of existing functions to maintain DRY principles.

The function incrGlobalComputingPowerOnEpoch correctly reuses GetGlobalComputingPowerOnEpoch and setGlobalComputingPowerOnEpoch to increment the global computing power, adhering to the DRY principle.


36-39: LGTM! Simple and effective function for clearing data.

The function delGlobalComputingPowerOnEpoch effectively uses the store's Delete method to remove the computing power record, ensuring clean state management.


144-157: Consider adding error handling for data retrieval operations.

The function GetGlobalsComputingPower retrieves global computing power without handling potential errors from GetGlobalComputingPowerOnEpoch. Adding error handling would improve robustness.

+ power.Amount, err = k.GetGlobalComputingPowerOnEpoch(ctx, power.EpochId)
+ if err != nil {
+     continue // or handle the error appropriately
+ }
  powers = append(powers, power)

159-173: Review data consistency and error handling.

The function GetNodesComputingPower retrieves computing power for all nodes but lacks error handling for the GetNodeComputingPowerOnEpoch call. Consider adding error checks to ensure data consistency.

+ power.Amount, err = k.GetNodeComputingPowerOnEpoch(ctx, power.EpochId, nodeId)
+ if err != nil {
+     continue // or handle the error appropriately
+ }
  powers = append(powers, power)
x/captains/keeper/msg_server.go (1)

266-266: Ensure proper error handling after removing the error return type.

Verification successful

The removal of the error return type from CommitComputingPower in msg_server.go does not seem to affect the overall error handling in the codebase. The function CommitComputingPower in msg_server.go handles errors before calling m.k.CommitComputingPower, and the rest of the code appears to be adjusted accordingly.

Key Points:

  • The function CommitComputingPower in msg_server.go handles errors before calling m.k.CommitComputingPower.
  • The rest of the code appears to be adjusted accordingly to handle the absence of an error return type.

Conclusion:

The removal of the error return type from CommitComputingPower does not introduce any issues in the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all calls to `CommitComputingPower` handle the absence of an error return.

# Test: Search for the function usage and check for error handling. Expect: Proper handling or adjustments in the calling code.
rg --type go $'CommitComputingPower'

Length of output: 8998



Script:

#!/bin/bash
# Description: Verify that the removal of the error return type from `CommitComputingPower` does not affect error handling.

# Test: Search for error handling in `msg_server.go` and related files.
rg --type go 'CommitComputingPower' -A 5 -B 5

Length of output: 32797

x/captains/keeper/report.go (2)

32-34: Verify data consistency after significant changes in handling report digests.


47-52: Check the impact of incrementing global computing power on epoch.

x/captains/types/keys.go (10)

26-37: Ensure consistency in naming and usage of new key prefixes.

The addition of new key prefixes such as prefixEpochEmission, prefixGlobalClaimedEmission, etc., aligns with the PR's objectives to enhance clarity and consistency in the codebase.


123-132: Validate the correctness of the EpochEmissionStoreKey function.

The function correctly constructs a key for storing epoch emission data, using the EpochEmissionKey prefix and the epoch ID. This is consistent with the intended usage described in the PR summary.


134-143: Check the implementation of NodeCumulativeEmissionByEpochStoreKey.

This function correctly constructs a key for storing cumulative emission data by node on a specific epoch, which is crucial for the new data structure introduced in the PR.


159-165: Confirm the implementation of NodeClaimedEmissionStoreKey.

The function implementation is correct and aligns with the changes in the PR, ensuring that node claimed emission data is stored with the appropriate key.


169-176: Check the ClaimableComputingPowerStoreKey function for correctness.

This function correctly handles the generation of keys for claimable computing power, which is a new feature introduced in the PR.


180-187: Validate the GlobalComputingPowerOnEpochStoreKey function.

The function is implemented correctly to handle the storage of global computing power data on a specific epoch, which is part of the new data structure changes.


215-222: Ensure correctness of GlobalPledgeOnEpochStoreKey.

The function correctly generates a key for storing global pledge data on a specific epoch, aligning with the new data structures.


Line range hint 227-247: Check the implementation of OwnerPledgeOnEpochStoreKey and ParseOwnerPledgeOnEpochPrefixStoreKey.

Both functions are implemented correctly to handle owner-specific pledge data on epochs, which is crucial for the new data structures introduced.


250-256: Validate the ReportDigestOnEpochStoreKey function.

This function is correctly implemented to handle the storage of report digest data on a specific epoch, aligning with the changes in the PR.


Line range hint 273-289: Review the ReportBatchOnEpochPrefixStoreKey and EndOnEpochStoreKey functions.

Both functions are implemented correctly to handle their respective data types on epochs, which is part of the enhancements made in the PR.

x/captains/types/genesis.go (4)

22-48: Ensure the NewGenesisState function correctly initializes all new fields.

The function has been updated to include all the new fields such as BaseState, EpochesEmission, etc., which are essential for the new genesis structure as described in the PR.


54-58: Check the DefaultGenesisState function for correct default initialization.

The function correctly initializes the GenesisState with default values for the new fields, ensuring that the system can start with a valid state.


61-66: Review the DefaultBaseState function for correct default values.

This function provides sensible default values for the BaseState, which is crucial for ensuring the system's initial configuration is valid.


123-191: Ensure comprehensive validation in the Validate method of GenesisState.

The method thoroughly validates all the new and existing fields of GenesisState, ensuring that the genesis state is consistent and valid before the system starts.

x/captains/keeper/integration_test.go (28)

106-106: Ensure the new method name GetReportDigest is consistently used across all test cases.


138-138: Verify that the new method GetGlobalComputingPowerOnEpoch correctly aggregates computing power across nodes.


183-183: Confirm that GetReportDigest correctly retrieves the report digest for the specified epoch.


190-190: Ensure that the method GetGlobalComputingPowerOnEpoch is used correctly to fetch the global computing power for the specified epoch.


218-218: Check that GetGlobalComputingPowerOnEpoch returns the expected computing power sum after all batches are processed.


237-237: Validate that the computing power sum is correctly maintained across epochs.


242-242: Confirm that GetGlobalComputingPowerOnEpoch correctly returns zero after the epoch ends, indicating reset of values.


270-270: Ensure that GetReportDigest is consistently retrieving the correct report digest for the given epoch.


277-277: Check that the global computing power is correctly calculated and retrieved for the specified epoch.


283-283: Verify that GetNodeCumulativeEmissionByEpoch and GetNodeComputingPowerOnEpoch are correctly retrieving node-specific data.


310-310: Confirm that node-specific cumulative emissions and computing power are reset to zero at the start of a new epoch.


314-314: Ensure that the global computing power sum is correctly calculated and matches the expected value after all batches are processed.


333-333: Validate that the computing power sum is correctly maintained across epochs.


338-338: Confirm that GetGlobalComputingPowerOnEpoch correctly returns zero after the epoch ends, indicating reset of values.


378-378: Ensure that GetReportDigest is consistently retrieving the correct report digest for the given epoch.


411-411: Check that the global computing power is correctly calculated and retrieved for the specified epoch.


466-466: Confirm that GetReportDigest correctly retrieves the report digest for the specified epoch.


474-474: Ensure that the method GetGlobalComputingPowerOnEpoch is used correctly to fetch the global computing power for the specified epoch.


502-502: Check that GetGlobalComputingPowerOnEpoch returns the expected computing power sum after all batches are processed.


521-521: Validate that the computing power sum is correctly maintained across epochs.


526-526: Confirm that GetGlobalComputingPowerOnEpoch correctly returns zero after the epoch ends, indicating reset of values.


554-554: Ensure that GetReportDigest is consistently retrieving the correct report digest for the given epoch.


562-562: Check that the global computing power is correctly calculated and retrieved for the specified epoch.


568-568: Verify that GetNodeCumulativeEmissionByEpoch and GetNodeComputingPowerOnEpoch are correctly retrieving node-specific data.


595-595: Confirm that node-specific cumulative emissions and computing power are reset to zero at the start of a new epoch.


599-599: Ensure that the global computing power sum is correctly calculated and matches the expected value after all batches are processed.


618-618: Validate that the computing power sum is correctly maintained across epochs.


623-623: Confirm that GetGlobalComputingPowerOnEpoch correctly returns zero after the epoch ends, indicating reset of values.

x/captains/keeper/computing_power.go Show resolved Hide resolved
x/captains/keeper/computing_power.go Show resolved Hide resolved
x/captains/keeper/computing_power.go Show resolved Hide resolved
x/captains/keeper/computing_power.go Show resolved Hide resolved
x/captains/types/keys.go Show resolved Hide resolved
x/captains/types/keys.go Show resolved Hide resolved
x/captains/keeper/genesis.go Show resolved Hide resolved
x/captains/keeper/emission.go Show resolved Hide resolved
@richardleeft richardleeft merged commit 7d1b925 into develop May 17, 2024
@richardleeft richardleeft deleted the oris/captains/refactor branch May 17, 2024 06:46
richardleeft added a commit that referenced this pull request May 24, 2024
* chore: remove vesting

* chore: remove revenue

* chore: remove other modules

* feature: add testnet cmd

* chore: fmt code

* add mint proto file

* add module file

* Complete mint module

* fix: testnet cmd

* proto-gen: add proto & proto-gen

* init claims module

* add claims module to app

* chore: reorganize tabichain project struct

* add claims write interface

* add caption-node proto

* feat: init caption-node struct

* update captain node proto

* fix: fix testutils

* feat: init token-convert

* modify caption-node proto

* Complete node creation logic

* add query && tx cmd

* add test case

* chore: fix bug

* feat: Add auxiliary interface

* Add module cache

* feat: add claims module (#15)

* refactor: Removed logic for assigning rewards to captain-node in claims (#16)

* refactor: Redefine interfaces and Change processing logic (#17)

* feat: token-convert module (#18)

* proto: define and generate token-convert module

* init: token-convert module structure

* feat: get token-convert key

* feat: token-convert msg sever
proto: definiton modification

* fix: type err

* feat: token-convert app module

* feat: msg validation

* fix: delete voucher

* feat: token-convert query server

* feat: token-convert genesis

* feat: token-convert tx cli cmd

* feat: token-convert query cli cmd

* refactor: captains proto (#19)

* refactor: captains proto

* fix: rename callers to members & add update_params service

* feat: refactor claims proto (#21)

* feat: refactor claims proto

* fix: fix review comment

* refactor: captains module interfaces (#20)

* fix: compiling error due to proto redefinition.

* fix: module name error in token-convert

* fix: interface name typo

* fix: query authorized members

* chore: rename captains event type

* refactor: captains keys

* refactor: captains interfaces

* fix: division proto

* feat: captains exported interfaces (#22)

* feat: exported interfaces

* fix: exported keeper

* feat: implement claims module (#23)

* add calculate rewards

* add query cmd

* implement claims

* chore: modify CalculateRewards return value

* chore: modify CalculateRewards return value

* fix bug

* chore: add error and add event to claims

* fix: fix claims bug (#24)

* feat: captains rewards calculation logic (#25)

* feat: msg server

* feat: impl calculation func for emssion reward

* fix: module pkg name

* feat: improve calculation algo

* abci: incr epoch

* fix: commit report

* feat: captains optimization (#26)

* impr: align report epoch with current epoch

* fix: msg validation

* feat: captains tx&query cmd

* fix: get all powers

* fix: init geneis

* fix: new genesis

* fix: register claim amino error

* chore: Remove useless operations (#27)

* feat: Restrict sending EVM transactions to allow list only (#28)

* refactor: emission formula revised (#29)

* refactor emssion formula

* revise exported interface in captains

* fix: Fixed the MsgUpdateParams non-registration issue of captains module (#30)

* refactor: mint output is only given to Validators and delegators (#31)

* test: part of captains unit tests (#32)

* captains unit test part 1

* captains unit test part 2

* test: token-convert msg server unit test (#33)

* add token-convert server unit test

* format code

* revise formula (#34)

* feat: query node emission on last epoch (#35)

* fix: add node power on ratio and remove limit on nodes holding

* revise proto and fix captains logic

* proto: add query for captains

* feat: add additional query

* refactor: seperate state prune or set from calc func  (#36)

* fix: seperate set/prune logic from calc func

* complete full epoch test

* revise proto and func name

* test[claims]: implement claims module test (#37)

* feat: implement claims module test

* fix: set mock keeper

* feat: implement claims module claims test

* implement claims module query test

---------

Co-authored-by: oris <[email protected]>

* test: captains integration test (#38)

* fix: seperate set/prune logic from calc func

* complete full epoch test

* revise proto and func name

* add grpc test

* add captains unit test

* fix captains suite

* fix test

* refactor: captains genesis and key naming. (#39)

* rename key

* mv report func to report.go

* refactor genesis import/export

* rename captains expected keeper interface

* feat: restrict captains tx as per epoch phase  (#40)

* feat: restriction on captains txs as per epoch phase

* fix func name

* add stand-by flag to genesis

* rm typo in ante

* fix: captains test (#41)

* chore: update division default value

* fix: restrict claim on rewards and powers

* fix tx cli

* fix coefficient

* fix msg validation

* add commit report msg test

* fix grpc query

* fix: key store error
test: captains import and export

* chore: Optimize code (#42)

* feat: epoches testing framework  (#43)

* add full epoch testing framework

* fix testing error

* fix epoch phase

* add state transition table and fix tests

* chore: rm cpr

* rm gitpod

* retract do not edit

* test&cli: add ante test and draft report cmd (#44)

* rename captains exported interface

* add ante testing

* cli: add draft report

* typo

* chore: add changelog (#45)

---------

Co-authored-by: chivalrouslee <[email protected]>
Co-authored-by: richardleeft <[email protected]>
Co-authored-by: ppyang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants