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 1 commit
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
10 changes: 10 additions & 0 deletions proto/crosschain/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,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
26 changes: 26 additions & 0 deletions proto/crosschain/rate_limiter_flags.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syntax = "proto3";
package zetachain.zetacore.crosschain;

import "gogoproto/gogo.proto";
import "pkg/coin/coin.proto";

option go_package = "github.com/zeta-chain/zetacore/x/crosschain/types";

// ZRC20Rate defines the conversion rate of ZRC20 to ZETA
message ZRC20Rate {
int64 chain_id = 1;
coin.CoinType coin_type = 2;
string asset = 3;
double conversion_rate = 4;
}

// RateLimiterFlags defines the outbound rate limiter flags
message RateLimiterFlags {
bool is_enabled = 1;
int64 rate_limit_window = 2;
string rate_limit_in_zeta = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
(gogoproto.nullable) = false
];
repeated ZRC20Rate zrc20_rates = 4;
}
1 change: 1 addition & 0 deletions typescript/crosschain/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export * from "./in_tx_tracker_pb";
export * from "./last_block_height_pb";
export * from "./out_tx_tracker_pb";
export * from "./query_pb";
export * from "./rate_limiter_flags_pb";
export * from "./tx_pb";
58 changes: 58 additions & 0 deletions typescript/crosschain/query_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,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
91 changes: 91 additions & 0 deletions typescript/crosschain/rate_limiter_flags_pb.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// @generated by protoc-gen-es v1.3.0 with parameter "target=dts"
// @generated from file crosschain/rate_limiter_flags.proto (package zetachain.zetacore.crosschain, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf";
import { Message, proto3 } from "@bufbuild/protobuf";
import type { CoinType } from "../pkg/coin/coin_pb.js";

/**
* ZRC20Rate defines the conversion rate of ZRC20 to ZETA
*
* @generated from message zetachain.zetacore.crosschain.ZRC20Rate
*/
export declare class ZRC20Rate extends Message<ZRC20Rate> {
/**
* @generated from field: int64 chain_id = 1;
*/
chainId: bigint;

/**
* @generated from field: coin.CoinType coin_type = 2;
*/
coinType: CoinType;

/**
* @generated from field: string asset = 3;
*/
asset: string;

/**
* @generated from field: double conversion_rate = 4;
*/
conversionRate: number;

constructor(data?: PartialMessage<ZRC20Rate>);

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

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

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

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

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

/**
* RateLimiterFlags defines the outbound rate limiter flags
*
* @generated from message zetachain.zetacore.crosschain.RateLimiterFlags
*/
export declare class RateLimiterFlags extends Message<RateLimiterFlags> {
/**
* @generated from field: bool is_enabled = 1;
*/
isEnabled: boolean;

/**
* @generated from field: int64 rate_limit_window = 2;
*/
rateLimitWindow: bigint;

/**
* @generated from field: string rate_limit_in_zeta = 3;
*/
rateLimitInZeta: string;

/**
* @generated from field: repeated zetachain.zetacore.crosschain.ZRC20Rate zrc20_rates = 4;
*/
zrc20Rates: ZRC20Rate[];

constructor(data?: PartialMessage<RateLimiterFlags>);

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

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

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

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

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

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