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-826] Initial protos for x/ibcratelimit #864

Merged
merged 4 commits into from
Dec 8, 2023

Conversation

teddyding
Copy link
Contributor

Changelist

Initial protos for x/ibcratelimit. Design doc here. While it's not 100% finalized, wanted to check in the current version to get the ball rolling.

Test Plan

N/A

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 8, 2023

CORE-826 Check in protos

Copy link
Contributor

coderabbitai bot commented Dec 8, 2023

Walkthrough

The updates involve the introduction of new protocol buffer definitions and gRPC services for the dydxprotocol.ibcratelimit package, which is part of a Cosmos SDK-based blockchain application. These changes include new messages for rate limit parameters, state genesis, and query services, as well as transaction-related RPC methods for setting and deleting limit parameters. Additionally, there are updates to TypeScript codegen files to reflect these new protobuf definitions and services.

Changes

File Path Change Summary
proto/dydxprotocol/ibcratelimit/... Introduced new protobuf definitions for DenomCapacity, GenesisState, LimitParams, Limiter, and gRPC service Query and Msg with related RPC methods.
indexer/packages/v4-protos/src/codegen/dydxprotocol/... Updated TypeScript codegen files to align with new protobuf definitions, including changes to interfaces, encoding/decoding functions, and gRPC service implementations.
indexer/packages/v4-protos/src/codegen/gogoproto/bundle.ts Updated import statement and reassignment of the exported constant gogoproto.
indexer/packages/v4-protos/src/codegen/google/bundle.ts Reorganized import statements and updated namespace declarations with new import numbers.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

Note: For conversation with the bot, please use the review comments on code diffs or files.

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

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 fe82149 and 2bceab4.
Files ignored due to filter (5)
  • protocol/x/ibcratelimit/types/capacity.pb.go
  • protocol/x/ibcratelimit/types/genesis.pb.go
  • protocol/x/ibcratelimit/types/limit_params.pb.go
  • protocol/x/ibcratelimit/types/query.pb.go
  • protocol/x/ibcratelimit/types/tx.pb.go
Files selected for processing (5)
  • proto/dydxprotocol/ibcratelimit/capacity.proto (1 hunks)
  • proto/dydxprotocol/ibcratelimit/genesis.proto (1 hunks)
  • proto/dydxprotocol/ibcratelimit/limit_params.proto (1 hunks)
  • proto/dydxprotocol/ibcratelimit/query.proto (1 hunks)
  • proto/dydxprotocol/ibcratelimit/tx.proto (1 hunks)
Additional comments: 10
proto/dydxprotocol/ibcratelimit/capacity.proto (1)
  • 9-20: The DenomCapacity message is well-defined with clear comments explaining the purpose of each field. The use of bytes for capacity_list with a custom type SerializableInt is noted, which should ensure that the capacity amounts are serialized efficiently. The nullable option is set to false, which is appropriate for repeated fields to avoid unnecessary null checks.
proto/dydxprotocol/ibcratelimit/genesis.proto (1)
  • 9-13: The GenesisState message definition correctly includes a repeated field limit_params_list of type LimitParams with the gogoproto.nullable option set to false, ensuring that the list cannot contain null elements.
proto/dydxprotocol/ibcratelimit/limit_params.proto (1)
  • 9-35: The LimitParams and Limiter message definitions are well-structured and align with the PR's objective to define rate limiting parameters. The use of bytes for baseline_minimum with a custom type SerializableInt ensures that large integer values can be handled correctly. Ensure that the custom type SerializableInt is well-documented and tested, as it is critical for the correct serialization and deserialization of these values.
proto/dydxprotocol/ibcratelimit/query.proto (4)
  • 10-18: The gRPC service Query is correctly defined with the two RPC methods ListLimitParams and CapacityByDenom. The methods are well-documented, indicating their purpose, which aligns with the PR's objective to introduce a global withdrawal speed limit feature.

  • 20-26: The ListLimitParamsRequest and ListLimitParamsResponse messages are defined correctly. The limit_params_list field in ListLimitParamsResponse is a repeated field of LimitParams, which is consistent with the summary provided.

  • 28-46: The QueryCapacityByDenomRequest and QueryCapacityByDenomResponse messages are defined correctly. The QueryCapacityByDenomRequest includes a denom field for the token denomination, and the QueryCapacityByDenomResponse includes a repeated field results of type CapacityResult, which aligns with the summary provided.

  • 33-40: The CapacityResult message uses a custom type for the capacity field, which is specified to be non-nullable. Ensure that the custom type github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt is correctly implemented and that all parts of the codebase that interact with CapacityResult are aware of how to handle this custom type.


The usage of the custom type SerializableInt in the CapacityResult message is consistent with its implementation and usage throughout the codebase. No issues found.

proto/dydxprotocol/ibcratelimit/tx.proto (3)
  • 10-16: The Msg service definition correctly introduces the SetLimitParams and DeleteLimitParams RPC methods as described in the summary.

  • 18-26: The MsgSetLimitParams message is well-defined with an authority field to specify the signer and a limit_params field to define the parameters to set.

  • 31-39: The MsgDeleteLimitParams message is correctly structured with an authority field for the signer and a denom field to identify the LimitParams to be deleted.

// SetLimitParams sets a `LimitParams` object in state.
rpc SetLimitParams(MsgSetLimitParams) returns (MsgSetLimitParamsResponse);

// DeleteLimitParams removes a `LimitParams` object in state.
Copy link
Contributor

Choose a reason for hiding this comment

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

mega nit:

Suggested change
// DeleteLimitParams removes a `LimitParams` object in state.
// DeleteLimitParams removes a `LimitParams` object from state.

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a1763ef and 07d6bbe.
Files ignored due to filter (3)
  • protocol/x/ibcratelimit/types/capacity.pb.go
  • protocol/x/ibcratelimit/types/query.pb.go
  • protocol/x/ibcratelimit/types/tx.pb.go
Files selected for processing (16)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts (3 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/ibcratelimit/capacity.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/ibcratelimit/genesis.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/ibcratelimit/limit_params.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/ibcratelimit/query.rpc.Query.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/ibcratelimit/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/ibcratelimit/tx.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)
  • indexer/packages/v4-protos/src/codegen/gogoproto/bundle.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/google/bundle.ts (1 hunks)
  • proto/dydxprotocol/ibcratelimit/capacity.proto (1 hunks)
  • proto/dydxprotocol/ibcratelimit/limit_params.proto (1 hunks)
  • proto/dydxprotocol/ibcratelimit/query.proto (1 hunks)
  • proto/dydxprotocol/ibcratelimit/tx.proto (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/gogoproto/bundle.ts
Files skipped from review as they are similar to previous changes (4)
  • proto/dydxprotocol/ibcratelimit/capacity.proto
  • proto/dydxprotocol/ibcratelimit/limit_params.proto
  • proto/dydxprotocol/ibcratelimit/query.proto
  • proto/dydxprotocol/ibcratelimit/tx.proto
Additional comments: 13
indexer/packages/v4-protos/src/codegen/dydxprotocol/ibcratelimit/capacity.ts (4)
  • 5-18: The TypeScript interface DenomCapacity is correctly defined with appropriate comments explaining the properties. The capacityList is an array of Uint8Array, which aligns with the expected protobuf byte array type for representing lists of binary data.

  • 21-34: The DenomCapacitySDKType interface is consistent with the DenomCapacity interface, with the property capacity_list following the snake_case naming convention typically used in protobuf definitions. This ensures consistency between the TypeScript code and the protobuf definitions.

  • 36-41: The createBaseDenomCapacity function provides a clean and clear way to create a base DenomCapacity object with default values. This is a good practice for initializing objects that will be populated later, either through decoding or partial object updates.

  • 43-87: The DenomCapacity class contains encode, decode, and fromPartial methods which are essential for working with protobuf data in TypeScript. These methods are implemented correctly, handling the encoding of non-empty strings and arrays of bytes, as well as decoding and constructing partial objects from provided values.

indexer/packages/v4-protos/src/codegen/dydxprotocol/ibcratelimit/genesis.ts (1)
  • 1-59: The changes to the GenesisState and GenesisStateSDKType interfaces, along with their associated methods, are consistent with the PR objectives and the summary provided. The code is well-structured and follows the conventions for defining protobuf-related types and methods in TypeScript. The encode, decode, and fromPartial methods are correctly implemented to handle the limitParamsList field.
indexer/packages/v4-protos/src/codegen/dydxprotocol/ibcratelimit/query.rpc.Query.ts (5)
  • 7-12: The interface Query correctly defines the two methods listLimitParams and capacityByDenom as described in the PR summary. The optional parameter in listLimitParams is consistent with the gRPC convention for request objects that may not require parameters.

  • 14-21: The QueryClientImpl class properly implements the Query interface and binds the methods within the constructor to ensure the correct this context when the methods are called. This is a good practice in TypeScript to avoid issues with this context in callbacks.

  • 23-26: The listLimitParams method implementation correctly encodes the request, sends the gRPC request, and decodes the response. This is in line with the expected behavior for a gRPC client method.

  • 29-32: The capacityByDenom method follows the same pattern as listLimitParams for encoding the request, sending the gRPC request, and decoding the response. This consistency in method implementation is good for maintainability.

  • 35-48: The createRpcQueryExtension function creates a new QueryClientImpl instance and returns an object with methods that proxy the calls to the service's methods. This pattern allows for extending the QueryClient with additional methods, which is a flexible design choice.

indexer/packages/v4-protos/src/codegen/dydxprotocol/rpc.query.ts (1)
  • 19-19: The addition of the ibcratelimit module to the createRPCQueryClient function is consistent with the PR objectives and the provided summaries. This change is necessary to support the new x/ibcratelimit module in the dydxprotocol.
indexer/packages/v4-protos/src/codegen/dydxprotocol/rpc.tx.ts (1)
  • 13-13: The addition of the ibcratelimit module to the createRPCMsgClient function is consistent with the PR objectives and the AI-generated summaries. This change integrates the new rate limiting functionality into the RPC message client creation process.
indexer/packages/v4-protos/src/codegen/google/bundle.ts (1)
  • 1-16: The changes to the import statements and namespace declarations are consistent with the summary provided. The import numbers have been incremented, which aligns with the addition of new modules or reorganization of the codebase. Ensure that these changes do not break any references in the codebase where these namespaces are used.

Comment on lines +58 to +63
export interface LimiterSDKType {
/**
* period_sec is the rolling time period for which the limit applies
* e.g. 3600 (an hour)
*/
period_sec: number;
Copy link
Contributor

Choose a reason for hiding this comment

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

The naming convention for period_sec in LimiterSDKType should be consistent with the Limiter interface. Consider renaming it to periodSec to match the camelCase convention used in TypeScript.

export interface LimiterSDKType {
  /**
   * period_sec is the rolling time period for which the limit applies
   * e.g. 3600 (an hour)
   */
-  period_sec: number;
+  periodSec: number;

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
export interface LimiterSDKType {
/**
* period_sec is the rolling time period for which the limit applies
* e.g. 3600 (an hour)
*/
period_sec: number;
export interface LimiterSDKType {
/**
* periodSec is the rolling time period for which the limit applies
* e.g. 3600 (an hour)
*/
periodSec: number;

* e.g. 100_000_000_000 uusdc for 100k USDC; 5e22 adv4tnt for 50k DV4TNT
*/

baselineMinimum: Uint8Array;
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a comment to clarify the expected format of the baselineMinimum byte array in the Limiter interface.

+ // baselineMinimum should be encoded as a byte array representing the numeric value.
  baselineMinimum: Uint8Array;

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
baselineMinimum: Uint8Array;
// baselineMinimum should be encoded as a byte array representing the numeric value.
baselineMinimum: Uint8Array;

/** ListLimitParamsRequest is a request type of the ListLimitParams RPC method. */

export interface ListLimitParamsRequest {}
/** ListLimitParamsRequest is a request type of the ListLimitParams RPC method. */
Copy link
Contributor

Choose a reason for hiding this comment

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

There are duplicate comments above the ListLimitParamsRequest interface. Consider removing the duplicate to improve code clarity.

- /** ListLimitParamsRequest is a request type of the ListLimitParams RPC method. */

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
/** ListLimitParamsRequest is a request type of the ListLimitParams RPC method. */

Comment on lines +22 to +32
setLimitParams(request: MsgSetLimitParams): Promise<MsgSetLimitParamsResponse> {
const data = MsgSetLimitParams.encode(request).finish();
const promise = this.rpc.request("dydxprotocol.ibcratelimit.Msg", "SetLimitParams", data);
return promise.then(data => MsgSetLimitParamsResponse.decode(new _m0.Reader(data)));
}

deleteLimitParams(request: MsgDeleteLimitParams): Promise<MsgDeleteLimitParamsResponse> {
const data = MsgDeleteLimitParams.encode(request).finish();
const promise = this.rpc.request("dydxprotocol.ibcratelimit.Msg", "DeleteLimitParams", data);
return promise.then(data => MsgDeleteLimitParamsResponse.decode(new _m0.Reader(data)));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The MsgClientImpl class methods setLimitParams and deleteLimitParams do not include error handling. Consider adding try-catch blocks to handle potential rejections from the rpc.request method and provide a more robust implementation.

async setLimitParams(request: MsgSetLimitParams): Promise<MsgSetLimitParamsResponse> {
  try {
    const data = MsgSetLimitParams.encode(request).finish();
    const response = await this.rpc.request("dydxprotocol.ibcratelimit.Msg", "SetLimitParams", data);
    return MsgSetLimitParamsResponse.decode(new _m0.Reader(response));
  } catch (error) {
    // Handle or rethrow the error as appropriate
    throw error;
  }
}

async deleteLimitParams(request: MsgDeleteLimitParams): Promise<MsgDeleteLimitParamsResponse> {
  try {
    const data = MsgDeleteLimitParams.encode(request).finish();
    const response = await this.rpc.request("dydxprotocol.ibcratelimit.Msg", "DeleteLimitParams", data);
    return MsgDeleteLimitParamsResponse.decode(new _m0.Reader(response));
  } catch (error) {
    // Handle or rethrow the error as appropriate
    throw error;
  }
}

periodSec: number;
capacity: Uint8Array;
}
/** CapacityResult is a specific rate limit for a denom. */
Copy link
Contributor

Choose a reason for hiding this comment

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

There are duplicate comments above the CapacityResult interface. Consider removing the duplicate to improve code clarity.

- /** CapacityResult is a specific rate limit for a denom. */

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
/** CapacityResult is a specific rate limit for a denom. */

/** MsgSetLimitParamsResponse is the Msg/SetLimitParams response type. */

export interface MsgSetLimitParamsResponseSDKType {}
/** MsgDeleteLimitParams is the Msg/SetLimitParams request type. */
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment above MsgDeleteLimitParams incorrectly states that it is the Msg/SetLimitParams request type. This should be corrected to Msg/DeleteLimitParams.

- /** MsgDeleteLimitParams is the Msg/SetLimitParams request type. */
+ /** MsgDeleteLimitParams is the Msg/DeleteLimitParams request type. */

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
/** MsgDeleteLimitParams is the Msg/SetLimitParams request type. */
/** MsgDeleteLimitParams is the Msg/DeleteLimitParams request type. */


denom: string;
}
/** MsgDeleteLimitParams is the Msg/SetLimitParams request type. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, the comment above MsgDeleteLimitParamsSDKType also incorrectly states that it is the Msg/SetLimitParams request type. This should be corrected to Msg/DeleteLimitParams.

- /** MsgDeleteLimitParams is the Msg/SetLimitParams request type. */
+ /** MsgDeleteLimitParams is the Msg/DeleteLimitParams request type. */

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
/** MsgDeleteLimitParams is the Msg/SetLimitParams request type. */
/** MsgDeleteLimitParams is the Msg/DeleteLimitParams request type. */

@teddyding teddyding merged commit fcda61d into main Dec 8, 2023
30 of 31 checks passed
@teddyding teddyding deleted the td/scaffold-ibcratelimit branch December 8, 2023 20:16
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.

2 participants