Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1cb9375

Browse files
committedMay 31, 2023
feat(connection): migrate connection params
1 parent 016ba0b commit 1cb9375

25 files changed

+817
-162
lines changed
 

‎docs/migrations/v7-to-v8.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@ TODO: https://github.com/cosmos/ibc-go/pull/3505 (extra parameter added to trans
4747
)
4848
```
4949

50-
- You should pass the `authority` to the IBC keeper. ([#3640](https://github.com/cosmos/ibc-go/pull/3640)) See [diff](https://github.com/cosmos/ibc-go/pull/3640/files#diff-d18972debee5e64f16e40807b2ae112ddbe609504a93ea5e1c80a5d489c3a08a).
50+
- You should pass the `authority` to the IBC keeper. ([#3640](https://github.com/cosmos/ibc-go/pull/3640) and [#3650](https://github.com/cosmos/ibc-go/pull/3650)) See [diff](https://github.com/cosmos/ibc-go/pull/3640/files#diff-d18972debee5e64f16e40807b2ae112ddbe609504a93ea5e1c80a5d489c3a08a).
5151

5252
```diff
5353
// app.go
5454

5555
// IBC Keepers
56-
5756
app.IBCKeeper = ibckeeper.NewKeeper(
5857
- appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper,
5958
+ appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),

‎e2e/tests/core/03-connection/connection_test.go

+20-19
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ package connection
33
import (
44
"context"
55
"fmt"
6-
"strconv"
7-
"strings"
86
"testing"
97
"time"
108

9+
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
1110
paramsproposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
1211
"github.com/strangelove-ventures/interchaintest/v7/ibc"
1312
test "github.com/strangelove-ventures/interchaintest/v7/testutil"
@@ -30,19 +29,11 @@ type ConnectionTestSuite struct {
3029

3130
// QueryMaxExpectedTimePerBlockParam queries the on-chain max expected time per block param for 03-connection
3231
func (s *ConnectionTestSuite) QueryMaxExpectedTimePerBlockParam(ctx context.Context, chain ibc.Chain) uint64 {
33-
queryClient := s.GetChainGRCPClients(chain).ParamsQueryClient
34-
res, err := queryClient.Params(ctx, &paramsproposaltypes.QueryParamsRequest{
35-
Subspace: ibcexported.ModuleName,
36-
Key: string(connectiontypes.KeyMaxExpectedTimePerBlock),
37-
})
38-
s.Require().NoError(err)
39-
40-
// removing additional strings that are used for amino
41-
delay := strings.ReplaceAll(res.Param.Value, "\"", "")
42-
time, err := strconv.ParseUint(delay, 10, 64)
32+
queryClient := s.GetChainGRCPClients(chain).ConnectionQueryClient
33+
res, err := queryClient.ConnectionParams(ctx, &connectiontypes.QueryConnectionParamsRequest{})
4334
s.Require().NoError(err)
4435

45-
return time
36+
return res.Params.MaxExpectedTimePerBlock
4637
}
4738

4839
// TestMaxExpectedTimePerBlockParam tests changing the MaxExpectedTimePerBlock param using a governance proposal
@@ -52,6 +43,7 @@ func (s *ConnectionTestSuite) TestMaxExpectedTimePerBlockParam() {
5243

5344
relayer, channelA := s.SetupChainsRelayerAndChannel(ctx, s.TransferChannelOptions())
5445
chainA, chainB := s.GetChains()
46+
chainAVersion := chainA.Config().Images[0].Version
5547

5648
chainBDenom := chainB.Config().Denom
5749
chainAIBCToken := testsuite.GetIBCToken(chainBDenom, channelA.PortID, channelA.ChannelID)
@@ -71,13 +63,22 @@ func (s *ConnectionTestSuite) TestMaxExpectedTimePerBlockParam() {
7163
})
7264

7365
t.Run("change the delay to 60 seconds", func(t *testing.T) {
74-
delay := fmt.Sprintf(`"%d"`, 1*time.Minute)
75-
changes := []paramsproposaltypes.ParamChange{
76-
paramsproposaltypes.NewParamChange(ibcexported.ModuleName, string(connectiontypes.KeyMaxExpectedTimePerBlock), delay),
77-
}
66+
delay := uint64(1 * time.Minute)
67+
if testvalues.SelfParamsFeatureReleases.IsSupported(chainAVersion) {
68+
authority, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainA)
69+
s.Require().NoError(err)
70+
s.Require().NotNil(authority)
71+
72+
msg := connectiontypes.NewMsgUpdateConnectionParams(authority.String(), connectiontypes.NewParams(delay))
73+
s.ExecuteGovProposalV1(ctx, msg, chainA, chainAWallet, 1)
74+
} else {
75+
changes := []paramsproposaltypes.ParamChange{
76+
paramsproposaltypes.NewParamChange(ibcexported.ModuleName, string(connectiontypes.KeyMaxExpectedTimePerBlock), fmt.Sprintf(`"%d"`, delay)),
77+
}
7878

79-
proposal := paramsproposaltypes.NewParameterChangeProposal(ibctesting.Title, ibctesting.Description, changes)
80-
s.ExecuteGovProposal(ctx, chainA, chainAWallet, proposal)
79+
proposal := paramsproposaltypes.NewParameterChangeProposal(ibctesting.Title, ibctesting.Description, changes)
80+
s.ExecuteGovProposal(ctx, chainA, chainAWallet, proposal)
81+
}
8182
})
8283

8384
t.Run("validate the param was successfully changed", func(t *testing.T) {

‎e2e/tests/transfer/base_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (s *TransferTestSuite) TestSendEnabledParam() {
245245
chainBAddress := chainBWallet.FormattedAddress()
246246

247247
chainAVersion := chainA.Config().Images[0].Version
248-
isSelfManagingParams := testvalues.TransferSelfParamsFeatureReleases.IsSupported(chainAVersion)
248+
isSelfManagingParams := testvalues.SelfParamsFeatureReleases.IsSupported(chainAVersion)
249249

250250
govModuleAddress, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainA)
251251
s.Require().NoError(err)
@@ -308,7 +308,7 @@ func (s *TransferTestSuite) TestReceiveEnabledParam() {
308308
)
309309

310310
chainAVersion := chainA.Config().Images[0].Version
311-
isSelfManagingParams := testvalues.TransferSelfParamsFeatureReleases.IsSupported(chainAVersion)
311+
isSelfManagingParams := testvalues.SelfParamsFeatureReleases.IsSupported(chainAVersion)
312312

313313
govModuleAddress, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainA)
314314
s.Require().NoError(err)

‎e2e/testsuite/grpc_query.go

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func (s *E2ETestSuite) InitGRPCClients(chain *cosmos.CosmosChain) {
7373

7474
s.grpcClients[chain.Config().ChainID] = GRPCClients{
7575
ClientQueryClient: clienttypes.NewQueryClient(grpcConn),
76+
ConnectionQueryClient: connectiontypes.NewQueryClient(grpcConn),
7677
ChannelQueryClient: channeltypes.NewQueryClient(grpcConn),
7778
TransferQueryClient: transfertypes.NewQueryClient(grpcConn),
7879
FeeQueryClient: feetypes.NewQueryClient(grpcConn),

‎e2e/testvalues/values.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ var IcadNewGenesisCommandsFeatureReleases = semverutil.FeatureReleases{
6767
}
6868

6969
// TransferSelfParamsFeatureReleases represents the releases the transfer module started managing its own params.
70-
var TransferSelfParamsFeatureReleases = semverutil.FeatureReleases{
70+
var SelfParamsFeatureReleases = semverutil.FeatureReleases{
7171
MajorVersion: "v8",
7272
}
7373

‎modules/core/03-connection/genesis.go

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package connection
22

33
import (
4+
"fmt"
5+
46
sdk "github.com/cosmos/cosmos-sdk/types"
57

68
"github.com/cosmos/ibc-go/v7/modules/core/03-connection/keeper"
@@ -18,6 +20,9 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) {
1820
k.SetClientConnectionPaths(ctx, connPaths.ClientId, connPaths.Paths)
1921
}
2022
k.SetNextConnectionSequence(ctx, gs.NextConnectionSequence)
23+
if err := gs.Params.Validate(); err != nil {
24+
panic(fmt.Sprintf("invalid ibc connection genesis state parameters: %v", err))
25+
}
2126
k.SetParams(ctx, gs.Params)
2227

2328
k.CreateSentinelLocalhostConnection(ctx)

‎modules/core/03-connection/keeper/keeper.go

+31-11
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ type Keeper struct {
2020
// implements gRPC QueryServer interface
2121
types.QueryServer
2222

23-
storeKey storetypes.StoreKey
24-
paramSpace paramtypes.Subspace
25-
cdc codec.BinaryCodec
26-
clientKeeper types.ClientKeeper
23+
storeKey storetypes.StoreKey
24+
legacySubspace paramtypes.Subspace
25+
cdc codec.BinaryCodec
26+
clientKeeper types.ClientKeeper
2727
}
2828

2929
// NewKeeper creates a new IBC connection Keeper instance
30-
func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace, ck types.ClientKeeper) Keeper {
30+
func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace paramtypes.Subspace, ck types.ClientKeeper) Keeper {
3131
// set KeyTable if it has not already been set
32-
if !paramSpace.HasKeyTable() {
33-
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
32+
if !legacySubspace.HasKeyTable() {
33+
legacySubspace = legacySubspace.WithKeyTable(types.ParamKeyTable())
3434
}
3535

3636
return Keeper{
37-
storeKey: key,
38-
cdc: cdc,
39-
paramSpace: paramSpace,
40-
clientKeeper: ck,
37+
storeKey: key,
38+
cdc: cdc,
39+
legacySubspace: legacySubspace,
40+
clientKeeper: ck,
4141
}
4242
}
4343

@@ -221,3 +221,23 @@ func (k Keeper) addConnectionToClient(ctx sdk.Context, clientID, connectionID st
221221
k.SetClientConnectionPaths(ctx, clientID, conns)
222222
return nil
223223
}
224+
225+
// GetParams returns the total set of ibc-connection parameters.
226+
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
227+
store := ctx.KVStore(k.storeKey)
228+
bz := store.Get([]byte(types.ParamsKey))
229+
if len(bz) == 0 {
230+
return types.Params{}
231+
}
232+
233+
var params types.Params
234+
k.cdc.MustUnmarshal(bz, &params)
235+
return params
236+
}
237+
238+
// SetParams sets the total set of ibc-connection parameters.
239+
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
240+
store := ctx.KVStore(k.storeKey)
241+
bz := k.cdc.MustMarshal(&params)
242+
store.Set([]byte(types.ParamsKey), bz)
243+
}

‎modules/core/03-connection/keeper/keeper_test.go

+50
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,53 @@ func (suite *KeeperTestSuite) TestLocalhostConnectionEndCreation() {
176176
expectedCounterParty := types.NewCounterparty(exported.LocalhostClientID, exported.LocalhostConnectionID, commitmenttypes.NewMerklePrefix(connectionKeeper.GetCommitmentPrefix().Bytes()))
177177
suite.Require().Equal(expectedCounterParty, connectionEnd.Counterparty)
178178
}
179+
180+
// TestDefaultSetParams tests the default params set are what is expected
181+
func (suite *KeeperTestSuite) TestDefaultSetParams() {
182+
expParams := types.DefaultParams()
183+
184+
params := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetParams(suite.chainA.GetContext())
185+
suite.Require().Equal(expParams, params)
186+
}
187+
188+
// TestParams tests that param setting and retrieval works properly
189+
func (suite *KeeperTestSuite) TestParams() {
190+
testCases := []struct {
191+
name string
192+
input types.Params
193+
expPass bool
194+
}{
195+
{"success: set default params", types.DefaultParams(), true},
196+
{"success: valid value for MaxExpectedTimePerBlock", types.NewParams(10), true},
197+
{"failure: invalid value for MaxExpectedTimePerBlock", types.NewParams(0), false},
198+
}
199+
200+
for _, tc := range testCases {
201+
tc := tc
202+
203+
suite.Run(tc.name, func() {
204+
suite.SetupTest() // reset
205+
ctx := suite.chainA.GetContext()
206+
err := tc.input.Validate()
207+
suite.chainA.GetSimApp().IBCKeeper.ConnectionKeeper.SetParams(ctx, tc.input)
208+
if tc.expPass {
209+
suite.Require().NoError(err)
210+
expected := tc.input
211+
p := suite.chainA.GetSimApp().IBCKeeper.ConnectionKeeper.GetParams(ctx)
212+
suite.Require().Equal(expected, p)
213+
} else {
214+
suite.Require().Error(err)
215+
}
216+
})
217+
}
218+
}
219+
220+
// TestUnsetParams tests that trying to get params that are not set panics.
221+
func (suite *KeeperTestSuite) TestUnsetParams() {
222+
suite.SetupTest()
223+
ctx := suite.chainA.GetContext()
224+
store := ctx.KVStore(suite.chainA.GetSimApp().GetKey(exported.StoreKey))
225+
store.Delete([]byte(types.ParamsKey))
226+
227+
suite.Require().Equal(suite.chainA.GetSimApp().IBCKeeper.ConnectionKeeper.GetParams(ctx), types.Params{})
228+
}

‎modules/core/03-connection/keeper/migrations.go

+15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
sdk "github.com/cosmos/cosmos-sdk/types"
55

66
connectionv7 "github.com/cosmos/ibc-go/v7/modules/core/03-connection/migrations/v7"
7+
"github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
78
)
89

910
// Migrator is a struct for handling in-place store migrations.
@@ -22,3 +23,17 @@ func (m Migrator) Migrate3to4(ctx sdk.Context) error {
2223
connectionv7.MigrateLocalhostConnection(ctx, m.keeper)
2324
return nil
2425
}
26+
27+
// MigrateParams migrates from consensus version 4 to 5.
28+
// This migration takes the parameters that are currently stored and managed by x/params
29+
// and stores them directly in the ibc module's state.
30+
func (m Migrator) MigrateParams(ctx sdk.Context) error {
31+
var params types.Params
32+
m.keeper.legacySubspace.GetParamSet(ctx, &params)
33+
34+
if err := params.Validate(); err != nil {
35+
return err
36+
}
37+
m.keeper.SetParams(ctx, params)
38+
return nil
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package keeper_test
2+
3+
import (
4+
"github.com/cosmos/ibc-go/v7/modules/core/03-connection/keeper"
5+
"github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
6+
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
7+
)
8+
9+
// TestMigrateParams tests that the params for the connection are properly migrated
10+
func (suite *KeeperTestSuite) TestMigrateParams() {
11+
testCases := []struct {
12+
name string
13+
malleate func()
14+
expectedParams types.Params
15+
}{
16+
{
17+
"success: default params",
18+
func() {
19+
params := types.DefaultParams()
20+
subspace := suite.chainA.GetSimApp().GetSubspace(ibcexported.ModuleName)
21+
subspace.SetParamSet(suite.chainA.GetContext(), &params) // set params
22+
},
23+
types.DefaultParams(),
24+
},
25+
}
26+
27+
for _, tc := range testCases {
28+
tc := tc
29+
suite.Run(tc.name, func() {
30+
suite.SetupTest() // reset
31+
32+
tc.malleate()
33+
34+
ctx := suite.chainA.GetContext()
35+
migrator := keeper.NewMigrator(suite.chainA.GetSimApp().IBCKeeper.ConnectionKeeper)
36+
err := migrator.MigrateParams(ctx)
37+
suite.Require().NoError(err)
38+
39+
params := suite.chainA.GetSimApp().IBCKeeper.ConnectionKeeper.GetParams(ctx)
40+
suite.Require().Equal(tc.expectedParams, params)
41+
})
42+
}
43+
}

‎modules/core/03-connection/keeper/params.go

-24
This file was deleted.

‎modules/core/03-connection/keeper/params_test.go

-17
This file was deleted.

‎modules/core/03-connection/keeper/verify.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ func (k Keeper) VerifyNextSequenceRecv(
369369
func (k Keeper) getBlockDelay(ctx sdk.Context, connection exported.ConnectionI) uint64 {
370370
// expectedTimePerBlock should never be zero, however if it is then return a 0 blcok delay for safety
371371
// as the expectedTimePerBlock parameter was not set.
372-
expectedTimePerBlock := k.GetMaxExpectedTimePerBlock(ctx)
372+
expectedTimePerBlock := k.GetParams(ctx).MaxExpectedTimePerBlock
373373
if expectedTimePerBlock == 0 {
374374
return 0
375375
}

‎modules/core/03-connection/types/codec.go

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
3333
&MsgConnectionOpenTry{},
3434
&MsgConnectionOpenAck{},
3535
&MsgConnectionOpenConfirm{},
36+
&MsgUpdateConnectionParams{},
3637
)
3738

3839
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)

‎modules/core/03-connection/types/keys.go

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ const (
2828

2929
// ConnectionPrefix is the prefix used when creating a connection identifier
3030
ConnectionPrefix = "connection-"
31+
32+
// ParamsKey is the store key for the IBC connection parameters
33+
ParamsKey = "connectionParams"
3134
)
3235

3336
// FormatConnectionIdentifier returns the connection identifier with the sequence appended.

‎modules/core/03-connection/types/msgs.go

+26
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var (
1717
_ sdk.Msg = (*MsgConnectionOpenConfirm)(nil)
1818
_ sdk.Msg = (*MsgConnectionOpenAck)(nil)
1919
_ sdk.Msg = (*MsgConnectionOpenTry)(nil)
20+
_ sdk.Msg = (*MsgUpdateConnectionParams)(nil)
2021

2122
_ codectypes.UnpackInterfacesMessage = (*MsgConnectionOpenTry)(nil)
2223
_ codectypes.UnpackInterfacesMessage = (*MsgConnectionOpenAck)(nil)
@@ -289,3 +290,28 @@ func (msg MsgConnectionOpenConfirm) GetSigners() []sdk.AccAddress {
289290
}
290291
return []sdk.AccAddress{accAddr}
291292
}
293+
294+
// NewMsgUpdateConnectionParams creates a new MsgUpdateConnectionParams instance
295+
func NewMsgUpdateConnectionParams(authority string, params Params) *MsgUpdateConnectionParams {
296+
return &MsgUpdateConnectionParams{
297+
Authority: authority,
298+
Params: params,
299+
}
300+
}
301+
302+
// GetSigners returns the expected signers for a MsgUpdateConnectionParams message.
303+
func (msg *MsgUpdateConnectionParams) GetSigners() []sdk.AccAddress {
304+
accAddr, err := sdk.AccAddressFromBech32(msg.Authority)
305+
if err != nil {
306+
panic(err)
307+
}
308+
return []sdk.AccAddress{accAddr}
309+
}
310+
311+
// ValidateBasic performs basic checks on a MsgUpdateConnectionParams.
312+
func (msg *MsgUpdateConnectionParams) ValidateBasic() error {
313+
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil {
314+
return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err)
315+
}
316+
return msg.Params.Validate()
317+
}

‎modules/core/03-connection/types/msgs_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,38 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenConfirm() {
231231
}
232232
}
233233
}
234+
235+
// TestMsgUpdateConnectionParams_ValidateBasic tests ValidateBasic for MsgUpdateConnectionParams
236+
func (suite *MsgTestSuite) TestMsgUpdateConnectionParams_ValidateBasic() {
237+
authority := suite.chainA.App.GetIBCKeeper().GetAuthority()
238+
testCases := []struct {
239+
name string
240+
msg *types.MsgUpdateConnectionParams
241+
expPass bool
242+
}{
243+
{
244+
"success: valid authority and params",
245+
types.NewMsgUpdateConnectionParams(authority, types.DefaultParams()),
246+
true,
247+
},
248+
{
249+
"failure: invalid authority address",
250+
types.NewMsgUpdateConnectionParams("invalid", types.DefaultParams()),
251+
false,
252+
},
253+
{
254+
"failure: invalid time per block",
255+
types.NewMsgUpdateConnectionParams(authority, types.NewParams(0)),
256+
false,
257+
},
258+
}
259+
260+
for _, tc := range testCases {
261+
err := tc.msg.ValidateBasic()
262+
if tc.expPass {
263+
suite.Require().NoError(err, "valid case %s failed", tc.name)
264+
} else {
265+
suite.Require().Error(err, "invalid case %s passed", tc.name)
266+
}
267+
}
268+
}

‎modules/core/03-connection/types/params.go

-25
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,11 @@ package types
33
import (
44
"fmt"
55
"time"
6-
7-
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
86
)
97

108
// DefaultTimePerBlock is the default value for maximum expected time per block (in nanoseconds).
119
const DefaultTimePerBlock = 30 * time.Second
1210

13-
// KeyMaxExpectedTimePerBlock is store's key for MaxExpectedTimePerBlock parameter
14-
var KeyMaxExpectedTimePerBlock = []byte("MaxExpectedTimePerBlock")
15-
16-
// ParamKeyTable type declaration for parameters
17-
func ParamKeyTable() paramtypes.KeyTable {
18-
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
19-
}
20-
2111
// NewParams creates a new parameter configuration for the ibc connection module
2212
func NewParams(timePerBlock uint64) Params {
2313
return Params{
@@ -37,18 +27,3 @@ func (p Params) Validate() error {
3727
}
3828
return nil
3929
}
40-
41-
// ParamSetPairs implements params.ParamSet
42-
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
43-
return paramtypes.ParamSetPairs{
44-
paramtypes.NewParamSetPair(KeyMaxExpectedTimePerBlock, p.MaxExpectedTimePerBlock, validateParams),
45-
}
46-
}
47-
48-
func validateParams(i interface{}) error {
49-
_, ok := i.(uint64)
50-
if !ok {
51-
return fmt.Errorf("invalid parameter. expected %T, got type: %T", uint64(1), i)
52-
}
53-
return nil
54-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
NOTE: Usage of x/params to manage parameters is deprecated in favor of x/gov
3+
controlled execution of MsgUpdateParams messages. These types remains solely
4+
for migration purposes and will be removed in a future release.
5+
[#3621](https://github.com/cosmos/ibc-go/issues/3621)
6+
*/
7+
package types
8+
9+
import (
10+
fmt "fmt"
11+
12+
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
13+
)
14+
15+
// KeyMaxExpectedTimePerBlock is store's key for MaxExpectedTimePerBlock parameter
16+
var KeyMaxExpectedTimePerBlock = []byte("MaxExpectedTimePerBlock")
17+
18+
// ParamKeyTable type declaration for parameters
19+
func ParamKeyTable() paramtypes.KeyTable {
20+
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
21+
}
22+
23+
// ParamSetPairs implements params.ParamSet
24+
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
25+
return paramtypes.ParamSetPairs{
26+
paramtypes.NewParamSetPair(KeyMaxExpectedTimePerBlock, &p.MaxExpectedTimePerBlock, validateParams),
27+
}
28+
}
29+
30+
func validateParams(i interface{}) error {
31+
_, ok := i.(uint64)
32+
if !ok {
33+
return fmt.Errorf("invalid parameter. expected %T, got type: %T", uint64(1), i)
34+
}
35+
return nil
36+
}

‎modules/core/03-connection/types/tx.pb.go

+449-54
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎modules/core/keeper/keeper.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ func (k *Keeper) SetRouter(rtr *porttypes.Router) {
9595
k.Router.Seal()
9696
}
9797

98-
// GetAuthority returns the client submodule's authority.
99-
func (k Keeper) GetAuthority() string {
100-
return k.authority
101-
}
102-
10398
// isEmpty checks if the interface is an empty struct or a pointer pointing
10499
// to an empty struct
105100
func isEmpty(keeper interface{}) bool {
@@ -115,3 +110,8 @@ func isEmpty(keeper interface{}) bool {
115110
}
116111
return false
117112
}
113+
114+
// GetAuthority returns the ibc module's authority.
115+
func (k Keeper) GetAuthority() string {
116+
return k.authority
117+
}

‎modules/core/keeper/msg_server.go

+12
Original file line numberDiff line numberDiff line change
@@ -706,3 +706,15 @@ func (k Keeper) UpdateClientParams(goCtx context.Context, msg *clienttypes.MsgUp
706706

707707
return &clienttypes.MsgUpdateClientParamsResponse{}, nil
708708
}
709+
710+
// UpdateConnectionParams defines a rpc handler method for MsgUpdateConnectionParams.
711+
func (k Keeper) UpdateConnectionParams(goCtx context.Context, msg *connectiontypes.MsgUpdateConnectionParams) (*connectiontypes.MsgUpdateConnectionParamsResponse, error) {
712+
if k.GetAuthority() != msg.Authority {
713+
return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "expected %s, got %s", k.GetAuthority(), msg.Authority)
714+
}
715+
716+
ctx := sdk.UnwrapSDKContext(goCtx)
717+
k.ConnectionKeeper.SetParams(ctx, msg.Params)
718+
719+
return &connectiontypes.MsgUpdateConnectionParamsResponse{}, nil
720+
}

‎modules/core/keeper/msg_server_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
66

77
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
8+
connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
89
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
910
commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types"
1011
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
@@ -825,3 +826,54 @@ func (suite *KeeperTestSuite) TestUpdateClientParams() {
825826
})
826827
}
827828
}
829+
830+
// TestUpdateConnectionParams tests the UpdateConnectionParams rpc handler
831+
func (suite *KeeperTestSuite) TestUpdateConnectionParams() {
832+
validAuthority := suite.chainA.App.GetIBCKeeper().GetAuthority()
833+
testCases := []struct {
834+
name string
835+
msg *connectiontypes.MsgUpdateConnectionParams
836+
expPass bool
837+
}{
838+
{
839+
"success: valid authority and default params",
840+
connectiontypes.NewMsgUpdateConnectionParams(validAuthority, connectiontypes.DefaultParams()),
841+
true,
842+
},
843+
{
844+
"failure: malformed authority address",
845+
connectiontypes.NewMsgUpdateConnectionParams(ibctesting.InvalidID, connectiontypes.DefaultParams()),
846+
false,
847+
},
848+
{
849+
"failure: empty authority address",
850+
connectiontypes.NewMsgUpdateConnectionParams("", connectiontypes.DefaultParams()),
851+
false,
852+
},
853+
{
854+
"failure: whitespace authority address",
855+
connectiontypes.NewMsgUpdateConnectionParams(" ", connectiontypes.DefaultParams()),
856+
false,
857+
},
858+
{
859+
"failure: unauthorized authority address",
860+
connectiontypes.NewMsgUpdateConnectionParams(ibctesting.TestAccAddress, connectiontypes.DefaultParams()),
861+
false,
862+
},
863+
}
864+
865+
for _, tc := range testCases {
866+
tc := tc
867+
suite.Run(tc.name, func() {
868+
suite.SetupTest()
869+
_, err := keeper.Keeper.UpdateConnectionParams(*suite.chainA.App.GetIBCKeeper(), suite.chainA.GetContext(), tc.msg)
870+
if tc.expPass {
871+
suite.Require().NoError(err)
872+
p := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetParams(suite.chainA.GetContext())
873+
suite.Require().Equal(tc.msg.Params, p)
874+
} else {
875+
suite.Require().Error(err)
876+
}
877+
})
878+
}
879+
}

‎modules/core/module.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,13 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
138138
panic(err)
139139
}
140140

141-
if err := cfg.RegisterMigration(exported.ModuleName, 4, clientMigrator.MigrateParams); err != nil {
141+
if err := cfg.RegisterMigration(exported.ModuleName, 4, func(ctx sdk.Context) error {
142+
if err := clientMigrator.MigrateParams(ctx); err != nil {
143+
return err
144+
}
145+
146+
return connectionMigrator.MigrateParams(ctx)
147+
}); err != nil {
142148
panic(err)
143149
}
144150
}

‎proto/ibc/core/connection/v1/tx.proto

+21
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package ibc.core.connection.v1;
44

55
option go_package = "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types";
66

7+
import "cosmos/msg/v1/msg.proto";
78
import "gogoproto/gogo.proto";
89
import "google/protobuf/any.proto";
910
import "ibc/core/client/v1/client.proto";
@@ -23,6 +24,10 @@ service Msg {
2324
// ConnectionOpenConfirm defines a rpc handler method for
2425
// MsgConnectionOpenConfirm.
2526
rpc ConnectionOpenConfirm(MsgConnectionOpenConfirm) returns (MsgConnectionOpenConfirmResponse);
27+
28+
// UpdateConnectionParams defines a rpc handler method for
29+
// MsgUpdateConnectionParams.
30+
rpc UpdateConnectionParams(MsgUpdateConnectionParams) returns (MsgUpdateConnectionParamsResponse);
2631
}
2732

2833
// MsgConnectionOpenInit defines the msg sent by an account on Chain A to
@@ -115,3 +120,19 @@ message MsgConnectionOpenConfirm {
115120
// MsgConnectionOpenConfirmResponse defines the Msg/ConnectionOpenConfirm
116121
// response type.
117122
message MsgConnectionOpenConfirmResponse {}
123+
124+
// MsgUpdateConnectionParams defines the sdk.Msg type to update the connection parameters.
125+
message MsgUpdateConnectionParams {
126+
option (cosmos.msg.v1.signer) = "authority";
127+
128+
// authority is the address of the governance account.
129+
string authority = 1;
130+
131+
// params defines the connection parameters to update.
132+
//
133+
// NOTE: All parameters must be supplied.
134+
Params params = 2 [(gogoproto.nullable) = false];
135+
}
136+
137+
// MsgUpdateConnectionParamsResponse defines the MsgUpdateConnectionParams response type.
138+
message MsgUpdateConnectionParamsResponse {}

0 commit comments

Comments
 (0)
Please sign in to comment.