-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ica/host)!: migrate ica/host to params to be self managed (#3520)
* feat: add proto msg * feat: add msg-server implementation * wip: add migrations * fix failing tests * cleanup * cleanup * Update modules/apps/27-interchain-accounts/host/migrations/v8/migrations.go * fix(transfer): 'p.AllowMessages' missing '&' in 'NewParamSetPair' * fix(transfer): 'p.HostEnabled' missing '&' in 'NewParamSetPair' * refactor(ica/host): reduce code duplication by removing 'IsHostEnabled' and 'GetAllowMessages' functions * refactor(ica/host): moved getter and setters to 'keeper.go' * refactor(ica/host): moved getter and setters to 'keeper.go' * fix(ica/host): handling the SetParam errors now * imp(ica/host): added failure cases to TestValidateParams * feat(ica/host): added codec for msg * fix(ica/host): added host's RegisterInterfaces to module.go * fix(changelog): removed manual addition * imp(ica/host): made GetParams more economical * fix(fee/test): handled ica's 'SetParams' error during testing * imp(ica/host): using ibcerrors instead of relying on sdk's govtypes * style(ica/host): removed '*' from Migrator's keeper * revert(ica/host): reverts to the previous commit as this is more consistent with what is done in module.go * fix(simapp): added ParamKeyTable to the icahost subspace in app.go for migration * feat(ica/host/test): added migrator_test.go * style(ica/host/test): ran gofumpt * feat(ica/host): passing legacySubspace to keeper instead * fix(ica/host): removed unneeded reference to hss from 'NewAppModule' function * fix(simapp): reduced modifications to simapp to 1 * fix(ica/host/test): updated tests * style(ica/host): ran gofumpt * docs(ica/host): fixed a typo * style(ica/host): added a space for import separation * style(ica/host): renamed 'migrator.go' to 'migrations.go' * refactor(ica/host): removed unneeded validate function * style(ica/host): storing ParamsKey using a string * fix(ica/host): registered the msg_server in ica's module.go * style(ica/host): removed unneeded fmt variable assignment * imp(ica/host/test): added more test cases, and refactored the test * style(ica/host/test): ran gofumpt * imp(ica/host): 'GetParams' panics now if it can't find the params * imp(core): added 'ErrInvalidAuthority' * imp(ica/host): uses 'ErrInvalidAuthority' * fix(ica/test): fixed test for the ica module * imp(ica/host/test): added a new test case * imp(ica/host/test): added params test to genesis * style(ica/host): ran gofumpt * imp(ica/host/test): added unset param test to keeper * docs(ica/host): added tracker issue for removing params_legacy.go * style(ica/host): improved test case naming * fix(ica/host/test): fixed a minor inaccuracy with the test in the hopes of increasing codecov * style(ica/host): updated err message * imp(ica/transfer, core/errors): removed ErrInvalidAuthority * style(ica/host): updated nil check to be more consistent * style(transfer): renamed errors to errorsmod to avoid shadowing * imp(ica/host/test): made test shorter * imp(ica/host/test): removed unneeded comment * style(ica/host/test): removed test case field names * refactor(ica/host, fee/test): refactored Validate out of SetParams * style(ica/host): ran gofumpt * imp(ica/types): switched back to 'bz == nil' * style(ica/host/test): looks better * style(ica/host): changed panic message * imp(ica/host): removed redundant Validate from msg server, handled in ValidateBasic * style(ica/host): added code comment * fix(ica/host): increase consensus version * style(ica/host/test): moved success case to top * style(ica/host/test): improve test styling * docs(migration): added changes in app.go * imp(ica/host): improved the error message --------- Co-authored-by: srdtrk <[email protected]> Co-authored-by: srdtrk <[email protected]>
- Loading branch information
1 parent
ba62612
commit df918d2
Showing
24 changed files
with
1,157 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
modules/apps/27-interchain-accounts/host/keeper/migrations.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" | ||
) | ||
|
||
// Migrator is a struct for handling in-place state migrations. | ||
type Migrator struct { | ||
keeper *Keeper | ||
} | ||
|
||
// NewMigrator returns Migrator instance for the state migration. | ||
func NewMigrator(k *Keeper) Migrator { | ||
return Migrator{ | ||
keeper: k, | ||
} | ||
} | ||
|
||
// MigrateParams migrates the host submodule's parameters from the x/params to self store. | ||
func (m Migrator) MigrateParams(ctx sdk.Context) error { | ||
var params types.Params | ||
m.keeper.legacySubspace.GetParamSet(ctx, ¶ms) | ||
|
||
if err := params.Validate(); err != nil { | ||
return err | ||
} | ||
m.keeper.SetParams(ctx, params) | ||
|
||
return nil | ||
} |
41 changes: 41 additions & 0 deletions
41
modules/apps/27-interchain-accounts/host/keeper/migrations_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" | ||
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestMigratorMigrateParams() { | ||
testCases := []struct { | ||
msg string | ||
malleate func() | ||
expectedParams icahosttypes.Params | ||
}{ | ||
{ | ||
"success: default params", | ||
func() { | ||
params := icahosttypes.DefaultParams() | ||
subspace := suite.chainA.GetSimApp().GetSubspace(icahosttypes.SubModuleName) // get subspace | ||
subspace.SetParamSet(suite.chainA.GetContext(), ¶ms) // set params | ||
}, | ||
icahosttypes.DefaultParams(), | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
suite.Run(fmt.Sprintf("case %s", tc.msg), func() { | ||
suite.SetupTest() // reset | ||
|
||
tc.malleate() // explicitly set params | ||
|
||
migrator := icahostkeeper.NewMigrator(&suite.chainA.GetSimApp().ICAHostKeeper) | ||
err := migrator.MigrateParams(suite.chainA.GetContext()) | ||
suite.Require().NoError(err) | ||
|
||
params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) | ||
suite.Require().Equal(tc.expectedParams, params) | ||
}) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
modules/apps/27-interchain-accounts/host/keeper/msg_server.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" | ||
ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors" | ||
) | ||
|
||
var _ types.MsgServer = (*msgServer)(nil) | ||
|
||
type msgServer struct { | ||
*Keeper | ||
} | ||
|
||
// NewMsgServerImpl returns an implementation of the ICS27 host MsgServer interface | ||
// for the provided Keeper. | ||
func NewMsgServerImpl(keeper *Keeper) types.MsgServer { | ||
return &msgServer{Keeper: keeper} | ||
} | ||
|
||
// UpdateParams updates the host submodule's params. | ||
func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { | ||
if m.authority != msg.Authority { | ||
return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "expected %s, got %s", m.authority, msg.Authority) | ||
} | ||
|
||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
m.SetParams(ctx, msg.Params) | ||
|
||
return &types.MsgUpdateParamsResponse{}, nil | ||
} |
Oops, something went wrong.