Skip to content

Commit

Permalink
Merge branch 'main' into aditya/update-val-set
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaSripal authored Mar 3, 2022
2 parents c5b6f0e + f71a505 commit f600a7f
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (interchain-accounts) [\#1037](https://github.com/cosmos/ibc-go/pull/1037) Add a function `InitModule` to the interchain accounts `AppModule`. This function should be called within the upgrade handler when adding the interchain accounts module to a chain. It should be called in place of InitGenesis (set the consensus version in the version map).
* (testing) [\#1003](https://github.com/cosmos/ibc-go/pull/1003) Testing chain's `Signer` fields has changed from `[]tmtypes.PrivValidator` to `map[string]tmtypes.PrivValidator` to accomodate valset updates changing the order of the ValidatorSet.
* (testing) [\#1003](https://github.com/cosmos/ibc-go/pull/1003) `SignAndDeliver` will now just deliver the transaction without creating and committing a block. Thus, it requires that `BeginBlock` MUST be called before `SignAndDeliver`
* (testing) [\#1003](https://github.com/cosmos/ibc-go/pull/1003) `NextBlock` will now call `EndBlock` and `Commit` internally and apply validator updates to the `NextVals` of `TestChain` and the `NextValsHash` of the current header. Test writers can now make changes to validator set and have them reflected in the `TestChain` and handled appropriately in `UpdateClient`
Expand Down
6 changes: 3 additions & 3 deletions docs/ibc/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ func NewApp(...args) *App {

// Create IBC Keeper
app.IBCKeeper = ibckeeper.NewKeeper(
appCodec, keys[ibchost.StoreKey], app.StakingKeeper, scopedIBCKeeper,
appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper,
)

// Create Transfer Keepers
app.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec, keys[ibctransfertypes.StoreKey],
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName),
app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.AccountKeeper, app.BankKeeper, scopedTransferKeeper,
)
transferModule := transfer.NewAppModule(app.TransferKeeper)
Expand Down
25 changes: 16 additions & 9 deletions docs/migrations/v2-to-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,24 @@ Please see the [ICS27 documentation](../apps/interchain-accounts/overview.md) fo
If the chain will adopt ICS27, it must set the appropriate params during the execution of the upgrade handler in `app.go`:
```go
app.UpgradeKeeper.SetUpgradeHandler("v3",
func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
// set ICS27 Host submodule params
app.ICAHostKeeper.SetParams(ctx, icahosttypes.Params{
HostEnabled: true,
AllowMessages: []string{"/cosmos.bank.v1beta1.MsgSend", ...],
})
func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// set the ICS27 consensus version so InitGenesis is not run
fromVM[icatypes.ModuleName] = icamodule.ConsensusVersion()

// set ICS27 Controller submodule params
app.ICAControllerKeeper.SetParams(ctx, icacontrollertypes.Params{

// create ICS27 Controller submodule params
controllerParams := icacontrollertypes.Params{
ControllerEnabled: true,
})
}

// create ICS27 Host submodule params
hostParams := icahosttypes.Params{
HostEnabled: true,
AllowMessages: []string{"/cosmos.bank.v1beta1.MsgSend", ...],
}

// initialize ICS27 module
icamodule.InitModule(ctx, controllerParams, hostParams)

...

Expand Down
13 changes: 13 additions & 0 deletions modules/apps/27-interchain-accounts/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
hosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types"
"github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
porttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
)

var (
Expand Down Expand Up @@ -101,6 +102,18 @@ func NewAppModule(controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkee
}
}

// InitModule will initialize the interchain accounts moudule. It should only be
// called once and as an alternative to InitGenesis.
func (am AppModule) InitModule(ctx sdk.Context, controllerParams controllertypes.Params, hostParams hosttypes.Params) {
am.controllerKeeper.SetParams(ctx, controllerParams)
am.hostKeeper.SetParams(ctx, hostParams)

cap := am.hostKeeper.BindPort(ctx, types.PortID)
if err := am.hostKeeper.ClaimCapability(ctx, cap, ibchost.PortPath(types.PortID)); err != nil {
panic(fmt.Sprintf("could not claim port capability: %v", err))
}
}

// RegisterInvariants implements the AppModule interface
func (AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
}
Expand Down
74 changes: 74 additions & 0 deletions modules/apps/27-interchain-accounts/module_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package ica_test

import (
"testing"

"github.com/stretchr/testify/suite"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

ica "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts"
controllertypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types"
hosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types"
"github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
ibctesting "github.com/cosmos/ibc-go/v3/testing"
"github.com/cosmos/ibc-go/v3/testing/simapp"
)

type InterchainAccountsTestSuite struct {
suite.Suite

coordinator *ibctesting.Coordinator
}

func TestICATestSuite(t *testing.T) {
suite.Run(t, new(InterchainAccountsTestSuite))
}

func (suite *InterchainAccountsTestSuite) SetupTest() {
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2)
}

func (suite *InterchainAccountsTestSuite) TestInitModule() {
app := simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, simapp.MakeTestEncodingConfig(), simapp.EmptyAppOptions{})
icamodule, ok := app.GetModuleManager().Modules[types.ModuleName].(ica.AppModule)
suite.Require().True(ok)

header := tmproto.Header{
ChainID: "testchain",
Height: 1,
Time: suite.coordinator.CurrentTime.UTC(),
}

ctx := app.GetBaseApp().NewContext(true, header)

// ensure params are not set
suite.Require().Panics(func() {
app.ICAControllerKeeper.GetParams(ctx)
})
suite.Require().Panics(func() {
app.ICAHostKeeper.GetParams(ctx)
})

controllerParams := controllertypes.DefaultParams()
controllerParams.ControllerEnabled = true

hostParams := hosttypes.DefaultParams()
expAllowMessages := []string{"sdk.Msg"}
hostParams.HostEnabled = true
hostParams.AllowMessages = expAllowMessages

suite.Require().False(app.IBCKeeper.PortKeeper.IsBound(ctx, types.PortID))

icamodule.InitModule(ctx, controllerParams, hostParams)

controllerParams = app.ICAControllerKeeper.GetParams(ctx)
suite.Require().True(controllerParams.ControllerEnabled)

hostParams = app.ICAHostKeeper.GetParams(ctx)
suite.Require().True(hostParams.HostEnabled)
suite.Require().Equal(expAllowMessages, hostParams.AllowMessages)

suite.Require().True(app.IBCKeeper.PortKeeper.IsBound(ctx, types.PortID))
}
2 changes: 1 addition & 1 deletion modules/apps/transfer/types/ack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
tmprotostate "github.com/tendermint/tendermint/proto/tendermint/state"
tmstate "github.com/tendermint/tendermint/state"

"github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types"
"github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
ibctesting "github.com/cosmos/ibc-go/v3/testing"
)

Expand Down
6 changes: 6 additions & 0 deletions testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,12 @@ func (app *SimApp) ModuleAccountAddrs() map[string]bool {
return modAccAddrs
}

// GetModuleManager returns the app module manager
// NOTE: used for testing purposes
func (app *SimApp) GetModuleManager() *module.Manager {
return app.mm
}

// LegacyAmino returns SimApp's amino codec.
//
// NOTE: This is solely to be used for testing purposes as it may be desirable
Expand Down

0 comments on commit f600a7f

Please sign in to comment.