-
Notifications
You must be signed in to change notification settings - Fork 672
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
refactor: cleanup middleware stacks #1248
Merged
Merged
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
227f47b
refactor: UX improvements for middleware
seantking 725936f
fix: move fee keeper
seantking 700ad6a
fix: remove unncessary wrapping
seantking 5852bdf
refactor: ica module stack setup
seantking 94f3e23
fix: define icaControllerStack as type porttypes.IBCModule
colin-axner e0e405e
add back controller routing for port
colin-axner fd2360f
refactor: remove unncessary SendPacket
seantking 2793d73
refactor: panic instead of return nil
seantking b419f8f
refactor: changing structure to init all keepers, then stacks & routing
seantking 4a60ff6
docs: add comments
seantking 2aa1f8c
Merge branch 'main' into sean/issue#773-cleanup-middleware-stacks
seantking 31c3f93
nit: comment
seantking 40fbdcc
chore: rename files
seantking 68f4843
chore: comment + nit
seantking 6624b73
refactor: stacks
seantking 611c5db
Update modules/apps/27-interchain-accounts/controller/ibc_middleware.go
seantking 5898bfc
nits: nits
seantking 80816aa
chore: comment
seantking 112d1c1
Merge branch 'main' into sean/issue#773-cleanup-middleware-stacks
seantking ac937cb
chore: chore
seantking 80de572
Merge branch 'main' into sean/issue#773-cleanup-middleware-stacks
seantking File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -10,30 +10,34 @@ import ( | |||||
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types" | ||||||
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" | ||||||
porttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types" | ||||||
"github.com/cosmos/ibc-go/v3/modules/core/exported" | ||||||
ibcexported "github.com/cosmos/ibc-go/v3/modules/core/exported" | ||||||
) | ||||||
|
||||||
// IBCModule implements the ICS26 interface for interchain accounts controller chains | ||||||
type IBCModule struct { | ||||||
keeper keeper.Keeper | ||||||
var _ porttypes.Middleware = &IBCMiddleware{} | ||||||
|
||||||
// IBCMiddlware implements the ICS26 callbacks for the fee middleware given the | ||||||
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.
Suggested change
|
||||||
// ICA controller keeper and the underlying application. | ||||||
type IBCMiddleware struct { | ||||||
app porttypes.IBCModule | ||||||
keeper keeper.Keeper | ||||||
} | ||||||
|
||||||
// NewIBCModule creates a new IBCModule given the associated keeper and underlying application | ||||||
func NewIBCModule(k keeper.Keeper, app porttypes.IBCModule) IBCModule { | ||||||
return IBCModule{ | ||||||
// IBCMiddleware creates a new IBCMiddleware given the associated keeper and underlying application | ||||||
func NewIBCMiddleware(k keeper.Keeper, app porttypes.IBCModule) IBCMiddleware { | ||||||
return IBCMiddleware{ | ||||||
keeper: k, | ||||||
app: app, | ||||||
} | ||||||
} | ||||||
|
||||||
// OnChanOpenInit implements the IBCModule interface | ||||||
// OnChanOpenInit implements the IBCMiddleware interface | ||||||
// | ||||||
// Interchain Accounts is implemented to act as middleware for connected authentication modules on | ||||||
// the controller side. The connected modules may not change the controller side portID or | ||||||
// version. They will be allowed to perform custom logic without changing | ||||||
// the parameters stored within a channel struct. | ||||||
func (im IBCModule) OnChanOpenInit( | ||||||
func (im IBCMiddleware) OnChanOpenInit( | ||||||
ctx sdk.Context, | ||||||
order channeltypes.Order, | ||||||
connectionHops []string, | ||||||
|
@@ -56,8 +60,8 @@ func (im IBCModule) OnChanOpenInit( | |||||
chanCap, counterparty, version) | ||||||
} | ||||||
|
||||||
// OnChanOpenTry implements the IBCModule interface | ||||||
func (im IBCModule) OnChanOpenTry( | ||||||
// OnChanOpenTry implements the IBCMiddleware interface | ||||||
func (im IBCMiddleware) OnChanOpenTry( | ||||||
ctx sdk.Context, | ||||||
order channeltypes.Order, | ||||||
connectionHops []string, | ||||||
|
@@ -70,13 +74,13 @@ func (im IBCModule) OnChanOpenTry( | |||||
return "", sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") | ||||||
} | ||||||
|
||||||
// OnChanOpenAck implements the IBCModule interface | ||||||
// OnChanOpenAck implements the IBCMiddleware interface | ||||||
// | ||||||
// Interchain Accounts is implemented to act as middleware for connected authentication modules on | ||||||
// the controller side. The connected modules may not change the portID or | ||||||
// version. They will be allowed to perform custom logic without changing | ||||||
// the parameters stored within a channel struct. | ||||||
func (im IBCModule) OnChanOpenAck( | ||||||
func (im IBCMiddleware) OnChanOpenAck( | ||||||
ctx sdk.Context, | ||||||
portID, | ||||||
channelID string, | ||||||
|
@@ -95,17 +99,17 @@ func (im IBCModule) OnChanOpenAck( | |||||
return im.app.OnChanOpenAck(ctx, portID, channelID, counterpartyChannelID, counterpartyVersion) | ||||||
} | ||||||
|
||||||
// OnChanOpenAck implements the IBCModule interface | ||||||
func (im IBCModule) OnChanOpenConfirm( | ||||||
// OnChanOpenAck implements the IBCMiddleware interface | ||||||
func (im IBCMiddleware) OnChanOpenConfirm( | ||||||
ctx sdk.Context, | ||||||
portID, | ||||||
channelID string, | ||||||
) error { | ||||||
return sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") | ||||||
} | ||||||
|
||||||
// OnChanCloseInit implements the IBCModule interface | ||||||
func (im IBCModule) OnChanCloseInit( | ||||||
// OnChanCloseInit implements the IBCMiddleware interface | ||||||
func (im IBCMiddleware) OnChanCloseInit( | ||||||
ctx sdk.Context, | ||||||
portID, | ||||||
channelID string, | ||||||
|
@@ -114,26 +118,26 @@ func (im IBCModule) OnChanCloseInit( | |||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel") | ||||||
} | ||||||
|
||||||
// OnChanCloseConfirm implements the IBCModule interface | ||||||
func (im IBCModule) OnChanCloseConfirm( | ||||||
// OnChanCloseConfirm implements the IBCMiddleware interface | ||||||
func (im IBCMiddleware) OnChanCloseConfirm( | ||||||
ctx sdk.Context, | ||||||
portID, | ||||||
channelID string, | ||||||
) error { | ||||||
return im.keeper.OnChanCloseConfirm(ctx, portID, channelID) | ||||||
} | ||||||
|
||||||
// OnRecvPacket implements the IBCModule interface | ||||||
func (im IBCModule) OnRecvPacket( | ||||||
// OnRecvPacket implements the IBCMiddleware interface | ||||||
func (im IBCMiddleware) OnRecvPacket( | ||||||
ctx sdk.Context, | ||||||
packet channeltypes.Packet, | ||||||
_ sdk.AccAddress, | ||||||
) ibcexported.Acknowledgement { | ||||||
return channeltypes.NewErrorAcknowledgement("cannot receive packet on controller chain") | ||||||
} | ||||||
|
||||||
// OnAcknowledgementPacket implements the IBCModule interface | ||||||
func (im IBCModule) OnAcknowledgementPacket( | ||||||
// OnAcknowledgementPacket implements the IBCMiddleware interface | ||||||
func (im IBCMiddleware) OnAcknowledgementPacket( | ||||||
ctx sdk.Context, | ||||||
packet channeltypes.Packet, | ||||||
acknowledgement []byte, | ||||||
|
@@ -147,8 +151,8 @@ func (im IBCModule) OnAcknowledgementPacket( | |||||
return im.app.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer) | ||||||
} | ||||||
|
||||||
// OnTimeoutPacket implements the IBCModule interface | ||||||
func (im IBCModule) OnTimeoutPacket( | ||||||
// OnTimeoutPacket implements the IBCMiddleware interface | ||||||
func (im IBCMiddleware) OnTimeoutPacket( | ||||||
ctx sdk.Context, | ||||||
packet channeltypes.Packet, | ||||||
relayer sdk.AccAddress, | ||||||
|
@@ -163,3 +167,22 @@ func (im IBCModule) OnTimeoutPacket( | |||||
|
||||||
return im.app.OnTimeoutPacket(ctx, packet, relayer) | ||||||
} | ||||||
|
||||||
// SendPacket implements the ICS4 Wrapper interface | ||||||
func (im IBCMiddleware) SendPacket( | ||||||
ctx sdk.Context, | ||||||
chanCap *capabilitytypes.Capability, | ||||||
packet exported.PacketI, | ||||||
) error { | ||||||
return nil | ||||||
} | ||||||
|
||||||
// WriteAcknowledgement implements the ICS4 Wrapper interface | ||||||
func (im IBCMiddleware) WriteAcknowledgement( | ||||||
ctx sdk.Context, | ||||||
chanCap *capabilitytypes.Capability, | ||||||
packet exported.PacketI, | ||||||
ack exported.Acknowledgement, | ||||||
) error { | ||||||
return nil | ||||||
} | ||||||
colin-axner marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,22 +12,25 @@ import ( | |||||
"github.com/cosmos/ibc-go/v3/modules/core/exported" | ||||||
) | ||||||
|
||||||
// IBCModule implements the ICS26 callbacks for the fee middleware given the fee keeper and the underlying application. | ||||||
type IBCModule struct { | ||||||
keeper keeper.Keeper | ||||||
var _ porttypes.Middleware = &IBCMiddleware{} | ||||||
|
||||||
// IBCMiddlware implements the ICS26 callbacks for the fee middleware given the | ||||||
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.
Suggested change
|
||||||
// fee keeper and the underlying application. | ||||||
type IBCMiddleware struct { | ||||||
app porttypes.IBCModule | ||||||
keeper keeper.Keeper | ||||||
} | ||||||
|
||||||
// NewIBCModule creates a new IBCModule given the keeper and underlying application | ||||||
func NewIBCModule(k keeper.Keeper, app porttypes.IBCModule) IBCModule { | ||||||
return IBCModule{ | ||||||
keeper: k, | ||||||
// NewIBCMiddlware creates a new IBCMiddlware given the keeper and underlying application | ||||||
func NewIBCMiddleware(app porttypes.IBCModule, k keeper.Keeper) IBCMiddleware { | ||||||
return IBCMiddleware{ | ||||||
app: app, | ||||||
keeper: k, | ||||||
} | ||||||
} | ||||||
|
||||||
// OnChanOpenInit implements the IBCModule interface | ||||||
func (im IBCModule) OnChanOpenInit( | ||||||
// OnChanOpenInit implements the IBCMiddleware interface | ||||||
func (im IBCMiddleware) OnChanOpenInit( | ||||||
ctx sdk.Context, | ||||||
order channeltypes.Order, | ||||||
connectionHops []string, | ||||||
|
@@ -57,10 +60,10 @@ func (im IBCModule) OnChanOpenInit( | |||||
chanCap, counterparty, versionMetadata.AppVersion) | ||||||
} | ||||||
|
||||||
// OnChanOpenTry implements the IBCModule interface | ||||||
// OnChanOpenTry implements the IBCMiddleware interface | ||||||
// If the channel is not fee enabled the underlying application version will be returned | ||||||
// If the channel is fee enabled we merge the underlying application version with the ics29 version | ||||||
func (im IBCModule) OnChanOpenTry( | ||||||
func (im IBCMiddleware) OnChanOpenTry( | ||||||
ctx sdk.Context, | ||||||
order channeltypes.Order, | ||||||
connectionHops []string, | ||||||
|
@@ -100,8 +103,8 @@ func (im IBCModule) OnChanOpenTry( | |||||
return string(versionBytes), nil | ||||||
} | ||||||
|
||||||
// OnChanOpenAck implements the IBCModule interface | ||||||
func (im IBCModule) OnChanOpenAck( | ||||||
// OnChanOpenAck implements the IBCMiddleware interface | ||||||
func (im IBCMiddleware) OnChanOpenAck( | ||||||
ctx sdk.Context, | ||||||
portID, | ||||||
channelID string, | ||||||
|
@@ -128,8 +131,8 @@ func (im IBCModule) OnChanOpenAck( | |||||
return im.app.OnChanOpenAck(ctx, portID, channelID, counterpartyChannelID, counterpartyVersion) | ||||||
} | ||||||
|
||||||
// OnChanOpenConfirm implements the IBCModule interface | ||||||
func (im IBCModule) OnChanOpenConfirm( | ||||||
// OnChanOpenConfirm implements the IBCMiddleware interface | ||||||
func (im IBCMiddleware) OnChanOpenConfirm( | ||||||
ctx sdk.Context, | ||||||
portID, | ||||||
channelID string, | ||||||
|
@@ -138,8 +141,8 @@ func (im IBCModule) OnChanOpenConfirm( | |||||
return im.app.OnChanOpenConfirm(ctx, portID, channelID) | ||||||
} | ||||||
|
||||||
// OnChanCloseInit implements the IBCModule interface | ||||||
func (im IBCModule) OnChanCloseInit( | ||||||
// OnChanCloseInit implements the IBCMiddleware interface | ||||||
func (im IBCMiddleware) OnChanCloseInit( | ||||||
ctx sdk.Context, | ||||||
portID, | ||||||
channelID string, | ||||||
|
@@ -166,8 +169,8 @@ func (im IBCModule) OnChanCloseInit( | |||||
return nil | ||||||
} | ||||||
|
||||||
// OnChanCloseConfirm implements the IBCModule interface | ||||||
func (im IBCModule) OnChanCloseConfirm( | ||||||
// OnChanCloseConfirm implements the IBCMiddleware interface | ||||||
func (im IBCMiddleware) OnChanCloseConfirm( | ||||||
ctx sdk.Context, | ||||||
portID, | ||||||
channelID string, | ||||||
|
@@ -189,9 +192,9 @@ func (im IBCModule) OnChanCloseConfirm( | |||||
return im.app.OnChanCloseConfirm(ctx, portID, channelID) | ||||||
} | ||||||
|
||||||
// OnRecvPacket implements the IBCModule interface. | ||||||
// OnRecvPacket implements the IBCMiddleware interface. | ||||||
// If fees are not enabled, this callback will default to the ibc-core packet callback | ||||||
func (im IBCModule) OnRecvPacket( | ||||||
func (im IBCMiddleware) OnRecvPacket( | ||||||
ctx sdk.Context, | ||||||
packet channeltypes.Packet, | ||||||
relayer sdk.AccAddress, | ||||||
|
@@ -214,9 +217,9 @@ func (im IBCModule) OnRecvPacket( | |||||
return types.NewIncentivizedAcknowledgement(forwardRelayer, ack.Acknowledgement(), ack.Success()) | ||||||
} | ||||||
|
||||||
// OnAcknowledgementPacket implements the IBCModule interface | ||||||
// OnAcknowledgementPacket implements the IBCMiddleware interface | ||||||
// If fees are not enabled, this callback will default to the ibc-core packet callback | ||||||
func (im IBCModule) OnAcknowledgementPacket( | ||||||
func (im IBCMiddleware) OnAcknowledgementPacket( | ||||||
ctx sdk.Context, | ||||||
packet channeltypes.Packet, | ||||||
acknowledgement []byte, | ||||||
|
@@ -244,9 +247,9 @@ func (im IBCModule) OnAcknowledgementPacket( | |||||
return im.app.OnAcknowledgementPacket(ctx, packet, ack.Result, relayer) | ||||||
} | ||||||
|
||||||
// OnTimeoutPacket implements the IBCModule interface | ||||||
// OnTimeoutPacket implements the IBCMiddleware interface | ||||||
// If fees are not enabled, this callback will default to the ibc-core packet callback | ||||||
func (im IBCModule) OnTimeoutPacket( | ||||||
func (im IBCMiddleware) OnTimeoutPacket( | ||||||
ctx sdk.Context, | ||||||
packet channeltypes.Packet, | ||||||
relayer sdk.AccAddress, | ||||||
|
@@ -267,3 +270,22 @@ func (im IBCModule) OnTimeoutPacket( | |||||
// call underlying callback | ||||||
return im.app.OnTimeoutPacket(ctx, packet, relayer) | ||||||
} | ||||||
|
||||||
// SendPacket implements the ICS4 Wrapper interface | ||||||
func (im IBCMiddleware) SendPacket( | ||||||
ctx sdk.Context, | ||||||
chanCap *capabilitytypes.Capability, | ||||||
packet exported.PacketI, | ||||||
) error { | ||||||
return im.keeper.SendPacket(ctx, chanCap, packet) | ||||||
} | ||||||
|
||||||
// WriteAcknowledgement implements the ICS4 Wrapper interface | ||||||
func (im IBCMiddleware) WriteAcknowledgement( | ||||||
ctx sdk.Context, | ||||||
chanCap *capabilitytypes.Capability, | ||||||
packet exported.PacketI, | ||||||
ack exported.Acknowledgement, | ||||||
) error { | ||||||
return im.keeper.WriteAcknowledgement(ctx, chanCap, packet, ack) | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
...callbacks for the
fee middleware
given...?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.
The next line continues the comment :)