-
Notifications
You must be signed in to change notification settings - Fork 700
Middleware Wiring Improvements #8528
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8528 +/- ##
=======================================
Coverage 57.58% 57.59%
=======================================
Files 317 319 +2
Lines 22666 22733 +67
=======================================
+ Hits 13052 13092 +40
- Misses 9006 9032 +26
- Partials 608 609 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@@ -26,27 +26,37 @@ var ( | |||
// ICA controller keeper and the underlying application. | |||
type IBCMiddleware struct { | |||
app porttypes.IBCModule | |||
keeper keeper.Keeper | |||
keeper *keeper.Keeper |
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.
I made the keepers inside middlewares and modules to now be pointers so that I can call WithICS4Wrapper
on them and have it persist in other references
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.
Is this a requirement for middlewares wiring up with this?
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.
If you are using a keeper function to do SendPacket and WriteAck then yes. We have middlewares that don't use keepers (e.g. callbacks) so then its not needed
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.
OK, sounds like it will be quite important to get some migration docs for all of this then!
storeService: storeService, | ||
cdc: cdc, | ||
ics4Wrapper: ics4Wrapper, | ||
ics4Wrapper: channelKeeper, |
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.
NewKeeper
defaults to using channelKeeper
as ICS4Wrapper. If you need this changed, you should use the stack builder primitive to set a new ICS4Wrapper
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.
Make sure to document this in the migration guide!
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.
Did a first pass, left a couple of questions, but this is clearly a big improvement, and it should be much harder to do this incorrectly. It still will require documentation and migration guides. At least the migration guide additions would be good to get sorted in this PR (for both chains and middleware devs).
@@ -26,27 +26,37 @@ var ( | |||
// ICA controller keeper and the underlying application. | |||
type IBCMiddleware struct { | |||
app porttypes.IBCModule | |||
keeper keeper.Keeper | |||
keeper *keeper.Keeper |
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.
Is this a requirement for middlewares wiring up with this?
|
||
// Add transfer stack to IBC Router | ||
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack) | ||
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack.Build(app.IBCKeeper.ChannelKeeper)) |
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.
Would it make more sense for the channel keeper to just be set on construction instead of being passed into the build method?
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.
Not super important though...
// The ICS4Wrapper **must** be used for sending packets and writing acknowledgements | ||
// to ensure that the middleware can intercept and process these calls. | ||
// Do not use the channel keeper directly to send packets or write acknowledgements | ||
// as this will bypass the middleware. |
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.
Just so I understand: this has always been a requirement of middlewares (to not use the channel keeper directly)?
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.
That is correct, though many people don't do it anyway. Which ends up being functionally ok because most of the middlewares are modifying recvpacket and not send and writeack
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.
Not sure where we are on docs with this, but we should:
- Make sure the docs are clear about this
- Link to that in the migration guide
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.
This looks great! I left some more comments, but the main thing we need to get in here is docs on the wiring and migration docs for both chains and middleware devs.
FYI: I merged in main and linted, so you should probably take a look through all the code another time yourself too.
You should in particular check out the rate-limiting middleware as I integrated it myself, and made similar changes that you've made to the other middlewares.
@@ -1,70 +1,69 @@ | |||
package ratelimiting |
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.
@AdityaSripal I merged in rate-limiting, so make sure it looks correct, please :)
@@ -2,6 +2,9 @@ module github.com/cosmos/ibc-go/e2e | |||
|
|||
go 1.24.3 | |||
|
|||
// TODO: Remove when v11 release of interchaintest is available (that is where this one is coming from) | |||
replace github.com/cosmos/interchain-security/v7 => github.com/cosmos/interchain-security/v7 v7.0.0-20250622154438-73c73cf686e5 |
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.
Had to add this, because interchaintest pulls in this, and the changes here break it :/
The PR that has the commit referenced in the replace: cosmos/interchain-security#2622
// to ensure that the middleware can intercept and process these calls. | ||
// Do not use the channel keeper directly to send packets or write acknowledgements | ||
// as this will bypass the middleware. | ||
SetICS4Wrapper(wrapper ICS4Wrapper) |
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.
A couple of things that might cause confusion:
- We have a mix of "SetICS4Wrapper" and "WithICS4Wrapper"
- We have these both in keepers and middleware (which I understand), but it makes for confusing interfaces
Can I suggest thinking about renaming so that perhaps the middleware SetICS4Wrapper is named distinctly from the keepers version of it? Ideally with something in the name that makes it clearer what it's for (and that it is middleware specific). There are also keepers that accidentally fulfill this interface, I don't think they should.
@@ -0,0 +1,51 @@ | |||
package types | |||
|
|||
type IBCStackBuilder struct { |
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.
There is an opportunity to give this extra value by adding a query to ibc core (or somewhere where it makes sense) for users to see the stack. Skip go currently keeps a manual repository of which chains support PFM, for instance. If they could just query, it would help them automate this in the future.
Additionally, chain devs could debug their stack more easily.
It could either just take list here and add another function to the Middleware interface to return a name (types.ModuleName type of response), or maybe even have it come out of ICS4Wrapper so it actually flows through the application stack.
wdyt?
|
||
// Add transfer stack to IBC Router | ||
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack) | ||
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack.Build(app.IBCKeeper.ChannelKeeper)) |
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.
Not super important though...
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.
Pull Request Overview
This PR improves the middleware wiring across multiple modules by converting various keeper and module types to pointer types and standardizing the use of ICS4Wrapper across IBC modules. Key changes include updating the return types in NewKeeper functions, refactoring middleware stack building logic, and revising test cases to align with the new pointer-based designs.
Reviewed Changes
Copilot reviewed 50 out of 51 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
testing/simapp/app.go | Updated keeper pointer types for ICA, Transfer, and RateLimit modules. |
testing/mock/middleware.go | Refactored ICS4Wrapper setter and related panic behavior. |
testing/mock/ibc_module.go | Modified NewIBCModule return type to pointer and adjusted ICS4Wrapper conversion. |
simapp/app.go | Reworked keeper instantiation and middleware wiring with pointer consistency. |
modules/light-clients/08-wasm/testing/simapp/app.go | Applied updates for pointer types and middleware wiring in the testing simapp. |
modules/core/api/module.go | Corrected naming of “PacketUnmarshalerModule” for clarity. |
modules/core/ante/ante_test.go | Adjusted message creation functions to use updated parameter names. |
modules/core/05-port/types/stack.go | Introduced IBCStackBuilder enhancements to support middleware stacking. |
modules/core/05-port/types/module.go | Updated ICS4Wrapper setter documentation and interface methods. |
modules/apps/transfer/** | Converted keeper and module functions to use pointer types and updated ICS4Wrapper wiring. |
modules/apps/rate-limiting/** | Updated keeper creation, query server registration, and test cases to use pointer types. |
modules/apps/packet-forward-middleware/** | Standardized keeper instantiation, updated ICS4Wrapper handling, and fixed type casts. |
modules/apps/callbacks/** | Revised middleware and application wiring for callbacks, ensuring pointer correctness. |
modules/apps/27-interchain-accounts/** | Updated keeper and IBCModule implementations for host and controller chains, including genesis and test files. |
e2e/go.mod | Added a replace directive for interchain-security dependency version. |
@@ -282,6 +284,7 @@ func (k *Keeper) ForwardTransferPacket(ctx sdk.Context, inFlightPacket *types.In | |||
"denom", token.Denom, | |||
"error", err, | |||
) | |||
// TODO: Should probably have custom errors! | |||
return errorsmod.Wrap(sdkerrors.ErrInsufficientFunds, err.Error()) |
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.
Consider defining and using custom error types instead of wrapping with generic errors. This will provide clearer error context and facilitate better error handling in production code.
Copilot uses AI. Check for mistakes.
Description
closes: #5814
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
docs/
) if anything is changed.godoc
comments if relevant.Files changed
in the GitHub PR explorer.