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 limit native tokens on all channels #3229

Closed
wants to merge 278 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
278 commits
Select commit Hold shift + click to select a range
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
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
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
88b1c4a
Merge branch 'main' into nicolas/ibc-rate-limit-integration-and-tests
nicolaslara Oct 5, 2022
f58e267
updated the contract to cosmwasm 1.1 and Uint256 for amounts
nicolaslara Oct 5, 2022
032f33b
Fixed send with ibc assets. Better tests and error messages
nicolaslara Oct 21, 2022
f107877
updated contract with x86 version
nicolaslara Oct 21, 2022
237f144
gofumpt
nicolaslara Oct 21, 2022
caad1f2
fixed clippy errors
nicolaslara Oct 21, 2022
13f2621
using the escrowed value as the channel value for native tokens
nicolaslara Oct 22, 2022
79109a2
gofumpt
nicolaslara Oct 22, 2022
60811cf
update fail string
nicolaslara Oct 23, 2022
c50cf10
Merge branch 'main' into nicolas/ibc-rate-limit-integration-and-tests
nicolaslara Oct 23, 2022
f3fb41d
initial experiments with moving the calculations into the contract
nicolaslara Oct 26, 2022
f3ffd4a
initial experiments with using the packet inside the contract
nicolaslara Oct 26, 2022
280382f
improved tests. Experiments with packet in the contract.
nicolaslara Oct 26, 2022
a843646
original contract
nicolaslara Oct 26, 2022
4f66cb1
cleaner tests
nicolaslara Oct 26, 2022
eac58d5
more test cleanup
nicolaslara Oct 26, 2022
68e007b
cleaner tests
nicolaslara Oct 28, 2022
2f932b5
Merge branch 'nicolas/ibc-rate-limit-contract-updates' into nicolas/i…
nicolaslara Oct 28, 2022
3e1539e
cleanup
nicolaslara Oct 28, 2022
952a2e6
Merge branch 'main' into nicolas/ibc-rate-limit-integration-and-tests
ValarDragon Oct 29, 2022
ef94442
align values from the tests and the contract
nicolaslara Oct 30, 2022
a80d964
fixed amounts for receive and cleanup code
nicolaslara Oct 30, 2022
e9a4d52
removed redundant wrapping logic
nicolaslara Oct 30, 2022
c2caa5c
adaped failed send test to the new testing abstractions
nicolaslara Oct 30, 2022
60330ea
only manipulate time on chain A
nicolaslara Oct 30, 2022
cd96c4d
Merge branch 'nicolas/ibc-rate-limit-integration-and-tests' into nico…
nicolaslara Oct 30, 2022
f2429dc
remove commented out block
nicolaslara Oct 31, 2022
719fd38
changed lints to stable so they change less often
nicolaslara Oct 31, 2022
80d04fd
gofumpt
nicolaslara Oct 31, 2022
976a672
update channel value tests
nicolaslara Oct 31, 2022
3ae7c43
Merge branch 'nicolas/cosmwasm-lints-2' into nicolas/ibc-rate-limit/n…
nicolaslara Oct 31, 2022
503011e
added x86 version of the contract for ci
nicolaslara Oct 31, 2022
49aa140
remove lint type that doesn't exist on stable
nicolaslara Oct 31, 2022
caf51cf
get the channel value across all channels for native assets
nicolaslara Nov 2, 2022
67dad2f
Merge branch 'main' into nicolas/ibc-rate-limit/channel-value-across-…
nicolaslara Nov 2, 2022
cdb75b2
gofumpt
nicolaslara Nov 2, 2022
6b0a6f3
temporarily using the whole supply for native tokens for performance …
nicolaslara Nov 2, 2022
958fdd7
fix expiration tests to to not use reduced value
nicolaslara Nov 3, 2022
4c599ba
filtering native tokens across all channels
nicolaslara Nov 3, 2022
f78273a
updated bytecode to x86
nicolaslara Nov 3, 2022
a5bbd6a
Merge branch 'nicolas/ibc-rate-limit/channel-value-across-channels' i…
nicolaslara Nov 3, 2022
f742674
Merge branch 'main' into nicolas/ibc-rate-limit/channel-any
nicolaslara Nov 7, 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
16 changes: 10 additions & 6 deletions x/ibc-rate-limit/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,10 @@ func (suite *MiddlewareTestSuite) AssertSend(success bool, msg sdk.Msg) (*sdk.Re
return r, err
}

func (suite *MiddlewareTestSuite) BuildChannelQuota(name, denom string, duration, send_precentage, recv_percentage uint32) string {
func (suite *MiddlewareTestSuite) BuildChannelQuota(name, channel, denom string, duration, send_precentage, recv_percentage uint32) string {
return fmt.Sprintf(`
{"channel_id": "channel-0", "denom": "%s", "quotas": [{"name":"%s", "duration": %d, "send_recv":[%d, %d]}] }
`, denom, name, duration, send_precentage, recv_percentage)
{"channel_id": "%s", "denom": "%s", "quotas": [{"name":"%s", "duration": %d, "send_recv":[%d, %d]}] }
`, channel, denom, name, duration, send_precentage, recv_percentage)
}

// Tests
Expand Down Expand Up @@ -259,9 +259,11 @@ func (suite *MiddlewareTestSuite) fullSendTest(native bool) map[string]string {
suite.initializeEscrow()
// Get the denom and amount to send
denom := sdk.DefaultBondDenom
channel := "any"
if !native {
denomTrace := transfertypes.ParseDenomTrace(transfertypes.GetPrefixedDenom("transfer", "channel-0", denom))
denom = denomTrace.IBCDenom()
channel = "channel-0"
}

osmosisApp := suite.chainA.GetOsmosisApp()
Expand All @@ -277,7 +279,7 @@ func (suite *MiddlewareTestSuite) fullSendTest(native bool) map[string]string {

// Setup contract
suite.chainA.StoreContractCode(&suite.Suite)
quotas := suite.BuildChannelQuota("weekly", denom, 604800, 5, 5)
quotas := suite.BuildChannelQuota("weekly", channel, denom, 604800, 5, 5)
fmt.Println(quotas)
addr := suite.chainA.InstantiateContract(&suite.Suite, quotas)
suite.chainA.RegisterRateLimitingContract(addr)
Expand Down Expand Up @@ -343,9 +345,11 @@ func (suite *MiddlewareTestSuite) fullRecvTest(native bool) {
suite.initializeEscrow()
// Get the denom and amount to send
denom := sdk.DefaultBondDenom
channel := "any"
if !native {
denomTrace := transfertypes.ParseDenomTrace(transfertypes.GetPrefixedDenom("transfer", "channel-0", denom))
denom = denomTrace.IBCDenom()
channel = "channel-0"
}

osmosisApp := suite.chainA.GetOsmosisApp()
Expand All @@ -361,7 +365,7 @@ func (suite *MiddlewareTestSuite) fullRecvTest(native bool) {

// Setup contract
suite.chainA.StoreContractCode(&suite.Suite)
quotas := suite.BuildChannelQuota("weekly", denom, 604800, 5, 5)
quotas := suite.BuildChannelQuota("weekly", channel, denom, 604800, 5, 5)
addr := suite.chainA.InstantiateContract(&suite.Suite, quotas)
suite.chainA.RegisterRateLimitingContract(addr)

Expand Down Expand Up @@ -400,7 +404,7 @@ func (suite *MiddlewareTestSuite) TestFailedSendTransfer() {
suite.initializeEscrow()
// Setup contract
suite.chainA.StoreContractCode(&suite.Suite)
quotas := suite.BuildChannelQuota("weekly", sdk.DefaultBondDenom, 604800, 1, 1)
quotas := suite.BuildChannelQuota("weekly", "any", sdk.DefaultBondDenom, 604800, 1, 1)
addr := suite.chainA.InstantiateContract(&suite.Suite, quotas)
suite.chainA.RegisterRateLimitingContract(addr)

Expand Down
19 changes: 17 additions & 2 deletions x/ibc-rate-limit/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ibc_rate_limit

import (
"encoding/json"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -136,13 +137,20 @@ func (im *IBCModule) OnRecvPacket(

channelValue := im.ics4Middleware.CalculateChannelValue(ctx, denom)

channel := packet.GetSourceChannel()
if !strings.HasPrefix(denom, "ibc/") {
// For native channels, we want to have only one limit across all channels. We can use a quota for
//channel "any" for this
channel = "any"
}
nicolaslara marked this conversation as resolved.
Show resolved Hide resolved

err = CheckAndUpdateRateLimits(
ctx,
im.ics4Middleware.ContractKeeper,
"recv_packet",
contract,
channelValue,
packet.GetDestChannel(),
channel,
denom, // We always use the packet's denom here, as we want the limits to be the same on both directions
amount,
)
Expand Down Expand Up @@ -219,11 +227,18 @@ func (im *IBCModule) RevertSentPacket(
return nil
}

channel := packet.GetSourceChannel()
if !strings.HasPrefix(data.Denom, "ibc/") {
// For native channels, we want to have only one limit across all channels. We can use a quota for
//channel "any" for this
channel = "any"
}

if err := UndoSendRateLimit(
ctx,
im.ics4Middleware.ContractKeeper,
contract,
packet.GetSourceChannel(),
channel,
data.Denom,
data.Amount,
); err != nil {
Expand Down
10 changes: 9 additions & 1 deletion x/ibc-rate-limit/ics4_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
channelkeeper "github.com/cosmos/ibc-go/v3/modules/core/04-channel/keeper"
porttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types"
"github.com/cosmos/ibc-go/v3/modules/core/exported"
"strings"
)

var (
Expand Down Expand Up @@ -59,13 +60,20 @@ func (i *ICS4Wrapper) SendPacket(ctx sdk.Context, chanCap *capabilitytypes.Capab

channelValue := i.CalculateChannelValue(ctx, denom)

channel := packet.GetSourceChannel()
if !strings.HasPrefix(denom, "ibc/") {
// For native channels, we want to have only one limit across all channels. We can use a quota for
//channel "any" for this
channel = "any"
}

err = CheckAndUpdateRateLimits(
ctx,
i.ContractKeeper,
"send_packet",
contract,
channelValue,
packet.GetSourceChannel(),
channel,
denom, // We always use the packet's denom here, as we want the limits to be the same on both directions
amount,
)
Expand Down