Skip to content

Commit a2c044e

Browse files
authored
Merge branch 'main' into add-empty-keepers-checking
2 parents 1241476 + cc4cd7b commit a2c044e

File tree

9 files changed

+194
-105
lines changed

9 files changed

+194
-105
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module github.com/cosmos/ibc-go/v3
55
replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
66

77
require (
8-
github.com/armon/go-metrics v0.3.10
8+
github.com/armon/go-metrics v0.3.11
99
github.com/confio/ics23/go v0.7.0
1010
github.com/cosmos/cosmos-sdk v0.45.3
1111
github.com/gogo/protobuf v1.3.3

go.sum

+2-1
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hC
128128
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
129129
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
130130
github.com/armon/go-metrics v0.3.9/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=
131-
github.com/armon/go-metrics v0.3.10 h1:FR+drcQStOe+32sYyJYyZ7FIdgoGGBnwLl+flodp8Uo=
132131
github.com/armon/go-metrics v0.3.10/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=
132+
github.com/armon/go-metrics v0.3.11 h1:/q4zqTAH+/mtFjimfc0SC7yuuxZshlS4TaCeBm+7sZ0=
133+
github.com/armon/go-metrics v0.3.11/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=
133134
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
134135
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
135136
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=

modules/apps/27-interchain-accounts/controller/ibc_module.go modules/apps/27-interchain-accounts/controller/ibc_middleware.go

+49-26
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,30 @@ import (
1313
ibcexported "github.com/cosmos/ibc-go/v3/modules/core/exported"
1414
)
1515

16-
// IBCModule implements the ICS26 interface for interchain accounts controller chains
17-
type IBCModule struct {
18-
keeper keeper.Keeper
16+
var _ porttypes.Middleware = &IBCMiddleware{}
17+
18+
// IBCMiddleware implements the ICS26 callbacks for the fee middleware given the
19+
// ICA controller keeper and the underlying application.
20+
type IBCMiddleware struct {
1921
app porttypes.IBCModule
22+
keeper keeper.Keeper
2023
}
2124

22-
// NewIBCModule creates a new IBCModule given the associated keeper and underlying application
23-
func NewIBCModule(k keeper.Keeper, app porttypes.IBCModule) IBCModule {
24-
return IBCModule{
25-
keeper: k,
25+
// IBCMiddleware creates a new IBCMiddleware given the associated keeper and underlying application
26+
func NewIBCMiddleware(app porttypes.IBCModule, k keeper.Keeper) IBCMiddleware {
27+
return IBCMiddleware{
2628
app: app,
29+
keeper: k,
2730
}
2831
}
2932

30-
// OnChanOpenInit implements the IBCModule interface
33+
// OnChanOpenInit implements the IBCMiddleware interface
3134
//
3235
// Interchain Accounts is implemented to act as middleware for connected authentication modules on
3336
// the controller side. The connected modules may not change the controller side portID or
3437
// version. They will be allowed to perform custom logic without changing
3538
// the parameters stored within a channel struct.
36-
func (im IBCModule) OnChanOpenInit(
39+
func (im IBCMiddleware) OnChanOpenInit(
3740
ctx sdk.Context,
3841
order channeltypes.Order,
3942
connectionHops []string,
@@ -56,8 +59,8 @@ func (im IBCModule) OnChanOpenInit(
5659
chanCap, counterparty, version)
5760
}
5861

59-
// OnChanOpenTry implements the IBCModule interface
60-
func (im IBCModule) OnChanOpenTry(
62+
// OnChanOpenTry implements the IBCMiddleware interface
63+
func (im IBCMiddleware) OnChanOpenTry(
6164
ctx sdk.Context,
6265
order channeltypes.Order,
6366
connectionHops []string,
@@ -70,13 +73,13 @@ func (im IBCModule) OnChanOpenTry(
7073
return "", sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain")
7174
}
7275

73-
// OnChanOpenAck implements the IBCModule interface
76+
// OnChanOpenAck implements the IBCMiddleware interface
7477
//
7578
// Interchain Accounts is implemented to act as middleware for connected authentication modules on
7679
// the controller side. The connected modules may not change the portID or
7780
// version. They will be allowed to perform custom logic without changing
7881
// the parameters stored within a channel struct.
79-
func (im IBCModule) OnChanOpenAck(
82+
func (im IBCMiddleware) OnChanOpenAck(
8083
ctx sdk.Context,
8184
portID,
8285
channelID string,
@@ -95,17 +98,17 @@ func (im IBCModule) OnChanOpenAck(
9598
return im.app.OnChanOpenAck(ctx, portID, channelID, counterpartyChannelID, counterpartyVersion)
9699
}
97100

98-
// OnChanOpenAck implements the IBCModule interface
99-
func (im IBCModule) OnChanOpenConfirm(
101+
// OnChanOpenAck implements the IBCMiddleware interface
102+
func (im IBCMiddleware) OnChanOpenConfirm(
100103
ctx sdk.Context,
101104
portID,
102105
channelID string,
103106
) error {
104107
return sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain")
105108
}
106109

107-
// OnChanCloseInit implements the IBCModule interface
108-
func (im IBCModule) OnChanCloseInit(
110+
// OnChanCloseInit implements the IBCMiddleware interface
111+
func (im IBCMiddleware) OnChanCloseInit(
109112
ctx sdk.Context,
110113
portID,
111114
channelID string,
@@ -114,26 +117,26 @@ func (im IBCModule) OnChanCloseInit(
114117
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel")
115118
}
116119

117-
// OnChanCloseConfirm implements the IBCModule interface
118-
func (im IBCModule) OnChanCloseConfirm(
120+
// OnChanCloseConfirm implements the IBCMiddleware interface
121+
func (im IBCMiddleware) OnChanCloseConfirm(
119122
ctx sdk.Context,
120123
portID,
121124
channelID string,
122125
) error {
123126
return im.keeper.OnChanCloseConfirm(ctx, portID, channelID)
124127
}
125128

126-
// OnRecvPacket implements the IBCModule interface
127-
func (im IBCModule) OnRecvPacket(
129+
// OnRecvPacket implements the IBCMiddleware interface
130+
func (im IBCMiddleware) OnRecvPacket(
128131
ctx sdk.Context,
129132
packet channeltypes.Packet,
130133
_ sdk.AccAddress,
131134
) ibcexported.Acknowledgement {
132135
return channeltypes.NewErrorAcknowledgement("cannot receive packet on controller chain")
133136
}
134137

135-
// OnAcknowledgementPacket implements the IBCModule interface
136-
func (im IBCModule) OnAcknowledgementPacket(
138+
// OnAcknowledgementPacket implements the IBCMiddleware interface
139+
func (im IBCMiddleware) OnAcknowledgementPacket(
137140
ctx sdk.Context,
138141
packet channeltypes.Packet,
139142
acknowledgement []byte,
@@ -147,8 +150,8 @@ func (im IBCModule) OnAcknowledgementPacket(
147150
return im.app.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer)
148151
}
149152

150-
// OnTimeoutPacket implements the IBCModule interface
151-
func (im IBCModule) OnTimeoutPacket(
153+
// OnTimeoutPacket implements the IBCMiddleware interface
154+
func (im IBCMiddleware) OnTimeoutPacket(
152155
ctx sdk.Context,
153156
packet channeltypes.Packet,
154157
relayer sdk.AccAddress,
@@ -164,7 +167,27 @@ func (im IBCModule) OnTimeoutPacket(
164167
return im.app.OnTimeoutPacket(ctx, packet, relayer)
165168
}
166169

170+
// SendPacket implements the ICS4 Wrapper interface
171+
// The ICA controller module builds the outgoing ICA packet and calls the core IBC SendPacket
172+
func (im IBCMiddleware) SendPacket(
173+
ctx sdk.Context,
174+
chanCap *capabilitytypes.Capability,
175+
packet ibcexported.PacketI,
176+
) error {
177+
panic("SendPacket not supported for ICA-auth module. Please use SendTx")
178+
}
179+
180+
// WriteAcknowledgement implements the ICS4 Wrapper interface
181+
func (im IBCMiddleware) WriteAcknowledgement(
182+
ctx sdk.Context,
183+
chanCap *capabilitytypes.Capability,
184+
packet ibcexported.PacketI,
185+
ack ibcexported.Acknowledgement,
186+
) error {
187+
panic("WriteAcknowledgement not supported for ICA controller module")
188+
}
189+
167190
// GetAppVersion returns the interchain accounts metadata.
168-
func (im IBCModule) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) {
191+
func (im IBCMiddleware) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) {
169192
return im.keeper.GetAppVersion(ctx, portID, channelID)
170193
}

modules/apps/27-interchain-accounts/controller/ibc_module_test.go modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ func (suite *InterchainAccountsTestSuite) TestGetAppVersion() {
717717
cbs, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module)
718718
suite.Require().True(ok)
719719

720-
controllerModule := cbs.(icacontroller.IBCModule)
720+
controllerModule := cbs.(icacontroller.IBCMiddleware)
721721

722722
appVersion, found := controllerModule.GetAppVersion(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
723723
suite.Require().True(found)

modules/apps/27-interchain-accounts/module.go

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
abci "github.com/tendermint/tendermint/abci/types"
1717

1818
"github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/client/cli"
19-
"github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller"
2019
controllerkeeper "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/keeper"
2120
controllertypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types"
2221
"github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host"
@@ -31,7 +30,6 @@ var (
3130
_ module.AppModule = AppModule{}
3231
_ module.AppModuleBasic = AppModuleBasic{}
3332

34-
_ porttypes.IBCModule = controller.IBCModule{}
3533
_ porttypes.IBCModule = host.IBCModule{}
3634
)
3735

modules/apps/29-fee/ibc_module.go modules/apps/29-fee/ibc_middleware.go

+48-26
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,25 @@ import (
1212
"github.com/cosmos/ibc-go/v3/modules/core/exported"
1313
)
1414

15-
// IBCModule implements the ICS26 callbacks for the fee middleware given the fee keeper and the underlying application.
16-
type IBCModule struct {
17-
keeper keeper.Keeper
15+
var _ porttypes.Middleware = &IBCMiddleware{}
16+
17+
// IBCMiddleware implements the ICS26 callbacks for the fee middleware given the
18+
// fee keeper and the underlying application.
19+
type IBCMiddleware struct {
1820
app porttypes.IBCModule
21+
keeper keeper.Keeper
1922
}
2023

21-
// NewIBCModule creates a new IBCModule given the keeper and underlying application
22-
func NewIBCModule(k keeper.Keeper, app porttypes.IBCModule) IBCModule {
23-
return IBCModule{
24-
keeper: k,
24+
// NewIBCMiddleware creates a new IBCMiddlware given the keeper and underlying application
25+
func NewIBCMiddleware(app porttypes.IBCModule, k keeper.Keeper) IBCMiddleware {
26+
return IBCMiddleware{
2527
app: app,
28+
keeper: k,
2629
}
2730
}
2831

29-
// OnChanOpenInit implements the IBCModule interface
30-
func (im IBCModule) OnChanOpenInit(
32+
// OnChanOpenInit implements the IBCMiddleware interface
33+
func (im IBCMiddleware) OnChanOpenInit(
3134
ctx sdk.Context,
3235
order channeltypes.Order,
3336
connectionHops []string,
@@ -57,10 +60,10 @@ func (im IBCModule) OnChanOpenInit(
5760
chanCap, counterparty, versionMetadata.AppVersion)
5861
}
5962

60-
// OnChanOpenTry implements the IBCModule interface
63+
// OnChanOpenTry implements the IBCMiddleware interface
6164
// If the channel is not fee enabled the underlying application version will be returned
6265
// If the channel is fee enabled we merge the underlying application version with the ics29 version
63-
func (im IBCModule) OnChanOpenTry(
66+
func (im IBCMiddleware) OnChanOpenTry(
6467
ctx sdk.Context,
6568
order channeltypes.Order,
6669
connectionHops []string,
@@ -100,8 +103,8 @@ func (im IBCModule) OnChanOpenTry(
100103
return string(versionBytes), nil
101104
}
102105

103-
// OnChanOpenAck implements the IBCModule interface
104-
func (im IBCModule) OnChanOpenAck(
106+
// OnChanOpenAck implements the IBCMiddleware interface
107+
func (im IBCMiddleware) OnChanOpenAck(
105108
ctx sdk.Context,
106109
portID,
107110
channelID string,
@@ -128,8 +131,8 @@ func (im IBCModule) OnChanOpenAck(
128131
return im.app.OnChanOpenAck(ctx, portID, channelID, counterpartyChannelID, counterpartyVersion)
129132
}
130133

131-
// OnChanOpenConfirm implements the IBCModule interface
132-
func (im IBCModule) OnChanOpenConfirm(
134+
// OnChanOpenConfirm implements the IBCMiddleware interface
135+
func (im IBCMiddleware) OnChanOpenConfirm(
133136
ctx sdk.Context,
134137
portID,
135138
channelID string,
@@ -138,8 +141,8 @@ func (im IBCModule) OnChanOpenConfirm(
138141
return im.app.OnChanOpenConfirm(ctx, portID, channelID)
139142
}
140143

141-
// OnChanCloseInit implements the IBCModule interface
142-
func (im IBCModule) OnChanCloseInit(
144+
// OnChanCloseInit implements the IBCMiddleware interface
145+
func (im IBCMiddleware) OnChanCloseInit(
143146
ctx sdk.Context,
144147
portID,
145148
channelID string,
@@ -155,8 +158,8 @@ func (im IBCModule) OnChanCloseInit(
155158
return nil
156159
}
157160

158-
// OnChanCloseConfirm implements the IBCModule interface
159-
func (im IBCModule) OnChanCloseConfirm(
161+
// OnChanCloseConfirm implements the IBCMiddleware interface
162+
func (im IBCMiddleware) OnChanCloseConfirm(
160163
ctx sdk.Context,
161164
portID,
162165
channelID string,
@@ -172,9 +175,9 @@ func (im IBCModule) OnChanCloseConfirm(
172175
return nil
173176
}
174177

175-
// OnRecvPacket implements the IBCModule interface.
178+
// OnRecvPacket implements the IBCMiddleware interface.
176179
// If fees are not enabled, this callback will default to the ibc-core packet callback
177-
func (im IBCModule) OnRecvPacket(
180+
func (im IBCMiddleware) OnRecvPacket(
178181
ctx sdk.Context,
179182
packet channeltypes.Packet,
180183
relayer sdk.AccAddress,
@@ -197,9 +200,9 @@ func (im IBCModule) OnRecvPacket(
197200
return types.NewIncentivizedAcknowledgement(forwardRelayer, ack.Acknowledgement(), ack.Success())
198201
}
199202

200-
// OnAcknowledgementPacket implements the IBCModule interface
203+
// OnAcknowledgementPacket implements the IBCMiddleware interface
201204
// If fees are not enabled, this callback will default to the ibc-core packet callback
202-
func (im IBCModule) OnAcknowledgementPacket(
205+
func (im IBCMiddleware) OnAcknowledgementPacket(
203206
ctx sdk.Context,
204207
packet channeltypes.Packet,
205208
acknowledgement []byte,
@@ -239,9 +242,9 @@ func (im IBCModule) OnAcknowledgementPacket(
239242
return im.app.OnAcknowledgementPacket(ctx, packet, ack.Result, relayer)
240243
}
241244

242-
// OnTimeoutPacket implements the IBCModule interface
245+
// OnTimeoutPacket implements the IBCMiddleware interface
243246
// If fees are not enabled, this callback will default to the ibc-core packet callback
244-
func (im IBCModule) OnTimeoutPacket(
247+
func (im IBCMiddleware) OnTimeoutPacket(
245248
ctx sdk.Context,
246249
packet channeltypes.Packet,
247250
relayer sdk.AccAddress,
@@ -268,7 +271,26 @@ func (im IBCModule) OnTimeoutPacket(
268271
return im.app.OnTimeoutPacket(ctx, packet, relayer)
269272
}
270273

274+
// SendPacket implements the ICS4 Wrapper interface
275+
func (im IBCMiddleware) SendPacket(
276+
ctx sdk.Context,
277+
chanCap *capabilitytypes.Capability,
278+
packet exported.PacketI,
279+
) error {
280+
return im.keeper.SendPacket(ctx, chanCap, packet)
281+
}
282+
283+
// WriteAcknowledgement implements the ICS4 Wrapper interface
284+
func (im IBCMiddleware) WriteAcknowledgement(
285+
ctx sdk.Context,
286+
chanCap *capabilitytypes.Capability,
287+
packet exported.PacketI,
288+
ack exported.Acknowledgement,
289+
) error {
290+
return im.keeper.WriteAcknowledgement(ctx, chanCap, packet, ack)
291+
}
292+
271293
// GetAppVersion returns the application version of the underlying application
272-
func (im IBCModule) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) {
294+
func (im IBCMiddleware) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) {
273295
return im.keeper.GetAppVersion(ctx, portID, channelID)
274296
}

modules/apps/29-fee/ibc_module_test.go modules/apps/29-fee/ibc_middleware_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ func (suite *FeeTestSuite) TestGetAppVersion() {
896896
cbs, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module)
897897
suite.Require().True(ok)
898898

899-
feeModule := cbs.(fee.IBCModule)
899+
feeModule := cbs.(fee.IBCMiddleware)
900900

901901
appVersion, found := feeModule.GetAppVersion(suite.chainA.GetContext(), portID, channelID)
902902

modules/apps/29-fee/module.go

-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ import (
2020
"github.com/cosmos/ibc-go/v3/modules/apps/29-fee/client/cli"
2121
"github.com/cosmos/ibc-go/v3/modules/apps/29-fee/keeper"
2222
"github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types"
23-
porttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types"
2423
)
2524

2625
var (
2726
_ module.AppModule = AppModule{}
28-
_ porttypes.IBCModule = IBCModule{}
2927
_ module.AppModuleBasic = AppModuleBasic{}
3028
)
3129

0 commit comments

Comments
 (0)