Don't claim channel capability on crossing hellos (#7763)
* don't claim capability on crossing hellos * clarify comment
This commit is contained in:
parent
194d2aa196
commit
88e4acac6b
|
@ -159,6 +159,11 @@ func (k Keeper) IterateDenomTraces(ctx sdk.Context, cb func(denomTrace types.Den
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function
|
||||||
|
func (k Keeper) AuthenticateCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) bool {
|
||||||
|
return k.scopedKeeper.AuthenticateCapability(ctx, cap, name)
|
||||||
|
}
|
||||||
|
|
||||||
// ClaimCapability allows the transfer module that can claim a capability that IBC module
|
// ClaimCapability allows the transfer module that can claim a capability that IBC module
|
||||||
// passes to it
|
// passes to it
|
||||||
func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error {
|
func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error {
|
||||||
|
|
|
@ -245,9 +245,15 @@ func (am AppModule) OnChanOpenTry(
|
||||||
return sdkerrors.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: got: %s, expected %s", counterpartyVersion, types.Version)
|
return sdkerrors.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: got: %s, expected %s", counterpartyVersion, types.Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Claim channel capability passed back by IBC module
|
// Module may have already claimed capability in OnChanOpenInit in the case of crossing hellos
|
||||||
if err := am.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil {
|
// (ie chainA and chainB both call ChanOpenInit before one of them calls ChanOpenTry)
|
||||||
return err
|
// If module can already authenticate the capability then module already owns it so we don't need to claim
|
||||||
|
// Otherwise, module does not have channel capability and we must claim it from IBC
|
||||||
|
if !am.keeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) {
|
||||||
|
// Only claim channel capability passed back by IBC module if we do not already own it
|
||||||
|
if err := am.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -108,6 +108,12 @@ func (suite *TransferTestSuite) TestOnChanOpenTry() {
|
||||||
{
|
{
|
||||||
"success", func() {}, true,
|
"success", func() {}, true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"capability already claimed in INIT should pass", func() {
|
||||||
|
err := suite.chainA.App.ScopedTransferKeeper.ClaimCapability(suite.chainA.GetContext(), chanCap, host.ChannelCapabilityPath(testChannel.PortID, testChannel.ID))
|
||||||
|
suite.Require().NoError(err)
|
||||||
|
}, true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"invalid order - ORDERED", func() {
|
"invalid order - ORDERED", func() {
|
||||||
channel.Ordering = channeltypes.ORDERED
|
channel.Ordering = channeltypes.ORDERED
|
||||||
|
@ -128,12 +134,6 @@ func (suite *TransferTestSuite) TestOnChanOpenTry() {
|
||||||
counterpartyVersion = "version"
|
counterpartyVersion = "version"
|
||||||
}, false,
|
}, false,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"capability already claimed", func() {
|
|
||||||
err := suite.chainA.App.ScopedTransferKeeper.ClaimCapability(suite.chainA.GetContext(), chanCap, host.ChannelCapabilityPath(testChannel.PortID, testChannel.ID))
|
|
||||||
suite.Require().NoError(err)
|
|
||||||
}, false,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
|
Loading…
Reference in New Issue