Skip to content

Commit

Permalink
Removed legacy gov tx format (#3)
Browse files Browse the repository at this point in the history
* gov.proto -> tx.proto

* updated tx protos

* added proto comments

* added proto comments

* updated codec.go

* added msgs

* added msgs tests

* added authority to keeper and removed gov handlers

* moved gov functions out to msg server

* implemented msg_server

* updated msg_server tests

* removed tx client

* updated simapp

* go mod tidy

* fixed msgs_tests

* fixed msg_server tests

* changes from review

* moved add/update rate limit to outside msg_server

* file re-org

* nit moved function
  • Loading branch information
sampocs authored Feb 24, 2024
1 parent 1763a05 commit 29a35e9
Show file tree
Hide file tree
Showing 42 changed files with 4,287 additions and 4,233 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ app.RatelimitKeeper = *ratelimitkeeper.NewKeeper(
appCodec,
keys[ratelimittypes.StoreKey],
app.GetSubspace(ratelimittypes.ModuleName),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
app.BankKeeper,
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.ChannelKeeper, // ICS4Wrapper
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
cosmossdk.io/tools/rosetta v0.2.1
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-proto v1.0.0-beta.2
github.com/cosmos/cosmos-sdk v0.47.5
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-go/v7 v7.3.1
Expand Down Expand Up @@ -53,7 +54,6 @@ require (
github.com/coinbase/rosetta-sdk-go/types v1.0.0 // indirect
github.com/confio/ics23/go v0.9.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.2 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v0.20.0 // indirect
Expand Down
72 changes: 0 additions & 72 deletions proto/ratelimit/v1/gov.proto

This file was deleted.

19 changes: 19 additions & 0 deletions proto/ratelimit/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,80 @@ option go_package = "github.com/Stride-Labs/ibc-rate-limiting/ratelimit/types";

// Query defines the gRPC querier service.
service Query {
// Queries all rate limits
rpc AllRateLimits(QueryAllRateLimitsRequest)
returns (QueryAllRateLimitsResponse) {
option (google.api.http).get =
"/Stride-Labs/ibc-rate-limiting/ratelimit/ratelimits";
}

// Queries a specific rate limit by channel ID and denom
// Ex:
// - /ratelimit/{channel_id}/by_denom?denom={denom}
rpc RateLimit(QueryRateLimitRequest) returns (QueryRateLimitResponse) {
option (google.api.http).get = "/Stride-Labs/ibc-rate-limiting/ratelimit/"
"ratelimit/{channel_id}/by_denom";
}

// Queries all the rate limits for a given chain
rpc RateLimitsByChainId(QueryRateLimitsByChainIdRequest)
returns (QueryRateLimitsByChainIdResponse) {
option (google.api.http).get =
"/Stride-Labs/ibc-rate-limiting/ratelimit/ratelimits/{chain_id}";
}

// Queries all the rate limits for a given channel ID
rpc RateLimitsByChannelId(QueryRateLimitsByChannelIdRequest)
returns (QueryRateLimitsByChannelIdResponse) {
option (google.api.http).get =
"/Stride-Labs/ibc-rate-limiting/ratelimit/ratelimits/{channel_id}";
}

// Queries all blacklisted denoms
rpc AllBlacklistedDenoms(QueryAllBlacklistedDenomsRequest)
returns (QueryAllBlacklistedDenomsResponse) {
option (google.api.http).get =
"/Stride-Labs/ibc-rate-limiting/ratelimit/blacklisted_denoms";
}

// Queries all whitelisted address pairs
rpc AllWhitelistedAddresses(QueryAllWhitelistedAddressesRequest)
returns (QueryAllWhitelistedAddressesResponse) {
option (google.api.http).get =
"/Stride-Labs/ibc-rate-limiting/ratelimit/whitelisted_addresses";
}
}

// Queries all rate limits
message QueryAllRateLimitsRequest {}
message QueryAllRateLimitsResponse {
repeated RateLimit rate_limits = 1 [ (gogoproto.nullable) = false ];
}

// Queries a specific rate limit by channel ID and denom
message QueryRateLimitRequest {
string denom = 1;
string channel_id = 2;
}
message QueryRateLimitResponse { RateLimit rate_limit = 1; }

// Queries all the rate limits for a given chain
message QueryRateLimitsByChainIdRequest { string chain_id = 1; }
message QueryRateLimitsByChainIdResponse {
repeated RateLimit rate_limits = 1 [ (gogoproto.nullable) = false ];
}

// Queries all the rate limits for a given channel ID
message QueryRateLimitsByChannelIdRequest { string channel_id = 1; }
message QueryRateLimitsByChannelIdResponse {
repeated RateLimit rate_limits = 1 [ (gogoproto.nullable) = false ];
}

// Queries all blacklisted denoms
message QueryAllBlacklistedDenomsRequest {}
message QueryAllBlacklistedDenomsResponse { repeated string denoms = 1; }

// Queries all whitelisted address pairs
message QueryAllWhitelistedAddressesRequest {}
message QueryAllWhitelistedAddressesResponse {
repeated WhitelistedAddressPair address_pairs = 1
Expand Down
23 changes: 23 additions & 0 deletions proto/ratelimit/v1/ratelimit.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,74 @@ import "google/protobuf/timestamp.proto";

option go_package = "github.com/Stride-Labs/ibc-rate-limiting/ratelimit/types";

// PacketDirection defines whether the transfer packet is being sent from
// this chain or is being received on this chain
enum PacketDirection {
option (gogoproto.goproto_enum_prefix) = false;

PACKET_SEND = 0;
PACKET_RECV = 1;
}

// Path holds the denom and channelID that define the rate limited route
message Path {
string denom = 1;
string channel_id = 2;
}

// Quota defines the rate limit thresholds for transfer packets
message Quota {
// MaxPercentSend defines the threshold for outflows
// The threshold is defined as a percentage (e.g. 10 indicates 10%)
string max_percent_send = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// MaxPercentSend defines the threshold for inflows
// The threshold is defined as a percentage (e.g. 10 indicates 10%)
string max_percent_recv = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// DurationHours specifies the number of hours before the rate limit
// is reset (e.g. 24 indicates that the rate limit is reset each day)
uint64 duration_hours = 3;
}

message Flow {
// Inflow defines the total amount of inbound transfers for the given
// rate limit in the current window
string inflow = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// Outflow defines the total amount of outbound transfers for the given
// rate limit in the current window
string outflow = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// ChannelValue stores the total supply of the denom at the start of
// the rate limit. This is used as the denominator when checking
// the rate limit threshold
// The ChannelValue is fixed for the duration of the rate limit window
string channel_value = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}

// RateLimit stores all the context about a given rate limit, including
// the relevant denom and channel, rate limit thresholds, and current
// progress towards the limits
message RateLimit {
Path path = 1;
Quota quota = 2;
Flow flow = 3;
}

// WhitelistedAddressPair represents a sender-receiver combo that is
// not subject to rate limit restrictions
message WhitelistedAddressPair {
string sender = 1;
string receiver = 2;
Expand Down
111 changes: 111 additions & 0 deletions proto/ratelimit/v1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
syntax = "proto3";
package ratelimit.v1;

import "gogoproto/gogo.proto";
import "amino/amino.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/msg/v1/msg.proto";

option go_package = "github.com/Stride-Labs/ibc-rate-limiting/ratelimit/types";

// Msg service for rate limit txs
service Msg {
// Gov tx to add a new rate limit
rpc AddRateLimit(MsgAddRateLimit) returns (MsgAddRateLimitResponse);
// Gov tx to update an existing rate limit
rpc UpdateRateLimit(MsgUpdateRateLimit) returns (MsgUpdateRateLimitResponse);
// Gov tx to remove a rate limit
rpc RemoveRateLimit(MsgRemoveRateLimit) returns (MsgRemoveRateLimitResponse);
// Gov tx to reset the flow on a rate limit
rpc ResetRateLimit(MsgResetRateLimit) returns (MsgResetRateLimitResponse);
}

// Gov tx to add a new rate limit
message MsgAddRateLimit {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "ratelimit/MsgAddRateLimit";

// Authority defines the x/gov module account
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
// Denom for the rate limit, as it appears on the rate limited chain
// When rate limiting a non-native token, this will be an ibc denom
string denom = 2;
// ChannelId for the rate limit, on the side of the rate limited chain
string channel_id = 3;
// MaxPercentSend defines the threshold for outflows
// The threshold is defined as a percentage (e.g. 10 indicates 10%)
string max_percent_send = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// MaxPercentSend defines the threshold for inflows
// The threshold is defined as a percentage (e.g. 10 indicates 10%)
string max_percent_recv = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// DurationHours specifies the number of hours before the rate limit
// is reset (e.g. 24 indicates that the rate limit is reset each day)
uint64 duration_hours = 6;
}
message MsgAddRateLimitResponse {}

// Gov tx to update an existing rate limit
message MsgUpdateRateLimit {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "ratelimit/MsgUpdateRateLimit";

// Authority defines the x/gov module account
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
// Denom for the rate limit, as it appears on the rate limited chain
// When rate limiting a non-native token, this will be an ibc denom
string denom = 2;
// ChannelId for the rate limit, on the side of the rate limited chain
string channel_id = 3;
// MaxPercentSend defines the threshold for outflows
// The threshold is defined as a percentage (e.g. 10 indicates 10%)
string max_percent_send = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// MaxPercentSend defines the threshold for inflows
// The threshold is defined as a percentage (e.g. 10 indicates 10%)
string max_percent_recv = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// DurationHours specifies the number of hours before the rate limit
// is reset (e.g. 24 indicates that the rate limit is reset each day)
uint64 duration_hours = 6;
}
message MsgUpdateRateLimitResponse {}

// Gov tx to remove a rate limit
message MsgRemoveRateLimit {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "ratelimit/MsgRemoveRateLimit";

// Authority defines the x/gov module account
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
// Denom for the rate limit, as it appears on the rate limited chain
// When rate limiting a non-native token, this will be an ibc denom
string denom = 2;
// ChannelId for the rate limit, on the side of the rate limited chain
string channel_id = 3;
}
message MsgRemoveRateLimitResponse {}

// Gov tx to reset the flow on a rate limit
message MsgResetRateLimit {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "ratelimit/MsgResetRateLimit";

// Authority defines the x/gov module account
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
// Denom for the rate limit, as it appears on the rate limited chain
// When rate limiting a non-native token, this will be an ibc denom
string denom = 2;
// ChannelId for the rate limit, on the side of the rate limited chain
string channel_id = 3;
}
message MsgResetRateLimitResponse {}
Loading

0 comments on commit 29a35e9

Please sign in to comment.