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

IBC Rate Limiting #2339

wants to merge 251 commits into from

Conversation

nicolaslara
Copy link
Contributor

@nicolaslara nicolaslara commented Aug 9, 2022

Closes: ##2305

What is the purpose of the change

We want to add the feature of rate limiting sends on IBC channels to Osmosis. The intended goal, is to be able to cap the amount of certain assets that can flow into and out of Osmosis per unit time, to mitigate bridge risk. It should be the case that if there is some unforeseen bridge bug or infinite token mint, the max amount extractable out of Osmosis is bounded.

See issue #2305. This PR tracks the development of the IBC Rate Limiting functionality.

Brief Changelog

  • An IBC middleware is now provided and registered with the IBC transfer module.
  • The level of rate limiting is controlled by a rate limiting contract that can be controlled by an address specified by governance (this could be the gov module itself)
  • The "governance address" of the rate limiting contract can reset the quota when a rate limit is hit (this could be the gov module itself)

Testing and Verifying

This change added tests and can be verified as follows:

  • Added integration tests for the middleware (IBC Message <-> IBC transfer module <-> RateLimitingMiddlware <-> Relayer <-> Counterparty chain)
  • TBD: Added E2E tests for the middleware

Documentation and Release Note

TBD

  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md? (yes / no)
  • How is the feature or change documented? (not applicable / specification (x/<module>/spec/) / Osmosis docs repo / not documented)

@github-actions github-actions bot added C:app-wiring Changes to the app folder C:x/mint labels Aug 9, 2022
@github-actions github-actions bot added the C:docs Improvements or additions to documentation label Sep 9, 2022
@github-actions github-actions bot removed the C:docs Improvements or additions to documentation label Sep 12, 2022
Copy link
Member

@mattverse mattverse left a comment

Choose a reason for hiding this comment

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

Left some comments! Havent looked at the e2e tests, but other changes lgtm!

app/modules.go Outdated Show resolved Hide resolved
@@ -440,6 +464,7 @@ func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legac
paramsKeeper.Subspace(wasm.ModuleName)
paramsKeeper.Subspace(tokenfactorytypes.ModuleName)
paramsKeeper.Subspace(twaptypes.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

app/keepers/keepers.go Show resolved Hide resolved
@@ -46,8 +46,8 @@ pub mod tests {
quota_name: &str,
send_recv: (u32, u32),
duration: u64,
inflow: u128,
outflow: u128,
inflow: Uint256,
Copy link
Member

Choose a reason for hiding this comment

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

just curious what made us change from u128 -> Uint256? Did we simply want to handle larger inflows and outflows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to deal with the case of a token having a very high precision: see this comment

@@ -103,12 +103,27 @@ func (im *IBCModule) OnChanCloseConfirm(
return im.app.OnChanCloseConfirm(ctx, portID, channelID)
}

func ValidateReceiverAddress(packet channeltypes.Packet) error {
var packetData transfertypes.FungibleTokenPacketData
if err := json.Unmarshal(packet.GetData(), &packetData); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Is this simply checking if packetData can be succesfully unmarshalled without erroring?

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

return gInfo, res, err
}

// Move epochs to the future to avoid issues with minting
Copy link
Member

Choose a reason for hiding this comment

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

what's the issue when tokens get minted? Also curious if we don't need epoch within these testings at all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See this: #2409 (comment).

I considered removing the epochs, but I think it was more work that this workaround. Since it's only for this test, I figured this was enough.

accountFrom = suite.chainA.SenderAccount.GetAddress().String()
accountTo = suite.chainB.SenderAccount.GetAddress().String()
} else {
coins = transfertypes.GetTransferCoin(
Copy link
Member

Choose a reason for hiding this comment

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

should be deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we need this to test the receive case, but I may be wrong. I'll double check

x/ibc-rate-limit/ibc_middleware_test.go Outdated Show resolved Hide resolved
)
}

// Tests that a receiver address longer than 4096 is not accepted
Copy link
Member

Choose a reason for hiding this comment

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

nit: consider grouping helper methods together and the actual tests together

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wrote it this way cause I like the helpers to be close to where they're being used, but not a strong opinion, so I can move them

x/ibc-rate-limit/ibc_middleware_test.go Show resolved Hide resolved
@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label Oct 20, 2022
@github-actions github-actions bot closed this Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:app-wiring Changes to the app folder Stale T:CI
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants