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 #2339

Closed
wants to merge 251 commits into from
Closed
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
251 commits
Select commit Hold shift + click to select a range
0ed673a
added expiration
nicolaslara Aug 3, 2022
e61ab68
fixed integration test
nicolaslara Aug 3, 2022
187b49c
added initial middleware
nicolaslara Aug 4, 2022
d53529e
simple test to debug weirdness in ibctesting
nicolaslara Aug 4, 2022
b6947a0
using helpers
nicolaslara Aug 4, 2022
38cfe4d
Merge branch 'main' into ibc-rate-limit-weird-tests
nicolaslara Aug 4, 2022
773ea2b
testing with test changes from PR##2274
nicolaslara Aug 4, 2022
7c23a31
fixed tests and updated requirement to match cosmos-sdk fork branch w…
nicolaslara Aug 4, 2022
2c7dd18
updated to latest commit
nicolaslara Aug 4, 2022
a4b8dc2
using branch of the sdk fork that allows for ibc tests
nicolaslara Aug 4, 2022
cd950ce
Merge branch 'ibc-rate-limit-weird-tests' into ibc-rate-limit
nicolaslara Aug 4, 2022
8069131
Merge branch 'main' into supply-offset-changes-on-sdk-fork
nicolaslara Aug 5, 2022
bef2500
using the latest sdk fork changes with a new constructor
nicolaslara Aug 5, 2022
ef44407
Merge branch 'supply-offset-changes-on-sdk-fork' into ibc-rate-limit
nicolaslara Aug 5, 2022
2b2ba93
initial ibctest setup
nicolaslara Aug 5, 2022
19d9c94
propperly sending the package for testing
nicolaslara Aug 5, 2022
574b109
Initialize app before tests and add default genesis state
nicolaslara Aug 6, 2022
c423f12
initial middleware with working testing framework
nicolaslara Aug 6, 2022
2791d6a
improved testing framework
nicolaslara Aug 8, 2022
d45a830
can test both send and recv for success and failure
nicolaslara Aug 8, 2022
64a5ef0
cleanner testing framework
nicolaslara Aug 8, 2022
875214b
added contract instantiation
nicolaslara Aug 8, 2022
23ad652
working wasm integration
nicolaslara Aug 8, 2022
c1d52d9
added params for contract config
nicolaslara Aug 9, 2022
3cbcafe
extracted param registration
nicolaslara Aug 9, 2022
6d79e71
active rate limiting
nicolaslara Aug 9, 2022
225dfcf
calculating channel value
nicolaslara Aug 9, 2022
863abef
cleaner tests
nicolaslara Aug 9, 2022
76c0678
fix issue with epochs
nicolaslara Aug 9, 2022
c52c96e
fixed tests
nicolaslara Aug 9, 2022
de5e919
testing rate limit reset
nicolaslara Aug 10, 2022
5aa644e
linting
nicolaslara Aug 10, 2022
8309b95
added receive middleware
nicolaslara Aug 10, 2022
6432034
added test for non-configured channel
nicolaslara Aug 10, 2022
9ffdc37
make format
nicolaslara Aug 10, 2022
80b8008
Revert "make format"
nicolaslara Aug 10, 2022
de08caf
only applying format to ibc-rate-limit
nicolaslara Aug 10, 2022
bebec8b
applying fmt to app.go
nicolaslara Aug 10, 2022
2d1cacb
added gov_module and changed no-quota default to "allow all"
nicolaslara Aug 10, 2022
0fd7e64
added asymetric quotas
nicolaslara Aug 10, 2022
2733060
moved getters to modules.go
nicolaslara Aug 10, 2022
d040f84
Merge branch 'main' into ibc-rate-limit
nicolaslara Aug 10, 2022
ef47f16
initial work to support multiple quotas
nicolaslara Aug 11, 2022
fb072ed
added multiple quotas
nicolaslara Aug 11, 2022
010628c
small fixes
nicolaslara Aug 11, 2022
c604c0d
reordered imports
nicolaslara Aug 11, 2022
b9ffbab
added management messages
nicolaslara Aug 11, 2022
1ec6b8e
reorganized management messages and experimenting with e2e testing
nicolaslara Aug 12, 2022
73607f7
commenting out test configuration test for now
nicolaslara Aug 12, 2022
241aa9e
added query
nicolaslara Aug 12, 2022
66a55b0
added flow unit test
nicolaslara Aug 12, 2022
73535d4
cleanup
nicolaslara Aug 12, 2022
8f8b7d2
added AddChannel tests
nicolaslara Aug 12, 2022
e007ca6
format
nicolaslara Aug 12, 2022
b16fa70
test values are properly stored
nicolaslara Aug 12, 2022
c171bb8
testing remove channel
nicolaslara Aug 12, 2022
8ca29e7
some more rate limiting tests
nicolaslara Aug 12, 2022
66c3346
moved tests about test setup to the right place
nicolaslara Aug 15, 2022
3a37701
fixed params
nicolaslara Aug 15, 2022
8c97907
Merge branch 'main' into ibc-rate-limit
nicolaslara Aug 15, 2022
6a331dd
merged main
nicolaslara Aug 15, 2022
5ef145e
running gofumpt
nicolaslara Aug 15, 2022
0a2656c
added ibc-rate-limiting contract
nicolaslara Aug 15, 2022
2fd6e04
added ibc-rate-limit middleware
nicolaslara Aug 15, 2022
49ad2cd
Merge branch 'nicolas/ibc-rate-limit-middlware' into nicolas/ibc-rate…
nicolaslara Aug 15, 2022
7105550
added chain integration and tests
nicolaslara Aug 15, 2022
17c05af
reverted change to match merged branch in main (#2341 instead of #2274)
nicolaslara Aug 15, 2022
a6cf294
added cosmwasm workflow
nicolaslara Aug 15, 2022
4855c0f
Merge branch 'nicolas/ibc-rate-limit-contract' into nicolas/ibc-rate-…
nicolaslara Aug 15, 2022
3d8aa96
added a migrate message
nicolaslara Aug 16, 2022
318cf57
added some doc comments to the state
nicolaslara Aug 16, 2022
15cbcec
added doc comments
nicolaslara Aug 16, 2022
3357e94
fixed dependency after merging https://github.com/osmosis-labs/cosmos…
nicolaslara Aug 16, 2022
9f605fc
added migration msg
nicolaslara Aug 16, 2022
70a11b4
added workflow
nicolaslara Aug 17, 2022
2daf2ba
experimenting with better workflow
nicolaslara Aug 17, 2022
be0fa76
added missing $
nicolaslara Aug 17, 2022
04a2a7a
using env
nicolaslara Aug 17, 2022
26fc15b
Update x/ibc-rate-limit/contracts/rate-limiter/src/msg.rs
nicolaslara Aug 17, 2022
2723f07
using stable for clippy
nicolaslara Aug 17, 2022
a9dd5bf
removed gitkeep
nicolaslara Aug 17, 2022
94f079b
Merge branch 'nicolas/ibc-rate-limit-contract' into ibc-rate-limit
nicolaslara Aug 17, 2022
a7e7d75
using the minimal profile for clippy
nicolaslara Aug 17, 2022
8917e77
experimenting with cache
nicolaslara Aug 17, 2022
61bc4fe
removed target from lints
nicolaslara Aug 17, 2022
67b1477
cleaner matrix?
nicolaslara Aug 17, 2022
11c5765
COmments & questions
ValarDragon Aug 17, 2022
1f237e8
Merge branch 'nicolas/ibc-rate-limit-contract' of github.com:osmosis-…
ValarDragon Aug 17, 2022
d9dd5b3
debugging
nicolaslara Aug 17, 2022
bf41b6f
more debugging
nicolaslara Aug 17, 2022
8b6390b
debug faster
nicolaslara Aug 17, 2022
1faa8c5
quick cache debug
nicolaslara Aug 17, 2022
a8a9b88
typo
nicolaslara Aug 17, 2022
12accb3
quick workflow check
nicolaslara Aug 17, 2022
aee867f
working tests with optimization
nicolaslara Aug 17, 2022
2758919
testing artifacts
nicolaslara Aug 17, 2022
f726d2c
split the wasm target into its own step
nicolaslara Aug 17, 2022
506453a
artifacts without slash
nicolaslara Aug 17, 2022
2fa15b8
full working tests
nicolaslara Aug 17, 2022
4b66483
clippy fixes
nicolaslara Aug 17, 2022
8128b0c
Merge branch 'nicolas/ibc-rate-limit-contract' into ibc-rate-limit
nicolaslara Aug 17, 2022
73acb2f
workflow without test data checks and clippy fixes
nicolaslara Aug 17, 2022
5b66bdc
renamed CHANNEL_FLOWS
nicolaslara Aug 17, 2022
2e4a6ab
renaming and code clenaup
nicolaslara Aug 17, 2022
4af7fe9
more renames
nicolaslara Aug 17, 2022
48b19cb
renames and code fixes
nicolaslara Aug 17, 2022
0dd7fc9
Merge branch 'nicolas/ibc-rate-limit-contract' into ibc-rate-limit
nicolaslara Aug 17, 2022
6180eb8
reordered imports
nicolaslara Aug 17, 2022
82c83b1
cargo fmt
nicolaslara Aug 17, 2022
92b4bb3
Merge branch 'nicolas/ibc-rate-limit-contract' into ibc-rate-limit
nicolaslara Aug 17, 2022
d4ace7b
added danom tracking
nicolaslara Aug 17, 2022
746daa9
cleanup
nicolaslara Aug 17, 2022
fe97ee8
refactoring
nicolaslara Aug 18, 2022
c6758f1
changes to the expiration logic so that balances are calculated based…
nicolaslara Aug 18, 2022
e1d52f4
slightly slower but considerably cleanner
nicolaslara Aug 18, 2022
7434a44
cleanup attributes and removed redundancy when not testing
nicolaslara Aug 18, 2022
727fef2
update to edition 2021
nicolaslara Aug 18, 2022
7859a55
added comments explaining the tests
nicolaslara Aug 18, 2022
628db47
removed .beaker
nicolaslara Aug 18, 2022
9facb27
unified gitignore
nicolaslara Aug 18, 2022
042f3f4
removed second gitignore
nicolaslara Aug 18, 2022
c37a968
better doc comments
nicolaslara Aug 18, 2022
e5d72d6
spelling
nicolaslara Aug 18, 2022
d658fdd
spelling
nicolaslara Aug 18, 2022
c2a72ad
added channel value cache
nicolaslara Aug 18, 2022
0b738c9
Merge branch 'nicolas/ibc-rate-limit-contract' into ibc-rate-limit
nicolaslara Aug 19, 2022
71d8aca
updated the middlware to use the new contract interface
nicolaslara Aug 19, 2022
8135a90
update middleware to match new contract interface
nicolaslara Aug 19, 2022
2151825
added missing updates
nicolaslara Aug 19, 2022
a800e9b
updated dependencies
nicolaslara Aug 19, 2022
ae15972
added missing helpers
nicolaslara Aug 19, 2022
f8b972a
go.mod changes shouldn't be in this branch
nicolaslara Aug 19, 2022
e15c77c
Revert "go.mod changes shouldn't be in this branch"
nicolaslara Aug 19, 2022
63b23f0
moved send and receive to sudo
nicolaslara Aug 22, 2022
7aa90e3
reorganizing
nicolaslara Aug 22, 2022
fcec5b9
calling the contract via sudo
nicolaslara Aug 22, 2022
7acacb3
lint
nicolaslara Aug 22, 2022
4268c79
removed gitkeep
nicolaslara Aug 22, 2022
80617e8
using sudo instead of execute
nicolaslara Aug 22, 2022
0529667
cleaned up and updated contract and integration
nicolaslara Aug 22, 2022
294e19a
updated x86 test wasm file
nicolaslara Aug 22, 2022
6c49460
fixed bad print
nicolaslara Aug 23, 2022
3028b38
storing and instantiating the contract
nicolaslara Aug 23, 2022
f332e23
setting up E2E tests for ibc rate limits
nicolaslara Aug 24, 2022
5bdccfc
fixed proposal. Now just have to get the math right and cleanup
nicolaslara Aug 24, 2022
b9408e6
Using the supply for the channel value
nicolaslara Aug 25, 2022
6916ffa
experimenting with e2e tests
nicolaslara Aug 25, 2022
216bcee
passing the contract keeper instead of instantiating it each time
nicolaslara Aug 25, 2022
f1cdb16
changes from code review
nicolaslara Aug 25, 2022
314455e
added contract from main and changes to the middleware from code review
nicolaslara Aug 25, 2022
0aed029
using the correct bank supply method
nicolaslara Aug 26, 2022
54056fa
debugging issues with e2e tests. Everything works after one interacti…
nicolaslara Aug 26, 2022
cd74eaa
Merge branch 'main' into nicolas/merged-supply-offset-dependency
nicolaslara Aug 26, 2022
a69b58f
updated dependency to match latest sdk form (now that the changes to …
nicolaslara Aug 26, 2022
e8e9012
working E2E test for rate limiting
nicolaslara Aug 26, 2022
381e5e2
added e2e tests and changes from code review
nicolaslara Aug 26, 2022
fa8cafe
removed debug logs
nicolaslara Aug 26, 2022
cc91a76
remove debug logs
nicolaslara Aug 26, 2022
bbcc8af
Merge branch 'main' into nicolas/ibc-rate-limit-middlware
nicolaslara Aug 26, 2022
d4e10bd
Merge branch 'ibc-rate-limit' into nicolas/ibc-rate-limit-integration…
nicolaslara Aug 26, 2022
45ca648
Merge branch 'main' into nicolas/ibc-rate-limit-integration-and-tests
nicolaslara Aug 26, 2022
c425518
Merge branch 'nicolas/merged-supply-offset-dependency' into nicolas/i…
nicolaslara Aug 26, 2022
fde1440
Merge branch 'nicolas/merged-supply-offset-dependency' into nicolas/i…
nicolaslara Aug 26, 2022
79843a1
Merge branch 'nicolas/merged-supply-offset-dependency' into ibc-rate-…
nicolaslara Aug 26, 2022
fd54ed3
updated test to also use GetSupplyWithOffset
nicolaslara Aug 26, 2022
298636d
using correct GetSupplyWithOffset method
nicolaslara Aug 26, 2022
5561530
using correct GetSupplyWithOffset method
nicolaslara Aug 26, 2022
6e47abc
lint
nicolaslara Aug 26, 2022
deaacfd
Merge branch 'ibc-rate-limit' into nicolas/ibc-rate-limit-integration…
nicolaslara Aug 26, 2022
c676404
removed e2e from this branch as it's not doing anything without the i…
nicolaslara Aug 26, 2022
7544235
lint
nicolaslara Aug 26, 2022
98b720d
Merge branch 'ibc-rate-limit' into nicolas/ibc-rate-limit-integration…
nicolaslara Aug 26, 2022
a7f5bc4
tests fail on CI because of "inactive" proposal. Is the deposit the i…
nicolaslara Aug 26, 2022
89cf19f
remove rate limiting after the test so it doesn't interfeer with the …
nicolaslara Aug 26, 2022
10424b4
using standard proposals instead of expedited
nicolaslara Aug 26, 2022
4b23e98
Merge branch 'ibc-rate-limit' into nicolas/ibc-rate-limit-integration…
nicolaslara Aug 26, 2022
443fff3
added packet reverts on unsuccessful acks and timeouts
nicolaslara Aug 29, 2022
76c9cc9
lint
nicolaslara Aug 29, 2022
d46b51c
ran gofumpt
nicolaslara Aug 29, 2022
af4d9a7
lint
nicolaslara Aug 29, 2022
2751bee
added undo to the contract
nicolaslara Aug 30, 2022
b682542
integrating undo
nicolaslara Aug 30, 2022
fa12ff0
updated contract with x86 wasm file
nicolaslara Aug 30, 2022
25a7767
added undo for sent packages when they are rejected bia timeout or a …
nicolaslara Aug 30, 2022
219118c
added a readme
nicolaslara Aug 30, 2022
803d26e
markdown lint
nicolaslara Aug 30, 2022
f474ee4
added readme
nicolaslara Aug 30, 2022
a3f82e9
abstracted params
nicolaslara Aug 30, 2022
ddfcac0
better params and param tests
nicolaslara Aug 31, 2022
3018357
using a helper function instead of returning from the test
nicolaslara Aug 31, 2022
42b354d
updated contract to allow for undo
nicolaslara Aug 31, 2022
3350c57
added undo, readme, and cleanup based on reviews
nicolaslara Aug 31, 2022
a183a0e
Merge branch 'main' into ibc-rate-limit
nicolaslara Aug 31, 2022
2825e21
updated wasm file with x86 version
nicolaslara Aug 31, 2022
ca5fecf
using string params in e2e tests
nicolaslara Aug 31, 2022
20b40de
Merge branch 'main' into nicolas/ibc-rate-limit-middlware
nicolaslara Aug 31, 2022
3f98ebe
Merge branch 'main' into ibc-rate-limit
nicolaslara Sep 7, 2022
463f1cc
updated to v12
nicolaslara Sep 7, 2022
eb6471b
removed unnecessary keeper
nicolaslara Sep 7, 2022
f2ba12f
only exposing what's needed
nicolaslara Sep 7, 2022
4b68e46
refactoring
nicolaslara Sep 7, 2022
1506c3f
updated types
nicolaslara Sep 7, 2022
33ad060
added shell history to gitignore
nicolaslara Sep 7, 2022
30fb80b
adding only one wasm file to the codebase
nicolaslara Sep 7, 2022
acf1f50
remove test for same wasm files. No longer needed.
nicolaslara Sep 7, 2022
4541b87
Merge branch 'main' into nicolas/ibc-rate-limit-middlware
nicolaslara Sep 7, 2022
f9ee22d
refactor based on code review
nicolaslara Sep 7, 2022
d9df73c
removed integration tests as they won't pass without integration
nicolaslara Sep 7, 2022
e681a7d
added params unit test
nicolaslara Sep 7, 2022
9e14d15
Merge branch 'main' into nicolas/ibc-rate-limit-integration-and-tests
nicolaslara Sep 7, 2022
11a4957
Merge branch 'nicolas/ibc-rate-limit-middlware' into nicolas/ibc-rate…
nicolaslara Sep 7, 2022
4fc7abb
reorganized tests
nicolaslara Sep 7, 2022
d2daad6
reorganizing tests
nicolaslara Sep 7, 2022
24a3e2e
refactoring
nicolaslara Sep 7, 2022
2095003
Merge branch 'main' into ibc-rate-limit
nicolaslara Sep 8, 2022
65f0485
Merge branch 'ibc-rate-limit' into nicolas/ibc-rate-limit-integration…
nicolaslara Sep 8, 2022
9240011
added address length limit
nicolaslara Sep 9, 2022
0ca235b
Merge branch 'nicolas/ibc-receiver-field-cap' into ibc-rate-limit
nicolaslara Sep 9, 2022
71d60b8
Merge branch 'main' into nicolas/ibc-rate-limit-integration-and-tests
nicolaslara Sep 9, 2022
69b4954
added tests and fixed lack of return
nicolaslara Sep 9, 2022
21e7f51
Merge branch 'ibc-rate-limit' into nicolas/ibc-rate-limit-integration…
nicolaslara Sep 9, 2022
a78c757
remove tests from bad merge
nicolaslara Sep 9, 2022
93413be
remove from bad merge again
nicolaslara Sep 9, 2022
0b45d11
upgraded to cosmwasm 1.1.0 and added schema
nicolaslara Sep 9, 2022
1739f0c
replaced u128 by Uint256
nicolaslara Sep 9, 2022
a5bb034
adding new compiled contract (this will fail in ci so I can get the x…
nicolaslara Sep 9, 2022
82fd8ec
added x86 version of the contract
nicolaslara Sep 9, 2022
c4ad0bb
lint
nicolaslara Sep 9, 2022
f2561e2
Merge branch 'main' into ibc-rate-limit
nicolaslara Sep 9, 2022
1b92379
readme lints
nicolaslara Sep 9, 2022
547b38b
Merge branch 'main' into ibc-rate-limit
nicolaslara Sep 12, 2022
79c7224
Update app/keepers/keepers.go
nicolaslara Sep 26, 2022
130d902
Merge branch 'main' into ibc-rate-limit
nicolaslara Oct 4, 2022
29f61fd
Merge branch 'main' into nicolas/ibc-rate-limit-integration-and-tests
nicolaslara Oct 4, 2022
7b79685
comment
nicolaslara Oct 4, 2022
08a1cd8
test helpers for cosmwasm contracts
nicolaslara Oct 4, 2022
27ee3ee
added helpers for ibctesting
nicolaslara Oct 4, 2022
8c36532
comments
nicolaslara Oct 4, 2022
d125dbd
Merge branch 'nicolas/test-helpers' into nicolas/ibc-rate-limit-integ…
nicolaslara Oct 4, 2022
cc42cab
removed unnecessary txConfig
nicolaslara Oct 4, 2022
41b3cae
fixed typos
nicolaslara Oct 4, 2022
0ad0a90
clearer comment
nicolaslara Oct 4, 2022
7b50cb4
using second helper function for ExportGenesis
nicolaslara Oct 4, 2022
01f6faa
Merge branch 'nicolas/ibc-rate-limit-integration-and-tests' into ibc-…
nicolaslara Oct 5, 2022
40f8cc6
Merge branch 'nicolas/export_for_modules' into nicolas/ibc-rate-limit…
nicolaslara Oct 5, 2022
e7798a1
added new wasm file
nicolaslara Oct 5, 2022
8b27f9d
Merge branch 'nicolas/ibc-rate-limit-integration-and-tests' into ibc-…
nicolaslara Oct 5, 2022
92de82c
added new compiled contract
nicolaslara Oct 5, 2022
4af597a
Merge branch 'main' into ibc-rate-limit
nicolaslara Oct 5, 2022
3c4123e
added x86 version of the wasm file
nicolaslara Oct 5, 2022
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
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ type OsmosisApp struct {
mm *module.Manager
sm *simtypes.Manager
configurator module.Configurator
txConfig client.TxConfig
}

// init sets DefaultNodeHome to default osmosisd install location.
Expand Down Expand Up @@ -174,6 +175,7 @@ func NewOsmosisApp(
appCodec: appCodec,
interfaceRegistry: interfaceRegistry,
invCheckPeriod: invCheckPeriod,
txConfig: encodingConfig.TxConfig,
}

wasmDir := filepath.Join(homePath, "wasm")
Expand Down
18 changes: 17 additions & 1 deletion app/apptesting/events.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package apptesting

import sdk "github.com/cosmos/cosmos-sdk/types"
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"golang.org/x/exp/slices"
)

// AssertEventEmitted asserts that ctx's event manager has emitted the given number of events
// of the given type.
Expand All @@ -15,3 +18,16 @@ func (s *KeeperTestHelper) AssertEventEmitted(ctx sdk.Context, eventTypeExpected
}
s.Equal(numEventsExpected, len(actualEvents))
}

func (s *KeeperTestHelper) FindEvent(events []sdk.Event, name string) sdk.Event {
index := slices.IndexFunc(events, func(e sdk.Event) bool { return e.Type == name })
return events[index]
}

func (s *KeeperTestHelper) ExtractAttributes(event sdk.Event) map[string]string {
attrs := make(map[string]string)
for _, a := range event.Attributes {
attrs[string(a.Key)] = string(a.Value)
}
return attrs
}
Copy link
Member

Choose a reason for hiding this comment

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

:O nice

30 changes: 27 additions & 3 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The 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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added an issue for this: #2869


return paramsKeeper
}
Expand Down
21 changes: 21 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package app

import (
"github.com/CosmWasm/wasmd/x/wasm"
"github.com/cosmos/cosmos-sdk/client"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v3/modules/core"
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"

ica "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts"
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
Expand Down Expand Up @@ -245,3 +249,20 @@ func (app *OsmosisApp) GetAccountKeeper() simtypes.AccountKeeper {
func (app *OsmosisApp) GetBankKeeper() simtypes.BankKeeper {
return app.AppKeepers.BankKeeper
}

// Required for ibctesting
func (app *OsmosisApp) GetStakingKeeper() stakingkeeper.Keeper {
return *app.AppKeepers.StakingKeeper
nicolaslara marked this conversation as resolved.
Show resolved Hide resolved
}

func (app *OsmosisApp) GetIBCKeeper() *ibckeeper.Keeper {
return app.AppKeepers.IBCKeeper
}

func (app *OsmosisApp) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {
return app.AppKeepers.ScopedIBCKeeper
}

func (app *OsmosisApp) GetTxConfig() client.TxConfig {
return app.txConfig
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ replace (
// branch: v0.27.0.rc3-osmo, current tag: v0.27.0.rc3-osmo
github.com/CosmWasm/wasmd => github.com/osmosis-labs/wasmd v0.27.0-rc2.0.20220517191021-59051aa18d58
// Our cosmos-sdk branch is: https://github.com/osmosis-labs/cosmos-sdk, current tag: 0.45.0x-osmo-v11-alpha.5 current branch: osmosis-main
github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20220727221653-51bfa90799ee
github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20220805063506-b5f3b546c63f
// Use Osmosis fast iavl
github.com/cosmos/iavl => github.com/osmosis-labs/iavl v0.17.3-osmo-v7
// use cosmos-compatible protobufs
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1043,8 +1043,8 @@ github.com/ory/dockertest v3.3.5+incompatible h1:iLLK6SQwIhcbrG783Dghaaa3WPzGc+4
github.com/ory/dockertest v3.3.5+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnhNrne+V0E6LAcBILJdPs=
github.com/ory/dockertest/v3 v3.9.1 h1:v4dkG+dlu76goxMiTT2j8zV7s4oPPEppKT8K8p2f1kY=
github.com/ory/dockertest/v3 v3.9.1/go.mod h1:42Ir9hmvaAPm0Mgibk6mBPi7SFvTXxEcnztDYOJ//uM=
github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20220727221653-51bfa90799ee h1:JUWaacaNfxC0IxxkpC/MsJozi1eKQztZX+Wa9OU6+cw=
github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20220727221653-51bfa90799ee/go.mod h1:uUkGXyCWol+CHoaMxZA0nKglvlN5uHBCMbMSsZoGSAs=
github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20220805063506-b5f3b546c63f h1:DQN9TWeHngVmMTdrhNkt93lw6wrFa4xTva5z3tDST58=
github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20220805063506-b5f3b546c63f/go.mod h1:uUkGXyCWol+CHoaMxZA0nKglvlN5uHBCMbMSsZoGSAs=
github.com/osmosis-labs/iavl v0.17.3-osmo-v7 h1:6KcADC/WhL7yDmNQxUIJt2XmzNt4FfRmq9gRke45w74=
github.com/osmosis-labs/iavl v0.17.3-osmo-v7/go.mod h1:lJEOIlsd3sVO0JDyXWIXa9/Ur5FBscP26zJx0KxHjto=
github.com/osmosis-labs/wasmd v0.27.0-rc2.0.20220517191021-59051aa18d58 h1:15l3Iss2oCGCeJRi2g3CuCnqmEjpAr3Le7cDnoN/LS0=
Expand Down
12 changes: 12 additions & 0 deletions proto/osmosis/ibc-rate-limit/v1beta1/params.proto
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\"" ];
}
9 changes: 9 additions & 0 deletions tests/e2e/configurer/chain/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ func (n *NodeConfig) CreatePool(poolFile, from string) {
n.LogActionF("successfully created pool")
}

func (n *NodeConfig) StoreWasmCode(wasmFile, from string) {
n.LogActionF("storing wasm code from file %s", wasmFile)
cmd := []string{"osmosisd", "tx", "wasm", "store", wasmFile, fmt.Sprintf("--from=%s", from), "--gas=auto"}
_, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, cmd)
n.LogActionF(err.Error())
require.NoError(n.t, err)
n.LogActionF("successfully stored")
}

func (n *NodeConfig) SubmitUpgradeProposal(upgradeVersion string, upgradeHeight int64, initialDeposit sdk.Coin) {
n.LogActionF("submitting upgrade proposal %s for height %d", upgradeVersion, upgradeHeight)
cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "software-upgrade", upgradeVersion, fmt.Sprintf("--title=\"%s upgrade\"", upgradeVersion), "--description=\"upgrade proposal submission\"", fmt.Sprintf("--upgrade-height=%d", upgradeHeight), "--upgrade-info=\"\"", "--from=val", fmt.Sprintf("--deposit=%s", initialDeposit)}
Expand Down
26 changes: 26 additions & 0 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggest trying s.Require().NoError(err)

Without it, the test does not fail and continues.

It seems that there might be a path/permission issue at this step with:

open ../../x/ibc-rate-limit/testdata/rate-limiter.wasm: no such file or directory

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 /osmosis/rate-limiter.wasm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)

Copy link
Member

Choose a reason for hiding this comment

The 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
Expand Down
3 changes: 0 additions & 3 deletions tests/e2e/initialization/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,6 @@ func updateBankGenesis(bankGenState *banktypes.GenesisState) {
},
},
})
if len(bankGenState.SupplyOffsets) == 0 {
bankGenState.SupplyOffsets = []banktypes.GenesisSupplyOffset{}
}
}

func updateStakeGenesis(stakeGenState *staketypes.GenesisState) {
Expand Down
Binary file added tests/e2e/scripts/rate_limiter.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions x/ibc-rate-limit/.beaker/state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
21 changes: 21 additions & 0 deletions x/ibc-rate-limit/.gitignore
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
1 change: 1 addition & 0 deletions x/ibc-rate-limit/Beaker.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name = "ibc-rate-limit"
16 changes: 16 additions & 0 deletions x/ibc-rate-limit/Cargo.toml
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
Empty file.
3 changes: 3 additions & 0 deletions x/ibc-rate-limit/contracts/rate-limiter/.cargo/config
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"
15 changes: 15 additions & 0 deletions x/ibc-rate-limit/contracts/rate-limiter/.gitignore
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
53 changes: 53 additions & 0 deletions x/ibc-rate-limit/contracts/rate-limiter/Cargo.toml
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"
Loading