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(crosschain): add rate limiter flags singleton state variable #2046

Merged
merged 10 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
* [2046](https://github.com/zeta-chain/node/pull/2046) - add state variable in crosschain for rate limiter flags

### Tests

Expand Down
1 change: 1 addition & 0 deletions docs/cli/zetacored/zetacored_query_crosschain.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ zetacored query crosschain [flags]
* [zetacored query crosschain show-gas-price](zetacored_query_crosschain_show-gas-price.md) - shows a gasPrice
* [zetacored query crosschain show-in-tx-hash-to-cctx](zetacored_query_crosschain_show-in-tx-hash-to-cctx.md) - shows a inTxHashToCctx
* [zetacored query crosschain show-out-tx-tracker](zetacored_query_crosschain_show-out-tx-tracker.md) - shows a OutTxTracker
* [zetacored query crosschain update_rate_limit_flags](zetacored_query_crosschain_update_rate_limit_flags.md) - shows the rate limiter flags

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# query crosschain update_rate_limit_flags

shows the rate limiter flags

```
zetacored query crosschain update_rate_limit_flags [flags]
```

### Options

```
--grpc-addr string the gRPC endpoint to use for this chain
--grpc-insecure allow gRPC over insecure channels, if not TLS the server must use TLS
--height int Use a specific height to query state at (this can error if the node is pruning state)
-h, --help help for update_rate_limit_flags
--node string [host]:[port] to Tendermint RPC interface for this chain
-o, --output string Output format (text|json)
```

### Options inherited from parent commands

```
--chain-id string The network chain ID
--home string directory for config and data
--log_format string The logging format (json|plain)
--log_level string The logging level (trace|debug|info|warn|error|fatal|panic)
--trace print out full stack trace on errors
```

### SEE ALSO

* [zetacored query crosschain](zetacored_query_crosschain.md) - Querying commands for the crosschain module

47 changes: 47 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27187,6 +27187,21 @@ paths:
$ref: '#/definitions/googlerpcStatus'
tags:
- Query
/zeta-chain/crosschain/rateLimiterFlags:
get:
summary: Queries the rate limiter flags
operationId: Query_RateLimiterFlags
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/crosschainQueryRateLimiterFlagsResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
tags:
- Query
/zeta-chain/crosschain/zetaAccounting:
get:
operationId: Query_ZetaAccounting
Expand Down Expand Up @@ -53614,6 +53629,13 @@ definitions:
- PendingRevert: outbound cannot succeed; should revert inbound
- Reverted: inbound reverted.
- Aborted: inbound tx error or invalid paramters and cannot revert; just abort. But the amount can be refunded to zetachain using and admin proposal
crosschainConversion:
type: object
properties:
zrc20:
type: string
rate:
type: string
crosschainCrossChainTx:
type: object
properties:
Expand Down Expand Up @@ -53743,6 +53765,8 @@ definitions:
type: object
crosschainMsgRemoveFromOutTxTrackerResponse:
type: object
crosschainMsgUpdateRateLimiterFlagsResponse:
type: object
crosschainMsgUpdateTssAddressResponse:
type: object
crosschainMsgVoteGasPriceResponse:
Expand Down Expand Up @@ -53962,11 +53986,34 @@ definitions:
properties:
feeInZeta:
type: string
crosschainQueryRateLimiterFlagsResponse:
type: object
properties:
rateLimiterFlags:
$ref: '#/definitions/crosschainRateLimiterFlags'
crosschainQueryZetaAccountingResponse:
type: object
properties:
aborted_zeta_amount:
type: string
crosschainRateLimiterFlags:
type: object
properties:
enabled:
type: boolean
window:
type: string
format: int64
title: window in blocks
rate:
type: string
title: rate in azeta per block
conversions:
type: array
items:
type: object
$ref: '#/definitions/crosschainConversion'
title: conversion in azeta per token
crosschainTxFinalizationStatus:
type: string
enum:
Expand Down
12 changes: 12 additions & 0 deletions docs/spec/crosschain/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,15 @@ message MsgRefundAbortedCCTX {
}
```

## MsgUpdateRateLimiterFlags

UpdateRateLimiterFlags updates the rate limiter flags.
Authorized: admin policy operational.

```proto
message MsgUpdateRateLimiterFlags {
string creator = 1;
RateLimiterFlags rate_limiter_flags = 2;
}
```

2 changes: 2 additions & 0 deletions proto/crosschain/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "crosschain/in_tx_hash_to_cctx.proto";
import "crosschain/in_tx_tracker.proto";
import "crosschain/last_block_height.proto";
import "crosschain/out_tx_tracker.proto";
import "crosschain/rate_limiter_flags.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/zeta-chain/zetacore/x/crosschain/types";
Expand All @@ -21,4 +22,5 @@ message GenesisState {
repeated InTxTracker in_tx_tracker_list = 11 [(gogoproto.nullable) = false];
ZetaAccounting zeta_accounting = 12 [(gogoproto.nullable) = false];
repeated string FinalizedInbounds = 16;
RateLimiterFlags rate_limiter_flags = 17 [(gogoproto.nullable) = false];
}
12 changes: 12 additions & 0 deletions proto/crosschain/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "crosschain/in_tx_hash_to_cctx.proto";
import "crosschain/in_tx_tracker.proto";
import "crosschain/last_block_height.proto";
import "crosschain/out_tx_tracker.proto";
import "crosschain/rate_limiter_flags.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";

Expand Down Expand Up @@ -106,6 +107,11 @@ service Query {
rpc LastZetaHeight(QueryLastZetaHeightRequest) returns (QueryLastZetaHeightResponse) {
option (google.api.http).get = "/zeta-chain/crosschain/lastZetaHeight";
}

// Queries the rate limiter flags
rpc RateLimiterFlags(QueryRateLimiterFlagsRequest) returns (QueryRateLimiterFlagsResponse) {
option (google.api.http).get = "/zeta-chain/crosschain/rateLimiterFlags";
}
}

message QueryZetaAccountingRequest {}
Expand Down Expand Up @@ -274,3 +280,9 @@ message QueryMessagePassingProtocolFeeRequest {}
message QueryMessagePassingProtocolFeeResponse {
string feeInZeta = 1;
}

message QueryRateLimiterFlagsRequest {}

message QueryRateLimiterFlagsResponse {
RateLimiterFlags rateLimiterFlags = 1 [(gogoproto.nullable) = false];
}
30 changes: 30 additions & 0 deletions proto/crosschain/rate_limiter_flags.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
syntax = "proto3";
package zetachain.zetacore.crosschain;

import "gogoproto/gogo.proto";

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

message RateLimiterFlags {
bool enabled = 1;

// window in blocks
int64 window = 2;

// rate in azeta per block
string rate = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
(gogoproto.nullable) = false
];

// conversion in azeta per token
repeated Conversion conversions = 4 [(gogoproto.nullable) = false];
}

message Conversion {
string zrc20 = 1;
string rate = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}
10 changes: 10 additions & 0 deletions proto/crosschain/tx.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
syntax = "proto3";
package zetachain.zetacore.crosschain;

import "crosschain/rate_limiter_flags.proto";
import "gogoproto/gogo.proto";
import "pkg/chains/chains.proto";
import "pkg/coin/coin.proto";
Expand All @@ -23,6 +24,8 @@ service Msg {

rpc AbortStuckCCTX(MsgAbortStuckCCTX) returns (MsgAbortStuckCCTXResponse);
rpc RefundAbortedCCTX(MsgRefundAbortedCCTX) returns (MsgRefundAbortedCCTXResponse);

rpc UpdateRateLimiterFlags(MsgUpdateRateLimiterFlags) returns (MsgUpdateRateLimiterFlagsResponse);
}

message MsgMigrateTssFunds {
Expand Down Expand Up @@ -164,3 +167,10 @@ message MsgRefundAbortedCCTX {
}

message MsgRefundAbortedCCTXResponse {}

message MsgUpdateRateLimiterFlags {
string creator = 1;
RateLimiterFlags rate_limiter_flags = 2 [(gogoproto.nullable) = false];
}

message MsgUpdateRateLimiterFlagsResponse {}
34 changes: 34 additions & 0 deletions testutil/sample/crosschain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"math/rand"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"

"cosmossdk.io/math"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
Expand All @@ -14,6 +16,38 @@ import (
"github.com/zeta-chain/zetacore/x/crosschain/types"
)

func RateLimiterFlags() types.RateLimiterFlags {
r := Rand()

return types.RateLimiterFlags{
Enabled: true,
Window: r.Int63(),
Rate: sdk.NewUint(r.Uint64()),
Conversions: []types.Conversion{
{
Zrc20: EthAddress().Hex(),
Rate: sdk.NewDec(r.Int63()),
},
{
Zrc20: EthAddress().Hex(),
Rate: sdk.NewDec(r.Int63()),
},
{
Zrc20: EthAddress().Hex(),
Rate: sdk.NewDec(r.Int63()),
},
{
Zrc20: EthAddress().Hex(),
Rate: sdk.NewDec(r.Int63()),
},
{
Zrc20: EthAddress().Hex(),
Rate: sdk.NewDec(r.Int63()),
},
},
}
}

func OutTxTracker(t *testing.T, index string) types.OutTxTracker {
r := newRandFromStringSeed(t, index)

Expand Down
6 changes: 6 additions & 0 deletions typescript/crosschain/genesis_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { CrossChainTx, ZetaAccounting } from "./cross_chain_tx_pb.js";
import type { LastBlockHeight } from "./last_block_height_pb.js";
import type { InTxHashToCctx } from "./in_tx_hash_to_cctx_pb.js";
import type { InTxTracker } from "./in_tx_tracker_pb.js";
import type { RateLimiterFlags } from "./rate_limiter_flags_pb.js";

/**
* GenesisState defines the metacore module's genesis state.
Expand Down Expand Up @@ -58,6 +59,11 @@ export declare class GenesisState extends Message<GenesisState> {
*/
FinalizedInbounds: string[];

/**
* @generated from field: zetachain.zetacore.crosschain.RateLimiterFlags rate_limiter_flags = 17;
*/
rateLimiterFlags?: RateLimiterFlags;

constructor(data?: PartialMessage<GenesisState>);

static readonly runtime: typeof proto3;
Expand Down
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";
44 changes: 44 additions & 0 deletions typescript/crosschain/query_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { InTxHashToCctx } from "./in_tx_hash_to_cctx_pb.js";
import type { CrossChainTx } from "./cross_chain_tx_pb.js";
import type { GasPrice } from "./gas_price_pb.js";
import type { LastBlockHeight } from "./last_block_height_pb.js";
import type { RateLimiterFlags } from "./rate_limiter_flags_pb.js";

/**
* @generated from message zetachain.zetacore.crosschain.QueryZetaAccountingRequest
Expand Down Expand Up @@ -1019,3 +1020,46 @@ export declare class QueryMessagePassingProtocolFeeResponse extends Message<Quer
static equals(a: QueryMessagePassingProtocolFeeResponse | PlainMessage<QueryMessagePassingProtocolFeeResponse> | undefined, b: QueryMessagePassingProtocolFeeResponse | PlainMessage<QueryMessagePassingProtocolFeeResponse> | undefined): boolean;
}

/**
* @generated from message zetachain.zetacore.crosschain.QueryRateLimiterFlagsRequest
*/
export declare class QueryRateLimiterFlagsRequest extends Message<QueryRateLimiterFlagsRequest> {
constructor(data?: PartialMessage<QueryRateLimiterFlagsRequest>);

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

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

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

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

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

/**
* @generated from message zetachain.zetacore.crosschain.QueryRateLimiterFlagsResponse
*/
export declare class QueryRateLimiterFlagsResponse extends Message<QueryRateLimiterFlagsResponse> {
/**
* @generated from field: zetachain.zetacore.crosschain.RateLimiterFlags rateLimiterFlags = 1;
*/
rateLimiterFlags?: RateLimiterFlags;

constructor(data?: PartialMessage<QueryRateLimiterFlagsResponse>);

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

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

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

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

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

Loading
Loading