-
Notifications
You must be signed in to change notification settings - Fork 609
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 #2339
IBC Rate Limiting #2339
Changes from 58 commits
0ed673a
e61ab68
187b49c
d53529e
b6947a0
38cfe4d
773ea2b
7c23a31
2c7dd18
a4b8dc2
cd950ce
8069131
bef2500
ef44407
2b2ba93
19d9c94
574b109
c423f12
2791d6a
d45a830
64a5ef0
875214b
23ad652
c1d52d9
3cbcafe
6d79e71
225dfcf
863abef
76c0678
c52c96e
de5e919
5aa644e
8309b95
6432034
9ffdc37
80b8008
de08caf
bebec8b
2d1cacb
0fd7e64
2733060
d040f84
ef47f16
fb072ed
010628c
c604c0d
b9ffbab
1ec6b8e
73607f7
241aa9e
66a55b0
73535d4
8f8b7d2
e007ca6
b16fa70
c171bb8
8ca29e7
66c3346
3a37701
8c97907
6a331dd
5ef145e
0a2656c
2fd6e04
49ad2cd
7105550
17c05af
a6cf294
4855c0f
3d8aa96
318cf57
15cbcec
3357e94
9f605fc
70a11b4
2daf2ba
be0fa76
04a2a7a
26fc15b
2723f07
a9dd5bf
94f079b
a7e7d75
8917e77
61bc4fe
67b1477
11c5765
1f237e8
d9dd5b3
bf41b6f
8b6390b
1faa8c5
a8a9b88
12accb3
aee867f
2758919
f726d2c
506453a
2fa15b8
4b66483
8128b0c
73acb2f
5b66bdc
2e4a6ab
4af7fe9
48b19cb
0dd7fc9
6180eb8
82c83b1
92b4bb3
d4ace7b
746daa9
fe97ee8
c6758f1
e1d52f4
7434a44
727fef2
7859a55
628db47
9facb27
042f3f4
c37a968
e5d72d6
d658fdd
c2a72ad
0b738c9
71d8aca
8135a90
2151825
a800e9b
ae15972
f8b972a
e15c77c
63b23f0
7aa90e3
fcec5b9
7acacb3
4268c79
80617e8
0529667
294e19a
6c49460
3028b38
f332e23
5bdccfc
b9408e6
6916ffa
216bcee
f1cdb16
314455e
0aed029
54056fa
cd74eaa
a69b58f
e8e9012
381e5e2
fa8cafe
cc91a76
bbcc8af
d4e10bd
45ca648
c425518
fde1440
79843a1
fd54ed3
298636d
5561530
6e47abc
deaacfd
c676404
7544235
98b720d
a7f5bc4
89cf19f
10424b4
4b23e98
443fff3
76c9cc9
d46b51c
af4d9a7
2751bee
b682542
fa12ff0
25a7767
219118c
803d26e
f474ee4
a3f82e9
ddfcac0
3018357
42b354d
3350c57
a183a0e
2825e21
ca5fecf
20b40de
3f98ebe
463f1cc
eb6471b
f2ba12f
4b68e46
1506c3f
33ad060
30fb80b
acf1f50
4541b87
f9ee22d
d9df73c
e681a7d
9e14d15
11a4957
4fc7abb
d2daad6
24a3e2e
2095003
65f0485
9240011
0ca235b
71d60b8
69b4954
21e7f51
a78c757
93413be
0b45d11
1739f0c
a5bb034
82fd8ec
c4ad0bb
f2561e2
1b92379
547b38b
79c7224
130d902
29f61fd
7b79685
08a1cd8
27ee3ee
8c36532
d125dbd
cc42cab
41b3cae
0ad0a90
7b50cb4
01f6faa
40f8cc6
e7798a1
8b27f9d
92de82c
4af597a
3c4123e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ import ( | |
"github.com/cosmos/cosmos-sdk/x/upgrade" | ||
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
ibcratelimit "github.com/osmosis-labs/osmosis/v10/x/ibc-rate-limit" | ||
ibcratelimittypes "github.com/osmosis-labs/osmosis/v10/x/ibc-rate-limit/types" | ||
|
||
icahost "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host" | ||
icahostkeeper "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/keeper" | ||
|
@@ -111,9 +113,11 @@ type AppKeepers struct { | |
GovKeeper *govkeeper.Keeper | ||
WasmKeeper *wasm.Keeper | ||
TokenFactoryKeeper *tokenfactorykeeper.Keeper | ||
|
||
// IBC modules | ||
// transfer module | ||
TransferModule transfer.AppModule | ||
TransferModule transfer.AppModule | ||
RateLimitingICS4Wrapper *ibcratelimit.ICS4Middleware | ||
|
||
// keys to access the substores | ||
keys map[string]*sdk.KVStoreKey | ||
|
@@ -195,12 +199,25 @@ func (appKeepers *AppKeepers) InitNormalKeepers( | |
appKeepers.ScopedIBCKeeper, | ||
) | ||
|
||
// ChannelKeeper wrapper for rate limiting SendPacket(). The wasmKeeper needs to be added after it's created | ||
rateLimitingParams := appKeepers.GetSubspace(ibcratelimittypes.ModuleName) | ||
rateLimitingParams = rateLimitingParams.WithKeyTable(ibcratelimittypes.ParamKeyTable()) | ||
rateLimitingICS4Wrapper := ibcratelimit.NewICS4Middleware( | ||
appKeepers.IBCKeeper.ChannelKeeper, | ||
appKeepers.AccountKeeper, | ||
nil, | ||
appKeepers.BankKeeper, | ||
nil, | ||
rateLimitingParams, | ||
) | ||
appKeepers.RateLimitingICS4Wrapper = &rateLimitingICS4Wrapper | ||
|
||
// Create Transfer Keepers | ||
transferKeeper := ibctransferkeeper.NewKeeper( | ||
appCodec, | ||
appKeepers.keys[ibctransfertypes.StoreKey], | ||
appKeepers.GetSubspace(ibctransfertypes.ModuleName), | ||
appKeepers.IBCKeeper.ChannelKeeper, | ||
appKeepers.RateLimitingICS4Wrapper, // The ICS4Wrapper is replaced by the rateLimitingICS4Wrapper instead of the channel | ||
appKeepers.IBCKeeper.ChannelKeeper, | ||
&appKeepers.IBCKeeper.PortKeeper, | ||
appKeepers.AccountKeeper, | ||
|
@@ -211,6 +228,9 @@ func (appKeepers *AppKeepers) InitNormalKeepers( | |
appKeepers.TransferModule = transfer.NewAppModule(*appKeepers.TransferKeeper) | ||
transferIBCModule := transfer.NewIBCModule(*appKeepers.TransferKeeper) | ||
|
||
// RateLimiting IBC Middleware | ||
rateLimitingTransferMiddleware := ibcratelimit.NewIBCModule(transferIBCModule, appKeepers.RateLimitingICS4Wrapper) | ||
|
||
icaHostKeeper := icahostkeeper.NewKeeper( | ||
appCodec, appKeepers.keys[icahosttypes.StoreKey], | ||
appKeepers.GetSubspace(icahosttypes.SubModuleName), | ||
|
@@ -226,7 +246,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers( | |
// Create static IBC router, add transfer route, then set and seal it | ||
ibcRouter := porttypes.NewRouter() | ||
ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule). | ||
AddRoute(ibctransfertypes.ModuleName, transferIBCModule) | ||
AddRoute(ibctransfertypes.ModuleName, &rateLimitingTransferMiddleware) | ||
// Note: the sealing is done after creating wasmd and wiring that up | ||
|
||
// create evidence keeper with router | ||
|
@@ -283,6 +303,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers( | |
appKeepers.DistrKeeper, | ||
appKeepers.TxFeesKeeper, | ||
) | ||
appKeepers.RateLimitingICS4Wrapper.LockupKeeper = appKeepers.LockupKeeper | ||
|
||
appKeepers.SuperfluidKeeper = superfluidkeeper.NewKeeper( | ||
appCodec, appKeepers.keys[superfluidtypes.StoreKey], appKeepers.GetSubspace(superfluidtypes.ModuleName), | ||
|
@@ -347,6 +368,8 @@ func (appKeepers *AppKeepers) InitNormalKeepers( | |
wasmOpts..., | ||
) | ||
appKeepers.WasmKeeper = &wasmKeeper | ||
// Update the ICS4Wrapper with the right WasmKeeper | ||
appKeepers.RateLimitingICS4Wrapper.WasmKeeper = appKeepers.WasmKeeper | ||
|
||
// wire up x/wasm to IBC | ||
ibcRouter.AddRoute(wasm.ModuleName, wasm.NewIBCHandler(appKeepers.WasmKeeper, appKeepers.IBCKeeper.ChannelKeeper)) | ||
|
@@ -439,6 +462,7 @@ func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legac | |
paramsKeeper.Subspace(gammtypes.ModuleName) | ||
paramsKeeper.Subspace(wasm.ModuleName) | ||
paramsKeeper.Subspace(tokenfactorytypes.ModuleName) | ||
paramsKeeper.Subspace(ibcratelimittypes.ModuleName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also add initializing params to the upgrade handler(creating an issue for this also works for me so that we make sure we come back to this) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added an issue for this: #2869 |
||
|
||
return paramsKeeper | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
syntax = "proto3"; | ||
package osmosis.ibcratelimit.v1beta1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
|
||
option go_package = "github.com/osmosis-labs/osmosis/v10/x/ibc-rate-limit/types"; | ||
|
||
// Params defines the parameters for the ibc-rate-limiting module. | ||
message Params { | ||
string contract_address = 1 | ||
[ (gogoproto.moretags) = "yaml:\"contract_address\"" ]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,32 @@ func (s *IntegrationTestSuite) TestIBCTokenTransfer() { | |
chainB.SendIBC(chainA, chainA.NodeConfigs[0].PublicAddress, initialization.StakeToken) | ||
} | ||
|
||
func (s *IntegrationTestSuite) TestRateLimitingTestsSetupCorrectly() { | ||
// Checking the rate limiting tests are setup correctly | ||
//f1, err := ioutil.ReadFile("../../x/ibc-rate-limit/testdata/rate-limiter.wasm") | ||
//s.NoError(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest trying Without it, the test does not fail and continues. It seems that there might be a path/permission issue at this step with:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, sorry! that test was just me experimenting with making sure the file we're using for e2e tests (the one copied to the docket containers) is the same as the one in the integration tests. The path should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. Moved these tests to the integration tests (since they don't depend on the e2e containerization). I also want to add a test to check the rust code compiles to the wasm file we're using for testing, but I'm not sure if the go tests is the right place to do this. Seems like something that should be its own task in the workflow (especially if more contracts are going to start being part of the source) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome! I think a separate task in the workflow makes sense |
||
//f2, err := ioutil.ReadFile("./scripts/rate-limiter.wasm") | ||
//s.NoError(err) | ||
//s.Require().True(bytes.Equal(f1, f2)) | ||
} | ||
|
||
func (s *IntegrationTestSuite) TestIBCTokenTransferRateLimiting() { | ||
// TODO: Add E2E tests for this | ||
if s.skipIBC { | ||
s.T().Skip("Skipping IBC tests") | ||
} | ||
chainA := s.configurer.GetChainConfig(0) | ||
chainB := s.configurer.GetChainConfig(1) | ||
|
||
//node, err := chainA.GetDefaultNode() | ||
//s.NoError(err) | ||
// This doesn't work. Why? | ||
//node.StoreWasmCode("rate_limiter.wasm", initialization.ValidatorWalletName) | ||
|
||
chainA.SendIBC(chainB, chainB.NodeConfigs[0].PublicAddress, initialization.OsmoToken) | ||
|
||
} | ||
|
||
func (s *IntegrationTestSuite) TestSuperfluidVoting() { | ||
if s.skipUpgrade { | ||
// TODO: https://github.com/osmosis-labs/osmosis/issues/1843 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
debug/ | ||
target/ | ||
|
||
# Generated by rust-optimizer | ||
artifacts/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb | ||
|
||
|
||
# Ignores local beaker state | ||
**/state.local.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
name = "ibc-rate-limit" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[workspace] | ||
|
||
members = [ | ||
'contracts/*', | ||
] | ||
|
||
[profile.release] | ||
codegen-units = 1 | ||
debug = false | ||
debug-assertions = false | ||
incremental = false | ||
lto = true | ||
opt-level = 3 | ||
overflow-checks = true | ||
panic = 'abort' | ||
rpath = false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[alias] | ||
wasm = "build --release --target wasm32-unknown-unknown" | ||
unit-test = "test --lib" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Build results | ||
/target | ||
|
||
# Cargo+Git helper file (https://github.com/rust-lang/cargo/blob/0.44.1/src/cargo/sources/git/utils.rs#L320-L327) | ||
.cargo-ok | ||
|
||
# Text file backups | ||
**/*.rs.bk | ||
|
||
# macOS | ||
.DS_Store | ||
|
||
# IDEs | ||
*.iml | ||
.idea |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
[package] | ||
name = "rate-limiter" | ||
version = "0.1.0" | ||
authors = ["Nicolas Lara <[email protected]>"] | ||
edition = "2018" | ||
|
||
exclude = [ | ||
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. | ||
"contract.wasm", | ||
"hash.txt", | ||
] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[profile.release] | ||
opt-level = 3 | ||
debug = false | ||
rpath = false | ||
lto = true | ||
debug-assertions = false | ||
codegen-units = 1 | ||
panic = 'abort' | ||
incremental = false | ||
overflow-checks = true | ||
|
||
[features] | ||
# for more explicit tests, cargo test --features=backtraces | ||
backtraces = ["cosmwasm-std/backtraces"] | ||
# use library feature to disable all instantiate/execute/query exports | ||
library = [] | ||
|
||
[package.metadata.scripts] | ||
optimize = """docker run --rm -v "$(pwd)":/code \ | ||
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ | ||
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ | ||
cosmwasm/rust-optimizer:0.12.6 | ||
""" | ||
|
||
[dependencies] | ||
cosmwasm-std = "1.0.0" | ||
cosmwasm-storage = "1.0.0" | ||
cw-storage-plus = "0.13.2" | ||
cw2 = "0.13.2" | ||
schemars = "0.8.8" | ||
serde = { version = "1.0.137", default-features = false, features = ["derive"] } | ||
thiserror = { version = "1.0.31" } | ||
|
||
[dev-dependencies] | ||
cosmwasm-schema = "1.0.0" | ||
cw-multi-test = "0.13.2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:O nice