Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: outbound cctx scheduling with rate limiter #2045

Merged
merged 15 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
* [1935](https://github.com/zeta-chain/node/pull/1935) - add an operational authority group
* [1954](https://github.com/zeta-chain/node/pull/1954) - add metric for concurrent keysigns
* [2006](https://github.com/zeta-chain/node/pull/2006) - add Amoy testnet static chain information
* [2045](https://github.com/zeta-chain/node/pull/2046) - add grpc query with outbound rate limit for zetaclient to use
* [2046](https://github.com/zeta-chain/node/pull/2046) - add state variable in crosschain for rate limiter flags

### Tests
Expand Down
34 changes: 34 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26608,6 +26608,27 @@ paths:
format: int64
tags:
- Query
/zeta-chain/crosschain/cctxPendingWithRateLimit:
get:
summary: Queries a list of pending cctxs with rate limit.
operationId: Query_CctxListPendingWithinRateLimit
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/crosschainQueryListCctxPendingWithRateLimitResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: limit
in: query
required: false
type: integer
format: int64
tags:
- Query
/zeta-chain/crosschain/convertGasToZeta:
get:
operationId: Query_ConvertGasToZeta
Expand Down Expand Up @@ -53981,6 +54002,19 @@ definitions:
totalPending:
type: string
format: uint64
crosschainQueryListCctxPendingWithRateLimitResponse:
type: object
properties:
cross_chain_tx:
type: array
items:
type: object
$ref: '#/definitions/crosschainCrossChainTx'
total_pending:
type: string
format: uint64
rate_limit_exceeded:
type: boolean
crosschainQueryMessagePassingProtocolFeeResponse:
type: object
properties:
Expand Down
15 changes: 15 additions & 0 deletions proto/crosschain/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ service Query {
option (google.api.http).get = "/zeta-chain/crosschain/cctxPending";
}

// Queries a list of pending cctxs with rate limit.
rpc CctxListPendingWithinRateLimit(QueryListCctxPendingWithRateLimitRequest) returns (QueryListCctxPendingWithRateLimitResponse) {
option (google.api.http).get = "/zeta-chain/crosschain/cctxPendingWithRateLimit";
}

rpc ZetaAccounting(QueryZetaAccountingRequest) returns (QueryZetaAccountingResponse) {
option (google.api.http).get = "/zeta-chain/crosschain/zetaAccounting";
}
Expand Down Expand Up @@ -258,6 +263,16 @@ message QueryListCctxPendingResponse {
uint64 totalPending = 2;
}

message QueryListCctxPendingWithRateLimitRequest {
uint32 limit = 2;
}

message QueryListCctxPendingWithRateLimitResponse {
repeated CrossChainTx cross_chain_tx = 1;
uint64 total_pending = 2;
bool rate_limit_exceeded = 3;
}

message QueryLastZetaHeightRequest {}

message QueryLastZetaHeightResponse {
Expand Down
20 changes: 20 additions & 0 deletions testutil/keeper/mocks/crosschain/fungible.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions typescript/crosschain/query_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,64 @@ export declare class QueryListCctxPendingResponse extends Message<QueryListCctxP
static equals(a: QueryListCctxPendingResponse | PlainMessage<QueryListCctxPendingResponse> | undefined, b: QueryListCctxPendingResponse | PlainMessage<QueryListCctxPendingResponse> | undefined): boolean;
}

/**
* @generated from message zetachain.zetacore.crosschain.QueryListCctxPendingWithRateLimitRequest
*/
export declare class QueryListCctxPendingWithRateLimitRequest extends Message<QueryListCctxPendingWithRateLimitRequest> {
/**
* @generated from field: uint32 limit = 2;
*/
limit: number;

constructor(data?: PartialMessage<QueryListCctxPendingWithRateLimitRequest>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.crosschain.QueryListCctxPendingWithRateLimitRequest";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): QueryListCctxPendingWithRateLimitRequest;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): QueryListCctxPendingWithRateLimitRequest;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): QueryListCctxPendingWithRateLimitRequest;

static equals(a: QueryListCctxPendingWithRateLimitRequest | PlainMessage<QueryListCctxPendingWithRateLimitRequest> | undefined, b: QueryListCctxPendingWithRateLimitRequest | PlainMessage<QueryListCctxPendingWithRateLimitRequest> | undefined): boolean;
}

/**
* @generated from message zetachain.zetacore.crosschain.QueryListCctxPendingWithRateLimitResponse
*/
export declare class QueryListCctxPendingWithRateLimitResponse extends Message<QueryListCctxPendingWithRateLimitResponse> {
/**
* @generated from field: repeated zetachain.zetacore.crosschain.CrossChainTx cross_chain_tx = 1;
*/
crossChainTx: CrossChainTx[];

/**
* @generated from field: uint64 total_pending = 2;
*/
totalPending: bigint;

/**
* @generated from field: bool rate_limit_exceeded = 3;
*/
rateLimitExceeded: boolean;

constructor(data?: PartialMessage<QueryListCctxPendingWithRateLimitResponse>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.crosschain.QueryListCctxPendingWithRateLimitResponse";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): QueryListCctxPendingWithRateLimitResponse;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): QueryListCctxPendingWithRateLimitResponse;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): QueryListCctxPendingWithRateLimitResponse;

static equals(a: QueryListCctxPendingWithRateLimitResponse | PlainMessage<QueryListCctxPendingWithRateLimitResponse> | undefined, b: QueryListCctxPendingWithRateLimitResponse | PlainMessage<QueryListCctxPendingWithRateLimitResponse> | undefined): boolean;
}

/**
* @generated from message zetachain.zetacore.crosschain.QueryLastZetaHeightRequest
*/
Expand Down
4 changes: 2 additions & 2 deletions x/crosschain/keeper/foreign_coins.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
fungibleModuleTypes "github.com/zeta-chain/zetacore/x/fungible/types"
)

func (k Keeper) GetAllForeignCoins(ctx sdk.Context) ([]fungibleModuleTypes.ForeignCoins, error) {
func (k Keeper) GetAllForeignCoins(ctx sdk.Context) []fungibleModuleTypes.ForeignCoins {
chains := k.zetaObserverKeeper.GetSupportedChains(ctx)
var fCoins []fungibleModuleTypes.ForeignCoins
for _, chain := range chains {
fCoins = append(fCoins, k.fungibleKeeper.GetAllForeignCoinsForChain(ctx, chain.ChainId)...)
}
return fCoins, nil
return fCoins
}
3 changes: 1 addition & 2 deletions x/crosschain/keeper/foreign_coins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func TestKeeper_GetAllForeignCoins(t *testing.T) {
fc.ForeignChainId = 101
k.GetFungibleKeeper().SetForeignCoins(ctx, fc)

res, err := k.GetAllForeignCoins(ctx)
require.NoError(t, err)
res := k.GetAllForeignCoins(ctx)
require.Equal(t, 1, len(res))
}
Loading
Loading