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

[CORE-824] Implement keeper methods for LimitParams and DenomCapacity #877

Merged
merged 5 commits into from
Dec 12, 2023

Conversation

teddyding
Copy link
Contributor

@teddyding teddyding commented Dec 11, 2023

Changelist

  • Keeper methods for LimitParams and DenomCapacity
  • Register module in application

Test Plan

Unit tests

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Copy link

linear bot commented Dec 11, 2023

Copy link
Contributor

coderabbitai bot commented Dec 11, 2023

Walkthrough

The overall change involves renaming and reorganizing the ibcratelimit module to ratelimit across various files in the dYdX protocol codebase. This includes updates to package declarations, import paths, comments, and endpoint URLs. Additionally, there are enhancements to the ratelimit module's functionality, such as the addition of new error types, keeper functions, and test cases.

Changes

File(s) Change Summary
proto/dydxprotocol/ratelimit/... Updated package declaration from dydxprotocol.ibcratelimit to dydxprotocol.ratelimit and modified go_package option.
protocol/app/app.go Added imports for ratelimitmodulekeeper and ratelimitmoduletypes; integrated RatelimitKeeper into App struct.
protocol/x/ratelimit/client/cli/... Updated package paths and comments from ibcratelimit to ratelimit.
protocol/x/ratelimit/genesis.go, genesis_test.go, module.go, module_test.go Changed package name from ibcratelimit to ratelimit; updated import paths.
protocol/x/ratelimit/keeper/... Updated import paths; added new functionality and test cases in keeper package.
protocol/x/ratelimit/types/... Added new error type; introduced types package with constants for module names and store keys.
indexer/packages/v4-protos/src/codegen/dydxprotocol/... Renamed imports and exports from ibcratelimit to ratelimit; updated endpoint URLs and RPC request paths.

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 X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can reply to a review comment from CodeRabbit.
  • You can also chat with CodeRabbit bot directly around the specific lines of code or files in the PR by tagging @coderabbitai in a new comment.
  • You can tag @coderabbitai in a PR comment and ask questions about the PR and the codebase.

CodeRabbit Commands (invoked as PR comments)

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

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

CodeRabbit Configration File (.coderabbit.yaml)

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

@teddyding teddyding changed the title [CORE-824] Implement keeper methods for LimitParams and `DenomCapacity [CORE-824] Implement keeper methods for LimitParams and DenomCapacity Dec 11, 2023
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fb83527 and 285d498.
Files ignored due to filter (1)
  • protocol/x/ibcratelimit/types/limit_params.pb.go
Files selected for processing (6)
  • proto/dydxprotocol/ibcratelimit/limit_params.proto (1 hunks)
  • protocol/app/app.go (9 hunks)
  • protocol/x/ibcratelimit/keeper/keeper.go (2 hunks)
  • protocol/x/ibcratelimit/keeper/keeper_test.go (1 hunks)
  • protocol/x/ibcratelimit/types/errors.go (1 hunks)
  • protocol/x/ibcratelimit/types/keys.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • protocol/x/ibcratelimit/types/errors.go
Additional comments: 17
protocol/app/app.go (6)
  • 243-243: The addition of IBCRateLimitKeeper to the App struct is consistent with the PR objectives. Ensure that this keeper is properly initialized in the New function and that any necessary migrations or state initializations are handled.

  • 350-350: The addition of ibcratelimitmoduletypes.StoreKey to the list of keys is correct and necessary for the new module to have its own dedicated storage space.

  • 541-549: The instantiation of IBCRateLimitKeeper within the New function appears to be correct. Verify that the parameters passed to NewKeeper are appropriate and that the keeper is added to the module manager for proper interaction with the rest of the application.

  • 992-992: The addition of ibcratelimitmoduletypes.ModuleName to the BeginBlocker and EndBlocker module order is correct. Ensure that the module's logic is intended to be invoked at these points in the block lifecycle and that the order of execution is correct relative to other modules.

  • 1074-1074: The addition of ibcratelimitmoduletypes.ModuleName to the InitGenesis module order is correct. Ensure that the module's genesis state is properly initialized and that the order of execution is correct relative to other modules.

  • 1110-1110: The addition of ibcratelimitmoduletypes.ModuleName to the OrderMigrations module order is correct. Ensure that any state migrations required for the new module are properly handled and that the order of execution is correct relative to other modules.

protocol/x/ibcratelimit/keeper/keeper.go (9)
  • 5-14: The imports added are consistent with the new functionality introduced in the keeper. The math/big package is used for handling big integers, which is necessary for the financial calculations in the keeper methods. The cosmossdk.io/errors package is used for error handling, and the github.com/cosmos/cosmos-sdk/store/prefix package is used for prefix stores, which are a common pattern in Cosmos SDK modules for managing different types of data in the state. The github.com/dydxprotocol/v4-chain/protocol/dtypes import is used for the SerializableInt type, which is likely a custom type that can be serialized for storage.

  • 19-22: The global variable TempTVLPlacerholder is introduced with a TODO comment indicating that it is a temporary placeholder and should be replaced once the GetBaseline method is fully implemented. This is a good practice as it clearly marks the code that needs to be revisited and provides a reference to the related task.

  • 49-90: The ProcessWithdrawal function correctly checks if the withdrawal amount exceeds any of the capacities in the list and returns an error if it does. The error handling uses the new ErrWithdrawalExceedsCapacity constant as expected. The function then updates the capacity list by subtracting the withdrawal amount from each capacity. This logic seems correct, but it's important to ensure that the CapacityList is properly locked or synchronized if there are concurrent accesses, to prevent data races.

  • 93-121: The ProcessDeposit function updates the capacity list by adding the deposit amount to each capacity. The logic is similar to ProcessWithdrawal but in reverse, and it should be checked for the same concurrency concerns.

  • 123-142: The GetBaseline function uses the TempTVLPlacerholder to calculate the baseline. The formula used seems to be consistent with the comment describing the baseline calculation. However, it's important to ensure that the currentTVL placeholder is replaced with the actual total value locked (TVL) once the implementation is complete. The use of lib.BigMax and lib.BigIntMulPpm suggests that these are utility functions for big integer operations, which should be reviewed for correctness and efficiency.

  • 145-183: The SetLimitParams function uses prefix stores to set LimitParams and DenomCapacity in the state. The function handles the case where the limiters list is empty by deleting the corresponding state entries, which is a good practice for state cleanup. The use of MustMarshal is appropriate here as it's within a function that does not return an error, but it's important to ensure that the data being marshaled is always valid and that the function is not called in a context where a marshal error could occur.

  • 185-204: The GetLimitParams function retrieves LimitParams from the state, returning a default value if not found. The use of MustUnmarshal is appropriate here as well, but again, it's important to ensure that the data in the state is always valid and that the function is not called in a context where an unmarshal error could occur.

  • 206-222: The SetDenomCapacity function is similar to SetLimitParams in its use of prefix stores and handling of empty capacity lists. The logic is consistent and follows best practices for state management in Cosmos SDK modules.

  • 225-243: The GetDenomCapacity function is similar to GetLimitParams in its retrieval logic and handling of default values. The consistency in these getter functions is good for maintainability and readability of the code.

protocol/x/ibcratelimit/types/keys.go (2)
  • 12-13: The introduction of DenomCapacityKeyPrefix is a new addition. Ensure that this key prefix is used correctly wherever DenomCapacity data is accessed or modified.

The usage of DenomCapacityKeyPrefix has been verified in the keeper.go file in addition to its declaration in keys.go. This suggests that the new key prefix is being utilized correctly in the codebase.

Final review comment:

The addition of DenomCapacityKeyPrefix has been correctly implemented and is being used in the codebase as intended.

  • 15-16: Similarly, the introduction of LimitParamsKeyPrefix is a new addition. Ensure that this key prefix is used correctly wherever LimitParams data is accessed or modified.

The verification of the usage of LimitParamsKeyPrefix shows that it is referenced in both keys.go and keeper.go, which suggests that the new key prefix is being utilized in the codebase. Since there are no indications of misuse or errors, the introduction of this key prefix appears to be correctly implemented.

Final review comment:

The introduction of LimitParamsKeyPrefix has been verified and is being used correctly in the codebase.

Comment on lines 6 to 7
// Use `ratelimit` instead of `ibcratelimit` to prevent potential key space conflicts with the IBC module.
ModuleName = "ratelimit"
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 NOTE
Codebase verification is a beta feature.

The verification process has identified multiple files that still reference the old ModuleName ibcratelimit and the new ModuleName ratelimit. This suggests that the renaming has been partially applied but may not be consistent across the entire codebase. It is important to ensure that all necessary references are updated to maintain consistency and avoid potential errors.

Final review comment:

The renaming of ModuleName to ratelimit appears to be partially applied. Ensure that all references to the old module name are updated across the codebase to maintain consistency and prevent conflicts.

  • Update all references from ibcratelimit to ratelimit in the identified files to ensure consistency.
  • Review the usage in app.go and related files to confirm the module is registered correctly with the new name.
  • Check the proto files and the indexer service files for consistent use of the new module name.
Analysis chain

The change in the ModuleName constant from ibcratelimit to ratelimit is significant as it may affect other parts of the codebase that rely on this constant. Verify that all references to ModuleName have been updated accordingly.

CapacityList: nil,
},
k.GetDenomCapacity(ctx, testDenom),
"retrieved LimitParams do not match the set value",
Copy link
Contributor

Choose a reason for hiding this comment

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

The error message in the assertion should reference DenomCapacity instead of LimitParams.

- "retrieved LimitParams do not match the set value"
+ "retrieved DenomCapacity does not match the set value"

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
"retrieved LimitParams do not match the set value",
"retrieved DenomCapacity does not match the set value",

CapacityList: nil,
},
k.GetDenomCapacity(ctx, testDenom),
"retrieved LimitParams do not match the set value")
Copy link
Contributor

Choose a reason for hiding this comment

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

The error message in the assertion should reference DenomCapacity instead of LimitParams.

- "retrieved LimitParams do not match the set value"
+ "retrieved DenomCapacity does not match the set value"

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
"retrieved LimitParams do not match the set value")
"retrieved DenomCapacity does not match the set value")

Comment on lines 12 to 17
string denom = 1;
// limiters is a list of rate-limiters on this denom. All limiters
// must be satified for a withdrawal to proceed.
repeated Limiter limiters = 2;
repeated Limiter limiters = 2 [
(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.

💡 NOTE
Codebase verification is a beta feature.

The review of the new context from the shell scripts indicates that the non-nullable change to the limiters field in the LimitParams message will have significant implications across the Go codebase. The following files and areas are particularly affected:

  • MsgSetLimitParams struct in tx.pb.go still references LimitParams as a pointer.
  • keeper.go and keeper_test.go contain logic and tests for setting and getting LimitParams.
  • params.go includes a Validate method for LimitParams.
  • genesis.pb.go sets up initial LimitParams in the genesis state.
  • query.pb.go involves listing LimitParams, which may affect marshaling and unmarshaling.

Given these findings, it is crucial to ensure that all parts of the codebase that interact with LimitParams and its limiters field are updated to handle the non-pointer slice correctly.

  • Update MsgSetLimitParams in tx.pb.go to reflect the non-pointer nature of LimitParams.
  • Review and update logic and tests in keeper.go and keeper_test.go for compatibility with the non-nullable limiters field.
  • Verify the Validate method in params.go for any adjustments needed due to the change.
  • Ensure that the genesis state initialization in genesis.pb.go correctly handles the updated LimitParams.
  • Check serialization and deserialization processes in query.pb.go to ensure they work with the non-nullable limiters field.
Analysis chain

The change to make the limiters field non-nullable is a significant alteration to the data structure. This will affect the generated Go code, potentially impacting initialization and usage patterns. Ensure that all parts of the codebase that interact with LimitParams and its limiters field are updated to handle the non-pointer slice correctly.

@@ -152,6 +154,7 @@ import (
rewardsmodule "github.com/dydxprotocol/v4-chain/protocol/x/rewards"
rewardsmodulekeeper "github.com/dydxprotocol/v4-chain/protocol/x/rewards/keeper"
rewardsmoduletypes "github.com/dydxprotocol/v4-chain/protocol/x/rewards/types"

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove extra line

@@ -3,10 +3,17 @@ package types
// Module name and store keys
const (
// ModuleName defines the module name
ModuleName = "ibcratelimit"
// Use `ratelimit` instead of `ibcratelimit` to prevent potential key space conflicts with the IBC module.
Copy link
Contributor

Choose a reason for hiding this comment

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

any way to catch this automatically?

Copy link
Contributor Author

@teddyding teddyding Dec 12, 2023

Choose a reason for hiding this comment

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

Yes, this was caught here in test.

I also changed all of references ibcratelimit to ratelimit.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 420afa6 and cc506a6.
Files ignored due to filter (6)
  • protocol/x/ratelimit/types/capacity.pb.go
  • protocol/x/ratelimit/types/genesis.pb.go
  • protocol/x/ratelimit/types/limit_params.pb.go
  • protocol/x/ratelimit/types/query.pb.go
  • protocol/x/ratelimit/types/query.pb.gw.go
  • protocol/x/ratelimit/types/tx.pb.go
Files selected for processing (32)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts (5 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/ibcratelimit/genesis.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/ibcratelimit/query.lcd.ts (2 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/ibcratelimit/query.rpc.Query.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/ibcratelimit/tx.rpc.msg.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/lcd.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/rpc.query.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/rpc.tx.ts (1 hunks)
  • proto/dydxprotocol/ratelimit/capacity.proto (1 hunks)
  • proto/dydxprotocol/ratelimit/genesis.proto (1 hunks)
  • proto/dydxprotocol/ratelimit/limit_params.proto (2 hunks)
  • proto/dydxprotocol/ratelimit/query.proto (1 hunks)
  • proto/dydxprotocol/ratelimit/tx.proto (1 hunks)
  • protocol/app/app.go (8 hunks)
  • protocol/x/ratelimit/client/cli/query.go (2 hunks)
  • protocol/x/ratelimit/client/cli/query_params.go (1 hunks)
  • protocol/x/ratelimit/client/cli/query_params_test.go (1 hunks)
  • protocol/x/ratelimit/client/cli/tx.go (1 hunks)
  • protocol/x/ratelimit/genesis.go (1 hunks)
  • protocol/x/ratelimit/genesis_test.go (1 hunks)
  • protocol/x/ratelimit/keeper/grpc_query.go (2 hunks)
  • protocol/x/ratelimit/keeper/grpc_query_test.go (1 hunks)
  • protocol/x/ratelimit/keeper/keeper.go (1 hunks)
  • protocol/x/ratelimit/keeper/keeper_test.go (1 hunks)
  • protocol/x/ratelimit/keeper/msg_server.go (1 hunks)
  • protocol/x/ratelimit/keeper/msg_server_test.go (1 hunks)
  • protocol/x/ratelimit/module.go (2 hunks)
  • protocol/x/ratelimit/module_simulation.go (3 hunks)
  • protocol/x/ratelimit/module_test.go (1 hunks)
  • protocol/x/ratelimit/types/errors.go (1 hunks)
  • protocol/x/ratelimit/types/keys.go (1 hunks)
  • protocol/x/ratelimit/types/keys_test.go (1 hunks)
Files skipped from review due to trivial changes (8)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/ibcratelimit/genesis.ts
  • proto/dydxprotocol/ratelimit/genesis.proto
  • proto/dydxprotocol/ratelimit/query.proto
  • protocol/x/ratelimit/client/cli/query.go
  • protocol/x/ratelimit/genesis.go
  • protocol/x/ratelimit/keeper/grpc_query_test.go
  • protocol/x/ratelimit/keeper/msg_server_test.go
  • protocol/x/ratelimit/module_test.go
Additional comments: 66
indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts (5)
  • 42-52: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [42-53]

The renaming of imports from ibcratelimit to ratelimit is consistent with the PR objectives and the AI-generated overview. Ensure that all references to these modules throughout the codebase have been updated to reflect the new naming convention.

  • 95-101: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [95-109]

The addition of the new import ratelimit/query.lcd is consistent with the renaming strategy. Verify that the corresponding LCD queries have been updated to use the new module name.

  • 109-115: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [109-123]

The renaming of RPC query imports from ibcratelimit to ratelimit is consistent with the PR objectives. Verify that the RPC service definitions and client calls have been updated accordingly.

  • 122-128: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [122-136]

The renaming of RPC message imports from ibcratelimit to ratelimit is consistent with the PR objectives. Verify that the RPC message handling and client calls have been updated accordingly.

  • 208-214: The export of the ratelimit namespace is correctly added to align with the renaming of the module. Ensure that the exported namespace is being used correctly wherever necessary.
indexer/packages/v4-protos/src/codegen/dydxprotocol/ibcratelimit/query.lcd.ts (2)
  • 18-20: The update to the endpoint URL in the listLimitParams method is consistent with the module renaming from ibcratelimit to ratelimit. This change should be cross-verified with the server-side route configurations to ensure that the new endpoint is correctly set up to handle requests.

  • 34-35: Similarly, the update to the endpoint URL in the capacityByDenom method aligns with the module renaming. As with the previous endpoint, ensure that the corresponding server-side route is properly configured to respond to requests at the new URL.

indexer/packages/v4-protos/src/codegen/dydxprotocol/ibcratelimit/query.rpc.Query.ts (2)
  • 25-25: The RPC endpoint has been correctly updated to reflect the new module name. Ensure that the service definition for "dydxprotocol.ratelimit.Query" is properly registered and that the corresponding service is accessible.

  • 31-31: The RPC endpoint has been correctly updated to reflect the new module name. Ensure that the service definition for "dydxprotocol.ratelimit.Query" is properly registered and that the corresponding service is accessible.

indexer/packages/v4-protos/src/codegen/dydxprotocol/ibcratelimit/tx.rpc.msg.ts (1)
  • 22-32: The changes in the MsgClientImpl class correctly update the RPC service names from "dydxprotocol.ibcratelimit.Msg" to "dydxprotocol.ratelimit.Msg", aligning with the renaming of the module. This is consistent with the PR objectives and the AI-generated overview. No issues are found within this hunk.
indexer/packages/v4-protos/src/codegen/dydxprotocol/rpc.query.ts (1)
  • 19-19: The addition of the ratelimit module import is consistent with the PR's objectives and the renaming process described in the AI-generated summary.
proto/dydxprotocol/ratelimit/capacity.proto (1)
  • 1-9: The changes to the package declaration and go_package option are correct and align with the PR's objective to rename and reorganize the ibcratelimit module to ratelimit. This will affect import paths and package references throughout the codebase.
proto/dydxprotocol/ratelimit/limit_params.proto (3)
  • 2-2: The package declaration change from dydxprotocol.ibcratelimit to dydxprotocol.ratelimit is correct and aligns with the PR objectives.

  • 6-6: The go_package option update to github.com/dydxprotocol/v4-chain/protocol/x/ratelimit/types is correct and reflects the new module naming convention.

  • 15-15: The addition of [ (gogoproto.nullable) = false ] to the limiters field in the LimitParams message ensures non-nullable slices in the generated Go code, which is a good practice to prevent potential null pointer exceptions.

proto/dydxprotocol/ratelimit/tx.proto (3)
  • 2-2: The package name change from dydxprotocol.ibcratelimit to dydxprotocol.ratelimit is consistent with the PR's objectives and the renaming efforts across the codebase.

  • 4-4: The go_package option has been updated to reflect the new module path, which aligns with the renaming of the module and should ensure that the generated Go files are placed in the correct directory.

  • 7-7: The import path for limit_params.proto has been updated to the new module name. This change is necessary to maintain the correct references after the module renaming.

protocol/app/app.go (8)
  • 149-156: The addition of ratelimitmodulekeeper and ratelimitmoduletypes imports is consistent with the PR objectives to integrate the RatelimitKeeper into the App struct and aligns with the renaming of the module.

  • 239-245: The integration of RatelimitKeeper into the App struct is correctly implemented and matches the PR objectives and AI-generated summary.

  • 346-352: The addition of ratelimitmoduletypes.StoreKey to the list of store keys is necessary for the initialization of the RatelimitKeeper and is consistent with the PR objectives.

  • 537-554: The initialization of RatelimitKeeper using ratelimitmodulekeeper.NewKeeper is correctly implemented and follows the Cosmos SDK pattern for keeper initialization.

  • 988-994: The addition of ratelimitmoduletypes.ModuleName to the SetOrderBeginBlockers function ensures that the RatelimitKeeper is invoked at the beginning of each block, which is consistent with the expected behavior for a module keeper.

  • 1031-1037: The addition of ratelimitmoduletypes.ModuleName to the SetOrderEndBlockers function ensures that the RatelimitKeeper is invoked at the end of each block, which is consistent with the expected behavior for a module keeper.

  • 1070-1076: The addition of ratelimitmoduletypes.ModuleName to the SetOrderInitGenesis function ensures that the RatelimitKeeper is initialized during the genesis process, which is consistent with the expected behavior for a module keeper.

  • 1106-1112: The addition of ratelimitmoduletypes.ModuleName to the SetOrderMigrations function ensures that the RatelimitKeeper is included in the migration process, which is consistent with the expected behavior for a module keeper.

protocol/x/ratelimit/client/cli/query_params.go (1)
  • 8-8: The updated comment correctly reflects the ongoing work and module renaming. Ensure that the corresponding implementation for the CmdQueryParams function is tracked and completed as per the TODO item.
protocol/x/ratelimit/client/cli/query_params_test.go (1)
  • 14-14: The updated comment aligns with the PR's objective to rename the module from ibcratelimit to ratelimit. This change is a simple comment update and does not impact the functionality of the test.
protocol/x/ratelimit/client/cli/tx.go (2)
  • 10-10: The update of the import path from ibcratelimit to ratelimit aligns with the PR's objective to rename and reorganize the module.

  • 7-13: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [13-24]

The usage of types.ModuleName within the GetTxCmd function indicates that the renamed import is being utilized correctly in the file's scope.

protocol/x/ratelimit/genesis_test.go (2)
  • 1-1: The package name change from "ibcratelimit_test" to "ratelimit_test" aligns with the PR's objective to rename and reorganize the module.

  • 1-4: Ensure that the TODO comment in the TestGenesis function is tracked in the project's issue tracking system to ensure it is not forgotten.

protocol/x/ratelimit/keeper/grpc_query.go (5)
  • 6-6: The import path update is correct and aligns with the renaming of the module.

  • 17-17: The TODO comment indicates that the implementation for ListLimitParams is pending. Ensure that there is a tracking system (like an issue tracker) to follow up on these TODOs.

  • 24-24: Similarly, the TODO comment for CapacityByDenom suggests that its implementation is also pending. It's important to track these items to ensure they are completed.

  • 18-18: The method ListLimitParams currently returns an unimplemented error. Confirm that the rest of the system is prepared to handle this response until the method is implemented.

  • 25-25: The method CapacityByDenom also returns an unimplemented error. It's crucial to verify that the system can handle this response appropriately.

protocol/x/ratelimit/keeper/keeper.go (12)
  • 19-22: The TempTVLPlacerholder is a temporary placeholder for TVL. Ensure that the placeholder is removed and replaced with the actual implementation as soon as possible to avoid technical debt.

  • 37-46: The NewKeeper function initializes a Keeper struct with a map of authorities from a slice of strings. Ensure that the lib.UniqueSliceToSet function correctly handles duplicates and potential nil values to prevent runtime panics.

  • 49-90: The ProcessWithdrawal function should ensure that the amount is not nil and that it is a valid *big.Int to prevent potential panics when calling amount.Cmp. Additionally, consider adding a check to ensure that denom is not an empty string.

  • 93-121: Similar to the ProcessWithdrawal function, the ProcessDeposit function should validate the amount and denom inputs for the same reasons.

  • 123-142: The GetBaseline function uses a temporary placeholder for the current TVL. Ensure that the actual TVL is queried and used here once the implementation is complete. Also, verify that limiter.BaselineMinimum and limiter.BaselineTvlPpm are properly validated before use to prevent unexpected behavior.

  • 145-183: The SetLimitParams function deletes the limit params and denom capacity from the store if the length of input limit params is zero. Ensure that this behavior is intended and documented, as it could lead to data loss if not handled correctly.

  • 185-204: The GetLimitParams function returns a default value if the limit params do not exist in the state. Ensure that this behavior is consistent with the rest of the codebase and that the default value is properly documented.

  • 206-223: The SetDenomCapacity function deletes the denom capacity from the store if there's no capacity entry to set. Ensure that this behavior is intended and that there are no side effects of deleting the key, such as orphaned references elsewhere in the code.

  • 225-244: The GetDenomCapacity function returns a default value if the denom capacity does not exist in the state. Similar to GetLimitParams, ensure that this behavior is consistent and that the default value is properly documented.

  • 246-248: The HasAuthority function checks if a given authority is present in the authorities map. Ensure that the map is always initialized before this function is called to prevent a nil map panic.

  • 251-253: The Logger function creates a logger with a module key. Ensure that the fmt.Sprintf call does not introduce any performance overhead in high-throughput logging scenarios.

  • 255-256: The InitializeForGenesis function is currently empty. If this is intentional and meant to be implemented later, ensure that it is tracked with a TODO comment or an issue in the project's issue tracker.

protocol/x/ratelimit/keeper/keeper_test.go (2)
  • 82-117: The test TestSetGetLimitParams_Success includes a TODO comment for updating the expected value after GetBaseline depends on current TVL. This indicates that the test may need to be updated in the future to reflect changes in the GetBaseline method. It's important to track this TODO to ensure the test remains accurate after the implementation of GetBaseline.

  • 120-122: The TestGetBaseline function is currently a placeholder with a TODO comment. It's important to ensure that this test is implemented once the GetBaseline functionality is ready to be tested.

protocol/x/ratelimit/keeper/msg_server.go (2)
  • 9-9: The change in the import path from ibcratelimit to ratelimit is consistent with the PR's objective of renaming and reorganizing the module.

  • 12-12: Ensure that the HasAuthority method used in SetLimitParams and DeleteLimitParams functions is properly implemented and tested, as it is critical for authorization checks.

protocol/x/ratelimit/module.go (3)
  • 1-1: The package name change from ibcratelimit to ratelimit is consistent with the PR objectives and the AI-generated overview.

  • 18-20: The updated import paths for the cli, keeper, and types packages are consistent with the PR objectives and the AI-generated overview.

  • 15-23: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1-20]

Verify that all references to the old module name ibcratelimit have been updated to ratelimit across the entire codebase.

protocol/x/ratelimit/module_simulation.go (5)
  • 1-4: The package name change from ibcratelimit to ratelimit is correctly reflected here.

  • 9-22: The imports have been updated to reflect the new module name, and aliases are not used, which is good for clarity. Additionally, the use of underscore imports to avoid unused import issues is a common Go practice to pass the compiler checks when imports are used indirectly.

  • 28-32: The GenerateGenesisState function has been updated to include the initialization of ratelimitGenesis and correctly sets it in the simState.GenState using the ModuleName constant from the types package. This is consistent with the module renaming and the addition of new functionalities.

  • 33-33: No changes were made to the RegisterStoreDecoder function, which is consistent with the scope of the PR as no alterations to store decoding logic were mentioned.

  • 34-34: No changes were made to the WeightedOperations and ProposalMsgs functions, which is consistent with the scope of the PR as no alterations to simulation operations or governance proposals were mentioned.

protocol/x/ratelimit/types/errors.go (1)
  • 14-18: The addition of ErrWithdrawalExceedsCapacity with error code 1002 is correctly implemented and follows the module's error declaration pattern.
protocol/x/ratelimit/types/keys.go (1)
  • 1-17: The constants for the module name and store keys are well-defined and follow the new naming convention as per the PR's objective.
protocol/x/ratelimit/types/keys_test.go (3)
  • 6-6: The import path has been updated to reflect the new module name, which aligns with the PR objectives and the AI-generated overview.

  • 11-12: The values of ModuleName and StoreKey have been updated to "ratelimit" to match the new module name. This change is consistent with the renaming strategy outlined in the PR objectives and the AI-generated overview.

  • 15-15: The TestStateKeys function contains a TODO comment, which is a placeholder for future tests. This is a good practice to indicate work that needs to be completed, but it's important to ensure that these TODOs are tracked in the project's issue tracking system to ensure they are not forgotten.

// Module name and store keys
const (
// ModuleName defines the module name
// Use `ratelimit` instead of `ratelimit` to prevent potential key space conflicts with the IBC module.
Copy link
Contributor

Choose a reason for hiding this comment

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

There appears to be a typo or copy-paste error in the comment on line 6. The comment should clarify the distinction between the module names to prevent key space conflicts.

- // Use `ratelimit` instead of `ratelimit` to prevent potential key space conflicts with the IBC module.
+ // Use `ratelimit` instead of `ibcratelimit` to prevent potential key space conflicts with the IBC module.

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// Use `ratelimit` instead of `ratelimit` to prevent potential key space conflicts with the IBC module.
// Use `ratelimit` instead of `ibcratelimit` to prevent potential key space conflicts with the IBC module.

Comment on lines +16 to +50
func TestSetGetDenomCapacity(t *testing.T) {
tApp := testapp.NewTestAppBuilder(t).Build()
ctx := tApp.InitChain()
k := tApp.App.RatelimitKeeper

capacityList := []dtypes.SerializableInt{
dtypes.NewInt(123_456_789),
dtypes.NewInt(500_000_000),
}
denomCapacity := types.DenomCapacity{
Denom: testDenom,
CapacityList: capacityList,
}

// Test SetDenomCapacity
k.SetDenomCapacity(ctx, denomCapacity)

// Test GetDenomCapacity
gotDenomCapacity := k.GetDenomCapacity(ctx, testDenom)
require.Equal(t, denomCapacity, gotDenomCapacity, "retrieved DenomCapacity does not match the set value")

k.SetDenomCapacity(ctx, types.DenomCapacity{
Denom: testDenom,
CapacityList: []dtypes.SerializableInt{}, // Empty list, results in deletion of the key.
})

// Check that the key is deleted under `DenomCapacity` storage.
require.Equal(t,
types.DenomCapacity{
Denom: testDenom,
CapacityList: nil,
},
k.GetDenomCapacity(ctx, testDenom),
"retrieved LimitParams do not match the set value",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

The test TestSetGetDenomCapacity correctly sets and retrieves DenomCapacity and checks for the deletion of the key when an empty list is provided. However, the error message in line 49 is incorrect; it should refer to DenomCapacity instead of LimitParams.

- "retrieved LimitParams do not match the set value"
+ "retrieved DenomCapacity does not match the set value"

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func TestSetGetDenomCapacity(t *testing.T) {
tApp := testapp.NewTestAppBuilder(t).Build()
ctx := tApp.InitChain()
k := tApp.App.RatelimitKeeper
capacityList := []dtypes.SerializableInt{
dtypes.NewInt(123_456_789),
dtypes.NewInt(500_000_000),
}
denomCapacity := types.DenomCapacity{
Denom: testDenom,
CapacityList: capacityList,
}
// Test SetDenomCapacity
k.SetDenomCapacity(ctx, denomCapacity)
// Test GetDenomCapacity
gotDenomCapacity := k.GetDenomCapacity(ctx, testDenom)
require.Equal(t, denomCapacity, gotDenomCapacity, "retrieved DenomCapacity does not match the set value")
k.SetDenomCapacity(ctx, types.DenomCapacity{
Denom: testDenom,
CapacityList: []dtypes.SerializableInt{}, // Empty list, results in deletion of the key.
})
// Check that the key is deleted under `DenomCapacity` storage.
require.Equal(t,
types.DenomCapacity{
Denom: testDenom,
CapacityList: nil,
},
k.GetDenomCapacity(ctx, testDenom),
"retrieved LimitParams do not match the set value",
)
"retrieved DenomCapacity does not match the set value",

Comment on lines +1 to 4
package ratelimit

import (
"context"
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [33-33]

There is a typo in the comment describing the AppModuleBasic interface implementation. The word "methods" is incorrectly written as "methodsa".

- // AppModuleBasic implements the AppModuleBasic interface that defines the independent methodsa Cosmos SDK module
+ // AppModuleBasic implements the AppModuleBasic interface that defines the independent methods a Cosmos SDK module

Comment on lines 33 to 35
ratelimit: new (await import("./ratelimit/query.lcd")).LCDQueryClient({
requestClient
}),
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 NOTE
Codebase verification is a beta feature.

The verification process has revealed that the query.lcd.ts file is still located within the ibcratelimit directory, not the ratelimit directory as would be expected following the PR's objectives and summary. This suggests that the file may not have been correctly renamed or moved according to the changes described in the PR. Please verify the implementation of the file renaming and movement to align with the module reorganization.

  • The query.lcd.ts file is located in the ibcratelimit directory instead of the ratelimit directory.
Analysis chain

The addition of the ratelimit property to the createLCDClient function's return object is consistent with the PR's objectives and the renaming of the module. Ensure that the new import path ./ratelimit/query.lcd is correct and that the file exists.


Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the existence of the `query.lcd.ts` file in the `ratelimit` directory.
fd 'query.lcd.ts' 'indexer/packages/v4-protos/src/codegen/dydxprotocol/ratelimit'

Length of output: 228



Script:

#!/bin/bash
# Search for the `query.lcd.ts` file within the `ratelimit` directory across the entire codebase.
fd 'query.lcd.ts' --exec echo {} \; | grep 'ratelimit/query.lcd.ts'

Length of output: 148

Comment on lines 10 to 16
clob: new (await import("./clob/tx.rpc.msg")).MsgClientImpl(rpc),
delaymsg: new (await import("./delaymsg/tx.rpc.msg")).MsgClientImpl(rpc),
feetiers: new (await import("./feetiers/tx.rpc.msg")).MsgClientImpl(rpc),
ibcratelimit: new (await import("./ibcratelimit/tx.rpc.msg")).MsgClientImpl(rpc),
ratelimit: new (await import("./ratelimit/tx.rpc.msg")).MsgClientImpl(rpc),
perpetuals: new (await import("./perpetuals/tx.rpc.msg")).MsgClientImpl(rpc),
prices: new (await import("./prices/tx.rpc.msg")).MsgClientImpl(rpc),
rewards: new (await import("./rewards/tx.rpc.msg")).MsgClientImpl(rpc),
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 NOTE
Codebase verification is a beta feature.

The verification process has revealed that the ratelimit/tx.rpc.msg.ts file does not exist in the expected directory, which is inconsistent with the changes made in the pull request. The ast-grep command did not produce any output, which is consistent with the file not being present. Therefore, the reference to the ratelimit module in the createRPCMsgClient function cannot be resolved correctly.

  • The ratelimit/tx.rpc.msg.ts file is not present in the indexer/packages/v4-protos/src/codegen/dydxprotocol/ratelimit directory as expected.
Analysis chain

The change from ibcratelimit to ratelimit in the createRPCMsgClient function aligns with the PR objectives and the renaming of the module. Ensure that the new import path is correct and that all references to the old module name have been updated throughout the codebase.


I will correct the script to properly verify the existence of the new import path and to ensure that the commands for searching for references to ibcratelimit and its usage are accurate.


I will adjust the script to specifically check for the tx.rpc.msg.ts file within the ratelimit directory and verify the presence of the new ratelimit property to ensure the replacement is complete.


I will verify the existence of the ratelimit/tx.rpc.msg.ts file directly and confirm the accuracy of the ast-grep command.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the new import path exists.
fd 'tx.rpc.msg.ts' --exec test -f {} \; -a -d 'src/codegen/dydxprotocol/ratelimit'

# Search for any remaining references to the old module name.
rg 'ibcratelimit'

# Verify that the old property is not used anymore.
ast-grep --lang typescript --pattern $'ibcratelimit: new (await import("./ibcratelimit/tx.rpc.msg")).MsgClientImpl($_)'

Length of output: 372



Script:

#!/bin/bash
# Corrected command to verify the new import path exists by checking for the file within the specified directory.
fd 'tx.rpc.msg.ts' --exec sh -c 'test -f {} && echo {} is present' \;

# Re-run the search for any remaining references to the old module name to confirm the lack of output.
rg 'ibcratelimit'

# Re-run the ast-grep command to confirm that the old property is not used anymore.
ast-grep --lang typescript --pattern $'ibcratelimit: new (await import("./ibcratelimit/tx.rpc.msg")).MsgClientImpl($_)'

Length of output: 1255



Script:

#!/bin/bash
# Adjusted command to specifically check for the tx.rpc.msg.ts file within the ratelimit directory.
fd 'tx.rpc.msg.ts' --exec sh -c 'test -f {} && echo {} is present' \; | grep 'ratelimit/tx.rpc.msg.ts'

# Verify the presence of the new ratelimit property to ensure the replacement is complete.
ast-grep --lang typescript --pattern $'ratelimit: new (await import("./ratelimit/tx.rpc.msg")).MsgClientImpl($_)'

Length of output: 308



Script:

#!/bin/bash
# Directly check for the existence of the ratelimit/tx.rpc.msg.ts file.
test -f ./indexer/packages/v4-protos/src/codegen/dydxprotocol/ratelimit/tx.rpc.msg.ts && echo "ratelimit/tx.rpc.msg.ts is present" || echo "ratelimit/tx.rpc.msg.ts is not present"

# Confirm the accuracy of the ast-grep command for the new ratelimit property.
ast-grep --lang typescript --pattern $'ratelimit: new (await import("./ratelimit/tx.rpc.msg")).MsgClientImpl($_)'

Length of output: 289

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between cc506a6 and 415990e.
Files selected for processing (8)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts (6 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/lcd.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/ratelimit/genesis.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/ratelimit/query.lcd.ts (2 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/ratelimit/query.rpc.Query.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/ratelimit/tx.rpc.msg.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/rpc.query.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/rpc.tx.ts (1 hunks)
Files skipped from review due to trivial changes (2)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/ratelimit/genesis.ts
Files skipped from review as they are similar to previous changes (3)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/lcd.ts
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/rpc.query.ts
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/rpc.tx.ts
Additional comments: 7
indexer/packages/v4-protos/src/codegen/dydxprotocol/ratelimit/query.lcd.ts (2)
  • 18-20: The update to the endpoint URL in the listLimitParams method is consistent with the module renaming from ibcratelimit to ratelimit. This change aligns with the PR objectives and the broader refactoring effort.

  • 34-35: The update to the endpoint URL in the capacityByDenom method is consistent with the module renaming from ibcratelimit to ratelimit. This change aligns with the PR objectives and the broader refactoring effort.

indexer/packages/v4-protos/src/codegen/dydxprotocol/ratelimit/query.rpc.Query.ts (3)
  • 25-25: The update to the namespace in the rpc.request call within the listLimitParams method correctly reflects the new module name.

  • 31-31: The update to the namespace in the rpc.request call within the capacityByDenom method correctly reflects the new module name.

  • 23-33: Verify that all references to the old namespace dydxprotocol.ibcratelimit have been updated to dydxprotocol.ratelimit throughout the codebase.

indexer/packages/v4-protos/src/codegen/dydxprotocol/ratelimit/tx.rpc.msg.ts (2)
  • 22-26: The update to the RPC request path in the setLimitParams method is consistent with the renaming of the module from ibcratelimit to ratelimit. This change aligns with the PR objectives and should not introduce any issues as long as all corresponding server-side and client-side references have been updated accordingly.

  • 28-32: Similarly, the update to the RPC request path in the deleteLimitParams method is consistent with the renaming of the module. Ensure that all related RPC endpoints have been updated to reflect this new path.

@teddyding teddyding merged commit 316473c into main Dec 12, 2023
30 of 32 checks passed
@teddyding teddyding deleted the td/CORE-824 branch December 12, 2023 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants