Skip to content

Commit

Permalink
address @cwgoes comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaSripal committed Mar 31, 2020
1 parent ff0dbef commit 8086e42
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
13 changes: 9 additions & 4 deletions x/ibc/04-channel/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,16 @@ func (k Keeper) LookupModuleByChannel(ctx sdk.Context, portID, channelID string)
return "", nil, false
}
if len(capOwners.Owners) < 2 {
return "", nil, false
panic("more than one module has bound to this port; currently not supported")
}
// the module that owns the channel, for now, is the only module owner that isn't "ibc"
var module string
if capOwners.Owners[0].Module == "ibc" {
module = capOwners.Owners[1].Module
} else {
module = capOwners.Owners[0].Module
}
// the module that owns the channel, for now, is the first module that isn't "ibc"
// that owns the module
module := capOwners.Owners[1].Module

cap, _ := k.scopedKeeper.GetCapability(ctx, ibctypes.ChannelCapabilityPath(portID, channelID))
return module, cap, true

Expand Down
23 changes: 13 additions & 10 deletions x/ibc/05-port/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ import (
// Keeper defines the IBC connection keeper
type Keeper struct {
scopedKeeper capability.ScopedKeeper
router map[string]types.IBCModule
}

// NewKeeper creates a new IBC connection Keeper instance
func NewKeeper(sck capability.ScopedKeeper) Keeper {
return Keeper{
scopedKeeper: sck,
router: make(map[string]types.IBCModule),
}
}

Expand All @@ -33,7 +31,7 @@ func (k Keeper) isBounded(ctx sdk.Context, portID string) bool {
// Ports must be bound statically when the chain starts in `app.go`.
// The capability must then be passed to a module which will need to pass
// it as an extra parameter when calling functions on the IBC module.
func (k *Keeper) BindPort(ctx sdk.Context, portID string, cbs types.IBCModule) capability.Capability {
func (k *Keeper) BindPort(ctx sdk.Context, portID string) capability.Capability {
if err := host.DefaultPortIdentifierValidator(portID); err != nil {
panic(err.Error())
}
Expand All @@ -47,8 +45,6 @@ func (k *Keeper) BindPort(ctx sdk.Context, portID string, cbs types.IBCModule) c
panic(err.Error())
}

k.router[portID] = cbs

return key
}

Expand All @@ -70,12 +66,19 @@ func (k Keeper) LookupModuleByPort(ctx sdk.Context, portID string) (string, capa
if !ok {
return "", nil, false
}
if len(capOwners.Owners) < 2 {
return "", nil, false
// For now, we enforce that only IBC and the module bound to port can own the capability
// while future implementations may allow multiple modules to bind to a port, currently we
// only allow one module to be bound to a port at any given time
if len(capOwners.Owners) != 2 {
panic("more than one module has bound to this port; currently not supported")
}
// the module that owns the port, for now, is the only module owner that isn't "ibc"
var module string
if capOwners.Owners[0].Module == "ibc" {
module = capOwners.Owners[1].Module
} else {
module = capOwners.Owners[0].Module
}
// the module that owns the port, for now, is the first module that isn't "ibc"
// that owns the module
module := capOwners.Owners[1].Module
cap, _ := k.scopedKeeper.GetCapability(ctx, types.PortPath(portID))
return module, cap, true
}
4 changes: 2 additions & 2 deletions x/ibc/05-port/types/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type IBCModule interface {
connectionHops []string,
portID string,
channelID string,
chanCap capability.Capability,
channelCap capability.Capability,
counterParty channeltypes.Counterparty,
version string,
) error
Expand All @@ -26,7 +26,7 @@ type IBCModule interface {
connectionHops []string,
portID,
channelID string,
portCap capability.Capability,
channelCap capability.Capability,
counterparty channeltypes.Counterparty,
version,
counterpartyVersion string,
Expand Down

0 comments on commit 8086e42

Please sign in to comment.