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

IBC Rate Limiting #556

Merged
merged 80 commits into from
Feb 18, 2023
Merged
Show file tree
Hide file tree
Changes from 73 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
950a274
scaffold ibc rate limit module (#473)
antstalepresh Dec 7, 2022
21089a8
stride v3 -> v4 in rate limit module
sampocs Dec 7, 2022
f991e57
v3 -> v4 for rate limit protos
sampocs Dec 7, 2022
6e2a037
formatted and regenerated protos
sampocs Dec 7, 2022
32c67d5
removed stale ignite comments
sampocs Dec 7, 2022
8a608c5
changed store key since module name was changed
sampocs Dec 7, 2022
d5e4098
added remove quota proto types
sampocs Dec 7, 2022
573b0e8
added remove quota message to msg_server
sampocs Dec 7, 2022
43b8bca
added quota query types
sampocs Dec 7, 2022
3e7b583
added quota queries to grpc query
sampocs Dec 7, 2022
acc565c
Added Unit Test Framework to ratelimit module (#480)
sampocs Dec 8, 2022
bff325c
add msg types and routes, add creator field to tx msgs
antstalepresh Dec 8, 2022
fab8893
some minor fixes
antstalepresh Dec 8, 2022
1e35a51
minor fixes
antstalepresh Dec 8, 2022
6b2cb18
add newflow function
antstalepresh Dec 8, 2022
8adfb9f
[RATE-LIMIT] Path helper functions (#479)
sampocs Dec 9, 2022
ebcae0b
[RATE-LIMIT]: RateLimit Helper Functions and Queries (#490)
sampocs Dec 9, 2022
8b5a0b9
implement quota functions
antstalepresh Dec 8, 2022
2937b8d
change addquota to setquota, add unit tests for quota msgs
antstalepresh Dec 9, 2022
d3a4369
convert CheckExceedsQuota function to member function of quota object
antstalepresh Dec 9, 2022
c2e26da
adjustments for GetQuota function
antstalepresh Dec 9, 2022
d3612ad
add unit tests for quota keeper functions
antstalepresh Dec 9, 2022
2b25f18
minor adjustments
antstalepresh Dec 9, 2022
10ee62a
implement cli & tests
antstalepresh Dec 11, 2022
f45ad70
fix feedbacks
antstalepresh Dec 12, 2022
12a0dfe
Move Quota Attributes to RateLimit object (#502)
sampocs Dec 13, 2022
0200f69
address pr comments
antstalepresh Dec 13, 2022
c83d069
minor fix
antstalepresh Dec 13, 2022
275cbdb
adjust quota_test
antstalepresh Dec 13, 2022
334de7f
minor adjustments
antstalepresh Dec 13, 2022
bbf7ec1
[RATE-LIMIT] Implemented AddInflow, AddOutflow, GetChannelValue (#506)
sampocs Dec 14, 2022
1397864
[RATE-LIMIT] Added Epochs to ratelimit module (#507)
sampocs Dec 14, 2022
9df5cbf
minor comment issues
antstalepresh Dec 14, 2022
a2ef933
implementing ratelimit msgserver & tests (#511)
antstalepresh Dec 14, 2022
0d3b8c5
check if channel value is zero
antstalepresh Dec 15, 2022
a2efe4e
[RATE-LIMIT] Implement CheckRateLimit, SendPacket, OnRecvPacket (#515)
sampocs Dec 19, 2022
e176282
add genesis handler and tests, update some keeper tests
antstalepresh Dec 19, 2022
e7abc29
added genesis test helper function (#528)
sampocs Dec 19, 2022
67da44b
add error catches for mint functions
antstalepresh Dec 19, 2022
352601f
fix some cli config issues, add tests for clis
antstalepresh Dec 15, 2022
65200dc
adjust removeratelimit test
antstalepresh Dec 19, 2022
59cdbba
removed array from cli tests
sampocs Dec 20, 2022
ec41e24
fix a comment issue, clean some codebase (#532)
antstalepresh Dec 20, 2022
15364df
[RATE-LIMIT] Unit Tests for Packet Callback Functions (#534)
sampocs Dec 21, 2022
ad01251
[RATE-LIMIT] Query Rate Limits by ChainID (#535)
sampocs Dec 22, 2022
6be7aed
[RATE-LIMIT] Bash Integration Tests (#541)
sampocs Dec 30, 2022
d02ce19
[RATE-LIMIT] Expose Transactions to Governance (#549)
sampocs Jan 4, 2023
9bb5ef1
[RATE-LIMIT] Docs (#553)
sampocs Jan 4, 2023
510d29d
added TODO to add hour epoch
sampocs Jan 4, 2023
e00d9ce
Merge branch 'main' into rate-limiter
asalzmann Jan 5, 2023
4213325
update ratelimit query, add ratelimits-by-channel query
antstalepresh Jan 5, 2023
6ae4dd8
address pr comments
antstalepresh Jan 5, 2023
30e6e73
update ratelimit query, add ratelimits-by-channel query (#557)
antstalepresh Jan 6, 2023
79a1930
Merge branch 'rate-limiter' of github.com:Stride-Labs/stride into rat…
sampocs Jan 17, 2023
02cfd23
addressed pr comments
sampocs Jan 18, 2023
93bd465
Merge branch 'main' into rate-limiter
sampocs Jan 23, 2023
7d60f82
ibc go v3 -> v5
sampocs Jan 23, 2023
79d653e
stride v4 -> v5 in rate limit go files
sampocs Jan 23, 2023
c4f2618
stride v4 -> v5 in rate limit protos
sampocs Jan 23, 2023
3a69e45
removed rest client
sampocs Jan 23, 2023
560f7e2
45 -> 46: sdk.Int to sdkmath.Int, gov types v1beta1, OnChanOpenInit
sampocs Jan 23, 2023
1f3d75f
added boilerplate for get app version
sampocs Jan 23, 2023
eb795bd
fixed bug in denom flag
sampocs Jan 24, 2023
5409792
fixed integration tests
sampocs Jan 24, 2023
0d1c62e
renamed ibc_module to ibc_middleware
sampocs Jan 25, 2023
4f46c2e
refactored rate limit middleware wiring
sampocs Jan 25, 2023
e4c1e9c
finished middleware refactor
sampocs Jan 31, 2023
703d432
removed question from comments
sampocs Feb 1, 2023
1a1bd4e
added events when rate limit was exceeded
sampocs Feb 14, 2023
d3064f6
revert config.sh
sampocs Feb 14, 2023
aa0af49
added denom blacklist
sampocs Feb 16, 2023
4fa3ad7
Merge branch 'main' into rate-limiter
sampocs Feb 16, 2023
72b07ce
fixed lint errors
sampocs Feb 16, 2023
62d5857
Update x/ratelimit/README.md
sampocs Feb 17, 2023
fa505fc
refactored event to have differentiated attributes
sampocs Feb 18, 2023
8b5b394
Merge branch 'rate-limiter' of github.com:Stride-Labs/stride into rat…
sampocs Feb 18, 2023
e866d8e
Merge branch 'main' into rate-limiter
sampocs Feb 18, 2023
dad4ec9
added error logs
sampocs Feb 18, 2023
7bee669
fixed lint errors
sampocs Feb 18, 2023
90349c3
created lighterweight suiteless test helper
sampocs Feb 18, 2023
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ We use the following modules from [Osmosis](https://github.com/osmosis-labs/osmo
```
x/epochs
x/mint
x/ratelimit
asalzmann marked this conversation as resolved.
Show resolved Hide resolved
```
We use the following module (marketed as public infra) from [Quicksilver](https://github.com/ingenuity-build/quicksilver) provided under [this License](https://github.com/ingenuity-build/quicksilver/blob/main/LICENSE):
```
Expand Down
56 changes: 48 additions & 8 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ import (
ibcclient "github.com/cosmos/ibc-go/v5/modules/core/02-client"
ibcclientclient "github.com/cosmos/ibc-go/v5/modules/core/02-client/client"
ibcclienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types"
ibcporttypes "github.com/cosmos/ibc-go/v5/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v5/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper"
ibctesting "github.com/cosmos/ibc-go/v5/testing"
Expand Down Expand Up @@ -120,6 +119,10 @@ import (
icacallbacksmodule "github.com/Stride-Labs/stride/v5/x/icacallbacks"
icacallbacksmodulekeeper "github.com/Stride-Labs/stride/v5/x/icacallbacks/keeper"
icacallbacksmoduletypes "github.com/Stride-Labs/stride/v5/x/icacallbacks/types"
ratelimitmodule "github.com/Stride-Labs/stride/v5/x/ratelimit"
ratelimitclient "github.com/Stride-Labs/stride/v5/x/ratelimit/client"
ratelimitmodulekeeper "github.com/Stride-Labs/stride/v5/x/ratelimit/keeper"
ratelimitmoduletypes "github.com/Stride-Labs/stride/v5/x/ratelimit/types"
recordsmodule "github.com/Stride-Labs/stride/v5/x/records"
recordsmodulekeeper "github.com/Stride-Labs/stride/v5/x/records/keeper"
recordsmoduletypes "github.com/Stride-Labs/stride/v5/x/records/types"
Expand Down Expand Up @@ -155,6 +158,10 @@ func getGovProposalHandlers() []govclient.ProposalHandler {
ibcclientclient.UpdateClientProposalHandler,
ibcclientclient.UpgradeProposalHandler,
stakeibcclient.AddValidatorProposalHandler,
ratelimitclient.AddRateLimitProposalHandler,
ratelimitclient.UpdateRateLimitProposalHandler,
ratelimitclient.RemoveRateLimitProposalHandler,
ratelimitclient.ResetRateLimitProposalHandler,
// this line is used by starport scaffolding # stargate/app/govProposalHandler
)

Expand Down Expand Up @@ -193,6 +200,7 @@ var (
interchainquery.AppModuleBasic{},
ica.AppModuleBasic{},
recordsmodule.AppModuleBasic{},
ratelimitmodule.AppModuleBasic{},
icacallbacksmodule.AppModuleBasic{},
claim.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
Expand Down Expand Up @@ -283,6 +291,8 @@ type StrideApp struct {
RecordsKeeper recordsmodulekeeper.Keeper
ScopedIcacallbacksKeeper capabilitykeeper.ScopedKeeper
IcacallbacksKeeper icacallbacksmodulekeeper.Keeper
ScopedratelimitKeeper capabilitykeeper.ScopedKeeper
RatelimitKeeper ratelimitmodulekeeper.Keeper
ClaimKeeper claimkeeper.Keeper
// this line is used by starport scaffolding # stargate/app/keeperDeclaration

Expand Down Expand Up @@ -324,6 +334,7 @@ func NewStrideApp(
interchainquerytypes.StoreKey,
icacontrollertypes.StoreKey, icahosttypes.StoreKey,
recordsmoduletypes.StoreKey,
ratelimitmoduletypes.StoreKey,
icacallbacksmoduletypes.StoreKey,
claimtypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
Expand Down Expand Up @@ -405,11 +416,30 @@ func NewStrideApp(
appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper,
)

// Create Ratelimit Keeper
scopedratelimitKeeper := app.CapabilityKeeper.ScopeToModule(ratelimitmoduletypes.ModuleName)
app.ScopedratelimitKeeper = scopedratelimitKeeper
app.RatelimitKeeper = *ratelimitmodulekeeper.NewKeeper(
appCodec,
keys[ratelimitmoduletypes.StoreKey],
app.GetSubspace(ratelimitmoduletypes.ModuleName),
app.BankKeeper,
app.IBCKeeper.ChannelKeeper,
// TODO: Implement ICS4Wrapper in Records and pass records keeper here
app.IBCKeeper.ChannelKeeper, // ICS4Wrapper
)
ratelimitModule := ratelimitmodule.NewAppModule(appCodec, app.RatelimitKeeper)

// Create Transfer Keepers
app.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName),
app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.AccountKeeper, app.BankKeeper, scopedTransferKeeper,
appCodec, keys[ibctransfertypes.StoreKey],
app.GetSubspace(ibctransfertypes.ModuleName),
app.RatelimitKeeper, // ICS4Wrapper
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.AccountKeeper,
app.BankKeeper,
scopedTransferKeeper,
)
transferModule := transfer.NewAppModule(app.TransferKeeper)
transferIBCModule := transfer.NewIBCModule(app.TransferKeeper)
Expand Down Expand Up @@ -509,7 +539,8 @@ func NewStrideApp(
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)).
AddRoute(stakeibcmoduletypes.RouterKey, stakeibcmodule.NewStakeibcProposalHandler(app.StakeibcKeeper))
AddRoute(stakeibcmoduletypes.RouterKey, stakeibcmodule.NewStakeibcProposalHandler(app.StakeibcKeeper)).
AddRoute(ratelimitmoduletypes.RouterKey, ratelimitmodule.NewRateLimitProposalHandler(app.RatelimitKeeper, app.IBCKeeper.ChannelKeeper))

app.GovKeeper = govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
Expand All @@ -527,6 +558,7 @@ func NewStrideApp(
app.StakeibcKeeper.Hooks(),
app.MintKeeper.Hooks(),
app.ClaimKeeper.Hooks(),
app.RatelimitKeeper.Hooks(),
),
)
epochsModule := epochsmodule.NewAppModule(appCodec, app.EpochsKeeper)
Expand Down Expand Up @@ -576,14 +608,17 @@ func NewStrideApp(
// Stack two contains
// - IBC
// - records
// - ratelimit
// - transfer
// - base app
recordsStack := recordsmodule.NewIBCModule(app.RecordsKeeper, transferIBCModule)
var transferStack porttypes.IBCModule = transferIBCModule
transferStack = ratelimitmodule.NewIBCMiddleware(app.RatelimitKeeper, transferStack)
transferStack = recordsmodule.NewIBCModule(app.RecordsKeeper, transferStack)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := ibcporttypes.NewRouter()
ibcRouter := porttypes.NewRouter()
ibcRouter.
AddRoute(ibctransfertypes.ModuleName, recordsStack).
AddRoute(ibctransfertypes.ModuleName, transferStack).
AddRoute(icacontrollertypes.SubModuleName, icamiddlewareStack).
AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
// Note, authentication module packets are routed to the top level of the middleware stack
Expand Down Expand Up @@ -630,6 +665,7 @@ func NewStrideApp(
interchainQueryModule,
icaModule,
recordsModule,
ratelimitModule,
icacallbacksModule,
// this line is used by starport scaffolding # stargate/app/appModule
)
Expand Down Expand Up @@ -663,6 +699,7 @@ func NewStrideApp(
epochsmoduletypes.ModuleName,
interchainquerytypes.ModuleName,
recordsmoduletypes.ModuleName,
ratelimitmoduletypes.ModuleName,
icacallbacksmoduletypes.ModuleName,
claimtypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/beginBlockers
Expand Down Expand Up @@ -693,6 +730,7 @@ func NewStrideApp(
epochsmoduletypes.ModuleName,
interchainquerytypes.ModuleName,
recordsmoduletypes.ModuleName,
ratelimitmoduletypes.ModuleName,
icacallbacksmoduletypes.ModuleName,
claimtypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/endBlockers
Expand Down Expand Up @@ -728,6 +766,7 @@ func NewStrideApp(
epochsmoduletypes.ModuleName,
interchainquerytypes.ModuleName,
recordsmoduletypes.ModuleName,
ratelimitmoduletypes.ModuleName,
icacallbacksmoduletypes.ModuleName,
claimtypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
Expand Down Expand Up @@ -991,6 +1030,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(recordsmoduletypes.ModuleName)
paramsKeeper.Subspace(ratelimitmoduletypes.ModuleName)
paramsKeeper.Subspace(icacallbacksmoduletypes.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace

Expand Down
9 changes: 9 additions & 0 deletions app/apptesting/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ func (s *AppTestHelper) Setup() {
s.IcaAddresses = make(map[string]string)
}

// Instantiates an TestHelper without the test suite
// This is for testing scenarios where we simply need the setup function to run,
// and need access to the TestHelper attributes and keepers (e.g. genesis tests)
func SetupSuitelessTestHelper() AppTestHelper {
s := AppTestHelper{}
s.Setup()
return s
}

// Mints coins directly to a module account
func (s *AppTestHelper) FundModuleAccount(moduleName string, amount sdk.Coin) {
err := s.App.BankKeeper.MintCoins(s.Ctx, moduleName, sdk.NewCoins(amount))
Expand Down
8 changes: 8 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ func (app *StrideApp) setupUpgradeHandlers() {
Deleted: []string{authz.ModuleName},
}
}
// TODO: RATE LIMIT UPGRADE
// 1. Add ratelimit store key when module is added
// storeUpgrades = &storetypes.StoreUpgrades{
// Added: []string{ratelimittypes.StoreKey},
// }
//
// 2. Add hour epoch to store
// 3. Add rate limits for existing denoms
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we implement these here and just leave them commented out?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It'd require adding the whole upgrade handler, so I think I'd lean toward doing it in a separate PR. Wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, makes sense to put in a separate PR. We should just make sure that goes in the next upgrade.


if storeUpgrades != nil {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades))
Expand Down
1 change: 1 addition & 0 deletions dockernet/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ IBC_STARS_DENOM=$IBC_STARS_CHANNEL_3_DENOM

# CHAIN PARAMS
BLOCK_TIME='1s'
STRIDE_HOUR_EPOCH_DURATION="90s"
STRIDE_DAY_EPOCH_DURATION="100s"
STRIDE_EPOCH_EPOCH_DURATION="40s"
HOST_DAY_EPOCH_DURATION="60s"
Expand Down
45 changes: 45 additions & 0 deletions dockernet/config/relayer_config_juno_osmo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Sometimes it's beneficial to test a channel that is not connected with Stride
# For this case, we can use juno <> osmo
global:
api-listen-addr: :5183
timeout: 10s
memo: ""
light-cache-size: 20
chains:
juno:
type: cosmos
value:
key: juno-osmo-rly1
chain-id: JUNO
rpc-addr: http://juno1:26657
account-prefix: juno
keyring-backend: test
gas-adjustment: 1.2
gas-prices: 0.01ujuno
debug: false
timeout: 20s
output-format: json
sign-mode: direct
osmo:
type: cosmos
value:
key: juno-osmo-rly2
chain-id: OSMO
rpc-addr: http://osmo1:26657
account-prefix: osmo
keyring-backend: test
gas-adjustment: 1.2
gas-prices: 0.01uosmo
debug: false
timeout: 20s
output-format: json
sign-mode: direct
paths:
juno-osmo:
src:
chain-id: JUNO
dst:
chain-id: OSMO
src-channel-filter:
rule: ""
channel-list: []
7 changes: 7 additions & 0 deletions dockernet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,10 @@ services:
- ./state/relayer-host:/home/relayer/.relayer
restart: always
command: [ "bash", "start.sh", "stride-host" ]

relayer-juno-osmo:
image: stridezone:relayer
volumes:
- ./state/relayer-juno-osmo:/home/relayer/.relayer
restart: always
command: [ "bash", "start.sh", "juno-osmo" ]
13 changes: 13 additions & 0 deletions dockernet/scripts/ratelimit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Rate Limit Integration Tests
* **These tests are not intended to be run with normal CI, they were meant as a comprehensive sanity check before deploying the module and are redundant with the unit tests.**
* **WARNING**: `STRIDE_HOUR_EPOCH_DURATION` must be at least '90s' in `config.sh`
* `HOST_CHAINS` should be set to `(GAIA JUNO OSMO)` in `config.sh`
* Start dockernet
```
make start-docker
```
* Run the integration tests
```
bash dockernet/scripts/ratelimit/run_all_tests.sh
```
* Each test will print a checkmark or X depending on the status - if there are no X's, the tests passed.
Loading