Skip to content

Commit

Permalink
chore: ica submodules minor improvements and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan authored Nov 19, 2021
1 parent 7efc384 commit b87b806
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state types.ControllerGenesisSt
}

// ExportGenesis returns the interchain accounts controller exported genesis
func ExportGenesis(ctx sdk.Context, keeper Keeper) *types.ControllerGenesisState {
func ExportGenesis(ctx sdk.Context, keeper Keeper) types.ControllerGenesisState {
return types.NewControllerGenesisState(
keeper.GetAllActiveChannels(ctx),
keeper.GetAllInterchainAccounts(ctx),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ func (suite *KeeperTestSuite) TestInitGenesis() {
suite.SetupTest()

genesisState := types.ControllerGenesisState{
ActiveChannels: []*types.ActiveChannel{
ActiveChannels: []types.ActiveChannel{
{
PortId: TestPortID,
ChannelId: ibctesting.FirstChannelID,
},
},
InterchainAccounts: []*types.RegisteredInterchainAccount{
InterchainAccounts: []types.RegisteredInterchainAccount{
{
PortId: TestPortID,
AccountAddress: TestAccAddress.String(),
Expand Down
12 changes: 6 additions & 6 deletions modules/apps/27-interchain-accounts/controller/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,16 @@ func (k Keeper) GetActiveChannelID(ctx sdk.Context, portID string) (string, bool
}

// GetAllActiveChannels returns a list of all active interchain accounts controller channels and their associated port identifiers
func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []*types.ActiveChannel {
func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []types.ActiveChannel {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(types.ActiveChannelKeyPrefix))
defer iterator.Close()

var activeChannels []*types.ActiveChannel
var activeChannels []types.ActiveChannel
for ; iterator.Valid(); iterator.Next() {
keySplit := strings.Split(string(iterator.Key()), "/")

ch := &types.ActiveChannel{
ch := types.ActiveChannel{
PortId: keySplit[1],
ChannelId: string(iterator.Value()),
}
Expand Down Expand Up @@ -189,15 +189,15 @@ func (k Keeper) GetInterchainAccountAddress(ctx sdk.Context, portID string) (str
}

// GetAllInterchainAccounts returns a list of all registered interchain account addresses and their associated controller port identifiers
func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []*types.RegisteredInterchainAccount {
func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []types.RegisteredInterchainAccount {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(types.OwnerKeyPrefix))

var interchainAccounts []*types.RegisteredInterchainAccount
var interchainAccounts []types.RegisteredInterchainAccount
for ; iterator.Valid(); iterator.Next() {
keySplit := strings.Split(string(iterator.Key()), "/")

acc := &types.RegisteredInterchainAccount{
acc := types.RegisteredInterchainAccount{
PortId: keySplit[1],
AccountAddress: string(iterator.Value()),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (suite *KeeperTestSuite) TestGetAllActiveChannels() {

suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), expectedPortID, expectedChannelID)

expectedChannels := []*types.ActiveChannel{
expectedChannels := []types.ActiveChannel{
{
PortId: TestPortID,
ChannelId: path.EndpointA.ChannelID,
Expand Down Expand Up @@ -202,7 +202,7 @@ func (suite *KeeperTestSuite) TestGetAllInterchainAccounts() {

suite.chainA.GetSimApp().ICAControllerKeeper.SetInterchainAccountAddress(suite.chainA.GetContext(), expectedPortID, expectedAccAddr)

expectedAccounts := []*types.RegisteredInterchainAccount{
expectedAccounts := []types.RegisteredInterchainAccount{
{
PortId: TestPortID,
AccountAddress: TestAccAddress.String(),
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/27-interchain-accounts/host/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state types.HostGenesisState) {
}

// ExportGenesis returns the interchain accounts host exported genesis
func ExportGenesis(ctx sdk.Context, keeper Keeper) *types.HostGenesisState {
func ExportGenesis(ctx sdk.Context, keeper Keeper) types.HostGenesisState {
return types.NewHostGenesisState(
keeper.GetAllActiveChannels(ctx),
keeper.GetAllInterchainAccounts(ctx),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ func (suite *KeeperTestSuite) TestInitGenesis() {
suite.SetupTest()

genesisState := types.HostGenesisState{
ActiveChannels: []*types.ActiveChannel{
ActiveChannels: []types.ActiveChannel{
{
PortId: TestPortID,
ChannelId: ibctesting.FirstChannelID,
},
},
InterchainAccounts: []*types.RegisteredInterchainAccount{
InterchainAccounts: []types.RegisteredInterchainAccount{
{
PortId: TestPortID,
AccountAddress: TestAccAddress.String(),
Expand Down
28 changes: 6 additions & 22 deletions modules/apps/27-interchain-accounts/host/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,6 @@ func (k Keeper) RegisterInterchainAccount(ctx sdk.Context, accAddr sdk.AccAddres
k.SetInterchainAccountAddress(ctx, controllerPortID, interchainAccount.Address)
}

// GetAllPorts returns all ports to which the interchain accounts host module is bound. Used in ExportGenesis
func (k Keeper) GetAllPorts(ctx sdk.Context) []string {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(types.PortKeyPrefix))
defer iterator.Close()

var ports []string
for ; iterator.Valid(); iterator.Next() {
keySplit := strings.Split(string(iterator.Key()), "/")

ports = append(ports, keySplit[1])
}

return ports
}

// BindPort stores the provided portID and binds to it, returning the associated capability
func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability {
store := ctx.KVStore(k.storeKey)
Expand Down Expand Up @@ -129,16 +113,16 @@ func (k Keeper) GetActiveChannelID(ctx sdk.Context, portID string) (string, bool
}

// GetAllActiveChannels returns a list of all active interchain accounts host channels and their associated port identifiers
func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []*types.ActiveChannel {
func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []types.ActiveChannel {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(types.ActiveChannelKeyPrefix))
defer iterator.Close()

var activeChannels []*types.ActiveChannel
var activeChannels []types.ActiveChannel
for ; iterator.Valid(); iterator.Next() {
keySplit := strings.Split(string(iterator.Key()), "/")

ch := &types.ActiveChannel{
ch := types.ActiveChannel{
PortId: keySplit[1],
ChannelId: string(iterator.Value()),
}
Expand Down Expand Up @@ -180,15 +164,15 @@ func (k Keeper) GetInterchainAccountAddress(ctx sdk.Context, portID string) (str
}

// GetAllInterchainAccounts returns a list of all registered interchain account addresses and their associated controller port identifiers
func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []*types.RegisteredInterchainAccount {
func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []types.RegisteredInterchainAccount {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(types.OwnerKeyPrefix))

var interchainAccounts []*types.RegisteredInterchainAccount
var interchainAccounts []types.RegisteredInterchainAccount
for ; iterator.Valid(); iterator.Next() {
keySplit := strings.Split(string(iterator.Key()), "/")

acc := &types.RegisteredInterchainAccount{
acc := types.RegisteredInterchainAccount{
PortId: keySplit[1],
AccountAddress: string(iterator.Value()),
}
Expand Down
20 changes: 2 additions & 18 deletions modules/apps/27-interchain-accounts/host/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,6 @@ func (suite *KeeperTestSuite) TestIsBound() {
suite.Require().True(isBound)
}

func (suite *KeeperTestSuite) TestGetAllPorts() {
suite.SetupTest()

path := NewICAPath(suite.chainA, suite.chainB)
suite.coordinator.SetupConnections(path)

err := SetupICAPath(path, TestOwnerAddress)
suite.Require().NoError(err)

expectedPorts := []string{types.PortID}

ports := suite.chainB.GetSimApp().ICAHostKeeper.GetAllPorts(suite.chainB.GetContext())
suite.Require().Len(ports, len(expectedPorts))
suite.Require().Equal(expectedPorts, ports)
}

func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() {
suite.SetupTest()

Expand Down Expand Up @@ -170,7 +154,7 @@ func (suite *KeeperTestSuite) TestGetAllActiveChannels() {

suite.chainB.GetSimApp().ICAHostKeeper.SetActiveChannelID(suite.chainB.GetContext(), expectedPortID, expectedChannelID)

expectedChannels := []*types.ActiveChannel{
expectedChannels := []types.ActiveChannel{
{
PortId: path.EndpointB.ChannelConfig.PortID,
ChannelId: path.EndpointB.ChannelID,
Expand Down Expand Up @@ -202,7 +186,7 @@ func (suite *KeeperTestSuite) TestGetAllInterchainAccounts() {

suite.chainB.GetSimApp().ICAHostKeeper.SetInterchainAccountAddress(suite.chainB.GetContext(), expectedPortID, expectedAccAddr)

expectedAccounts := []*types.RegisteredInterchainAccount{
expectedAccounts := []types.RegisteredInterchainAccount{
{
PortId: TestPortID,
AccountAddress: TestAccAddress.String(),
Expand Down
8 changes: 3 additions & 5 deletions modules/apps/27-interchain-accounts/host/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,14 @@ func (k Keeper) executeTx(ctx sdk.Context, sourcePort, destPort, destChannel str
return err
}

// CacheContext returns a new context with the multi-store branched into a cached storage object
// writeCache is called only if all msgs succeed, performing state transitions atomically
cacheCtx, writeCache := ctx.CacheContext()
for _, msg := range msgs {
if err := msg.ValidateBasic(); err != nil {
return err
}
}

// CacheContext returns a new context with the multi-store branched into a cached storage object
// writeCache is called only if all msgs succeed, performing state transitions atomically
cacheCtx, writeCache := ctx.CacheContext()
for _, msg := range msgs {
if _, err := k.executeMsg(cacheCtx, msg); err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions modules/apps/27-interchain-accounts/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {

// ValidateGenesis performs genesis state validation for the IBC interchain acounts module
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
return nil
return nil // TODO: https://github.com/cosmos/ibc-go/issues/535
}

// RegisterRESTRoutes implements AppModuleBasic interface
Expand Down Expand Up @@ -127,11 +127,11 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.
cdc.MustUnmarshalJSON(data, &genesisState)

if am.controllerKeeper != nil {
controllerkeeper.InitGenesis(ctx, *am.controllerKeeper, *genesisState.ControllerGenesisState)
controllerkeeper.InitGenesis(ctx, *am.controllerKeeper, genesisState.ControllerGenesisState)
}

if am.hostKeeper != nil {
hostkeeper.InitGenesis(ctx, *am.hostKeeper, *genesisState.HostGenesisState)
hostkeeper.InitGenesis(ctx, *am.hostKeeper, genesisState.HostGenesisState)
}

return []abci.ValidatorUpdate{}
Expand All @@ -140,8 +140,8 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.
// ExportGenesis returns the exported genesis state as raw bytes for the interchain accounts module
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
var (
controllerGenesisState *types.ControllerGenesisState
hostGenesisState *types.HostGenesisState
controllerGenesisState = types.DefaultControllerGenesis()
hostGenesisState = types.DefaultHostGenesis()
)

if am.controllerKeeper != nil {
Expand Down
18 changes: 9 additions & 9 deletions modules/apps/27-interchain-accounts/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,37 @@ func DefaultGenesis() *GenesisState {
}

// NewGenesisState creates and returns a new GenesisState instance from the provided controller and host genesis state types
func NewGenesisState(controllerGenesisState *ControllerGenesisState, hostGenesisState *HostGenesisState) *GenesisState {
func NewGenesisState(controllerGenesisState ControllerGenesisState, hostGenesisState HostGenesisState) *GenesisState {
return &GenesisState{
ControllerGenesisState: controllerGenesisState,
HostGenesisState: hostGenesisState,
}
}

// DefaultControllerGenesis creates and returns the default interchain accounts ControllerGenesisState
func DefaultControllerGenesis() *ControllerGenesisState {
return &ControllerGenesisState{}
func DefaultControllerGenesis() ControllerGenesisState {
return ControllerGenesisState{}
}

// NewControllerGenesisState creates a returns a new ControllerGenesisState instance
func NewControllerGenesisState(channels []*ActiveChannel, accounts []*RegisteredInterchainAccount, ports []string) *ControllerGenesisState {
return &ControllerGenesisState{
func NewControllerGenesisState(channels []ActiveChannel, accounts []RegisteredInterchainAccount, ports []string) ControllerGenesisState {
return ControllerGenesisState{
ActiveChannels: channels,
InterchainAccounts: accounts,
Ports: ports,
}
}

// DefaultHostGenesis creates and returns the default interchain accounts HostGenesisState
func DefaultHostGenesis() *HostGenesisState {
return &HostGenesisState{
func DefaultHostGenesis() HostGenesisState {
return HostGenesisState{
Port: PortID,
}
}

// NewHostGenesisState creates a returns a new HostGenesisState instance
func NewHostGenesisState(channels []*ActiveChannel, accounts []*RegisteredInterchainAccount, port string) *HostGenesisState {
return &HostGenesisState{
func NewHostGenesisState(channels []ActiveChannel, accounts []RegisteredInterchainAccount, port string) HostGenesisState {
return HostGenesisState{
ActiveChannels: channels,
InterchainAccounts: accounts,
Port: port,
Expand Down
Loading

0 comments on commit b87b806

Please sign in to comment.