-
Notifications
You must be signed in to change notification settings - Fork 606
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
Changes from 19 commits
227f47b
725936f
700ad6a
5852bdf
94f3e23
e0e405e
fd2360f
2793d73
b419f8f
4a60ff6
2aa1f8c
31c3f93
40fbdcc
68f4843
6624b73
611c5db
5898bfc
80816aa
112d1c1
ac937cb
80de572
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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{} | ||
|
||
// IBCMiddleware implements the ICS26 callbacks for the fee middleware given the | ||
// 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{ | ||
keeper: k, | ||
// IBCMiddleware creates a new IBCMiddleware given the associated keeper and underlying application | ||
func NewIBCMiddleware(app porttypes.IBCModule, k keeper.Keeper) IBCMiddleware { | ||
return IBCMiddleware{ | ||
app: app, | ||
keeper: k, | ||
} | ||
} | ||
|
||
// 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, | ||
|
@@ -164,7 +168,27 @@ func (im IBCModule) OnTimeoutPacket( | |
return im.app.OnTimeoutPacket(ctx, packet, relayer) | ||
} | ||
|
||
// SendPacket implements the ICS4 Wrapper interface | ||
// The ICA controller module builds the outgoing ICA packet and calls the core IBC SendPacket | ||
func (im IBCMiddleware) SendPacket( | ||
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. Ok I understand now why you've done it this way. I think it should be documented in this function's go-doc that the packet is going to get constructed directly by ICA controller and sent to IBC rather than being created by ICA-auth. Reading this file, made me think SendPacket wasn't happening at all when really it is happening through the controller's SendTx function |
||
ctx sdk.Context, | ||
chanCap *capabilitytypes.Capability, | ||
packet exported.PacketI, | ||
) error { | ||
panic("SendPacket not supported for ICA-auth module. Please use SendTx") | ||
} | ||
|
||
// WriteAcknowledgement implements the ICS4 Wrapper interface | ||
func (im IBCMiddleware) WriteAcknowledgement( | ||
ctx sdk.Context, | ||
chanCap *capabilitytypes.Capability, | ||
packet ibcexported.PacketI, | ||
ack ibcexported.Acknowledgement, | ||
) error { | ||
panic("WriteAcknowledgement not supported for ICA controller module") | ||
} | ||
|
||
// GetAppVersion returns the interchain accounts metadata. | ||
func (im IBCModule) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) { | ||
func (im IBCMiddleware) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) { | ||
return im.keeper.GetAppVersion(ctx, portID, channelID) | ||
} |
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 is imported twice
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.
we should add a linter for 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.
duplicate import is still there