Skip to content

Commit

Permalink
Do not do any additional checks in gmp module
Browse files Browse the repository at this point in the history
  • Loading branch information
luckychess committed Nov 28, 2024
1 parent 22a2a84 commit e1849e1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 40 deletions.
1 change: 0 additions & 1 deletion x/gmp/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) error {

// GetPort returns the portID for the IBC app module. Used in ExportGenesis
func (k Keeper) GetPort(ctx sdk.Context) string {
ctx.Logger().Info(fmt.Sprintf("store key: %+v, keeper: %p", k.storeKey, &k))
store := ctx.KVStore(k.storeKey)
return string(store.Get(types.PortKey))
}
Expand Down
65 changes: 31 additions & 34 deletions x/gmp/module_ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
host "github.com/cosmos/ibc-go/v8/modules/core/24-host"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/sagaxyz/ssc/x/gmp/keeper"
Expand Down Expand Up @@ -77,22 +76,20 @@ func (im IBCModule) OnChanOpenInit(
version string,
) (string, error) {

ctx.Logger().Info(fmt.Sprintf("ccontext: %+v", ctx))

// Require portID is the portID module is bound to
boundPort := im.keeper.GetPort(ctx)
if boundPort != portID {
return "", cosmossdkerrors.Wrapf(porttypes.ErrInvalidPort, "invalid port: %s, expected %s", portID, boundPort)
}
// boundPort := im.keeper.GetPort(ctx)
// if boundPort != portID {
// return "", cosmossdkerrors.Wrapf(porttypes.ErrInvalidPort, "invalid port: %s, expected %s", portID, boundPort)
// }

if version != types.Version {
return "", cosmossdkerrors.Wrapf(types.ErrInvalidVersion, "got %s, expected %s", version, types.Version)
}
// if version != types.Version {
// return "", cosmossdkerrors.Wrapf(types.ErrInvalidVersion, "got %s, expected %s", version, types.Version)
// }

// Claim channel capability passed back by IBC module
if err := im.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil {
return "", err
}
// // Claim channel capability passed back by IBC module
// if err := im.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil {
// return "", err
// }

return im.app.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, version)
}
Expand All @@ -110,25 +107,25 @@ func (im IBCModule) OnChanOpenTry(
) (string, error) {

// Require portID is the portID module is bound to
boundPort := im.keeper.GetPort(ctx)
if boundPort != portID {
return "", cosmossdkerrors.Wrapf(porttypes.ErrInvalidPort, "invalid port: %s, expected %s", portID, boundPort)
}
// boundPort := im.keeper.GetPort(ctx)
// if boundPort != portID {
// return "", cosmossdkerrors.Wrapf(porttypes.ErrInvalidPort, "invalid port: %s, expected %s", portID, boundPort)
// }

if counterpartyVersion != types.Version {
return "", cosmossdkerrors.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: got: %s, expected %s", counterpartyVersion, types.Version)
}
// if counterpartyVersion != types.Version {
// return "", cosmossdkerrors.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: got: %s, expected %s", counterpartyVersion, types.Version)
// }

// Module may have already claimed capability in OnChanOpenInit in the case of crossing hellos
// (ie chainA and chainB both call ChanOpenInit before one of them calls ChanOpenTry)
// 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 !im.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 := im.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil {
return "", err
}
}
// // Module may have already claimed capability in OnChanOpenInit in the case of crossing hellos
// // (ie chainA and chainB both call ChanOpenInit before one of them calls ChanOpenTry)
// // 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 !im.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 := im.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil {
// return "", err
// }
// }

return im.app.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, counterpartyVersion)
}
Expand All @@ -141,9 +138,9 @@ func (im IBCModule) OnChanOpenAck(
counterpartyChannelID string,
counterpartyVersion string,
) error {
if counterpartyVersion != types.Version {
return cosmossdkerrors.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: %s, expected %s", counterpartyVersion, types.Version)
}
// if counterpartyVersion != types.Version {
// return cosmossdkerrors.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: %s, expected %s", counterpartyVersion, types.Version)
// }
return im.app.OnChanOpenAck(ctx, portID, channelID, counterpartyChannelID, counterpartyVersion)
}

Expand Down
10 changes: 5 additions & 5 deletions x/gmp/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const (
// MemStoreKey defines the in-memory store key
MemStoreKey = "mem_gmp"

// Version defines the current version the IBC module supports
Version = "gmp-1"
// Version defines the current version the IBC module supports
Version = "gmp-1"

// PortID is the default port id that module binds to
PortID = "gmp"
// PortID is the default port id that module binds to
PortID = "gmp"
)

var (
Expand All @@ -26,5 +26,5 @@ var (
)

func KeyPrefix(p string) []byte {
return []byte(p)
return []byte(p)
}

0 comments on commit e1849e1

Please sign in to comment.