Skip to content
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

Bind Transfer Port on InitChain #5954

Merged
merged 9 commits into from
Apr 8, 2020
4 changes: 3 additions & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ func NewSimApp(
// Create Transfer Keepers
app.TransferKeeper = transfer.NewKeeper(
app.cdc, keys[transfer.StoreKey],
app.IBCKeeper.ChannelKeeper, app.BankKeeper, app.SupplyKeeper,
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.BankKeeper, app.SupplyKeeper,
scopedTransferKeeper,
)
transferModule := transfer.NewAppModule(app.TransferKeeper)
Expand Down Expand Up @@ -289,6 +290,7 @@ func NewSimApp(
auth.ModuleName, distr.ModuleName, staking.ModuleName, bank.ModuleName,
slashing.ModuleName, gov.ModuleName, mint.ModuleName, supply.ModuleName,
crisis.ModuleName, ibc.ModuleName, genutil.ModuleName, evidence.ModuleName,
transfer.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down
4 changes: 0 additions & 4 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,6 @@ func (m *Manager) RegisterRoutes(router sdk.Router, queryRouter sdk.QueryRouter)
func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, genesisData map[string]json.RawMessage) abci.ResponseInitChain {
var validatorUpdates []abci.ValidatorUpdate
for _, moduleName := range m.OrderInitGenesis {
if genesisData[moduleName] == nil {
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
continue
}

moduleValUpdates := m.Modules[moduleName].InitGenesis(ctx, cdc, genesisData[moduleName])

// use these validator updates if provided, the module manager assumes
Expand Down
6 changes: 6 additions & 0 deletions x/ibc/20-transfer/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import (

// InitGenesis sets distribution information for genesis
func InitGenesis(ctx sdk.Context, keeper Keeper) {
// transfer module binds to the transfer port on InitChain
// and claims the returned capability
err := keeper.BindPort(ctx, types.PortID)
if err != nil {
panic(fmt.Sprintf("could not claim port capability: %v", err))
}
// check if the module account exists
moduleAcc := keeper.GetTransferAccount(ctx)
if moduleAcc == nil {
Expand Down
22 changes: 17 additions & 5 deletions x/ibc/20-transfer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/capability"
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
porttypes "github.com/cosmos/cosmos-sdk/x/ibc/05-port/types"
"github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported"
Expand All @@ -26,16 +27,19 @@ type Keeper struct {
storeKey sdk.StoreKey
cdc *codec.Codec

channelKeeper types.ChannelKeeper
bankKeeper types.BankKeeper
supplyKeeper types.SupplyKeeper
scopedKeeper capability.ScopedKeeper
clientKeeper types.ClientKeeper
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
connectionKeeper types.ConnectionKeeper
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
channelKeeper types.ChannelKeeper
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File is not gofmt-ed with -s (from gofmt)

portKeeper types.PortKeeper
bankKeeper types.BankKeeper
supplyKeeper types.SupplyKeeper
scopedKeeper capability.ScopedKeeper
}

// NewKeeper creates a new IBC transfer Keeper instance
func NewKeeper(
cdc *codec.Codec, key sdk.StoreKey,
channelKeeper types.ChannelKeeper,
channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper,
bankKeeper types.BankKeeper, supplyKeeper types.SupplyKeeper,
scopedKeeper capability.ScopedKeeper,
) Keeper {
Expand All @@ -49,6 +53,7 @@ func NewKeeper(
storeKey: key,
cdc: cdc,
channelKeeper: channelKeeper,
portKeeper: portKeeper,
bankKeeper: bankKeeper,
supplyKeeper: supplyKeeper,
scopedKeeper: scopedKeeper,
Expand Down Expand Up @@ -82,6 +87,13 @@ func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string) error {
return k.channelKeeper.ChanCloseInit(ctx, portID, channelID, chanCap)
}

// BindPort defines a wrapper function for the ort Keeper's function in
// order to expose it to module's InitGenesis function
func (k Keeper) BindPort(ctx sdk.Context, portID string) error {
cap := k.portKeeper.BindPort(ctx, portID)
return k.ClaimCapability(ctx, cap, porttypes.PortPath(portID))
}

// TimeoutExecuted defines a wrapper function for the channel Keeper's function
// in order to expose it to the ICS20 transfer handler.
func (k Keeper) TimeoutExecuted(ctx sdk.Context, packet channelexported.PacketI) error {
Expand Down
5 changes: 5 additions & 0 deletions x/ibc/20-transfer/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ type ConnectionKeeper interface {
GetConnection(ctx sdk.Context, connectionID string) (connection connection.ConnectionEnd, found bool)
}

// PortKeeper defines the expected IBC port keeper
type PortKeeper interface {
BindPort(ctx sdk.Context, portID string) *capability.Capability
}

// SupplyKeeper expected supply keeper
type SupplyKeeper interface {
GetModuleAddress(name string) sdk.AccAddress
Expand Down