Skip to content

Commit 48d39e3

Browse files
authored
Merge PR #5619: proto: migrate params to hybrid codec
1 parent dca7246 commit 48d39e3

File tree

18 files changed

+768
-41
lines changed

18 files changed

+768
-41
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ balances or a single balance by denom when the `denom` query parameter is presen
4444

4545
### API Breaking Changes
4646

47+
* (x/params) [\#5619](https://github.com/cosmos/cosmos-sdk/pull/5619) The `x/params` keeper now accepts a `codec.Marshaller` instead of
48+
a reference to an amino codec. Amino is still used for JSON serialization.
4749
* (types) [\#5579](https://github.com/cosmos/cosmos-sdk/pull/5579) The `keepRecent` field has been removed from the `PruningOptions` type.
4850
The `PruningOptions` type now only includes fields `KeepEvery` and `SnapshotEvery`, where `KeepEvery`
4951
determines which committed heights are flushed to disk and `SnapshotEvery` determines which of these

simapp/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func NewSimApp(
150150
}
151151

152152
// init params keeper and subspaces
153-
app.ParamsKeeper = params.NewKeeper(app.cdc, keys[params.StoreKey], tkeys[params.TStoreKey])
153+
app.ParamsKeeper = params.NewKeeper(appCodec.Params, keys[params.StoreKey], tkeys[params.TStoreKey])
154154
app.subspaces[auth.ModuleName] = app.ParamsKeeper.Subspace(auth.DefaultParamspace)
155155
app.subspaces[bank.ModuleName] = app.ParamsKeeper.Subspace(bank.DefaultParamspace)
156156
app.subspaces[staking.ModuleName] = app.ParamsKeeper.Subspace(staking.DefaultParamspace)

simapp/codec.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
sdk "github.com/cosmos/cosmos-sdk/types"
66
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
77
distr "github.com/cosmos/cosmos-sdk/x/distribution"
8+
"github.com/cosmos/cosmos-sdk/x/params"
89
"github.com/cosmos/cosmos-sdk/x/staking"
910
)
1011

@@ -13,6 +14,7 @@ import (
1314
type AppCodec struct {
1415
amino *codec.Codec
1516

17+
Params *params.Codec
1618
Staking *staking.Codec
1719
Distribution *distr.Codec
1820
}
@@ -22,6 +24,7 @@ func NewAppCodec() *AppCodec {
2224

2325
return &AppCodec{
2426
amino: amino,
27+
Params: params.NewCodec(amino),
2528
Staking: staking.NewCodec(amino),
2629
Distribution: distr.NewCodec(amino),
2730
}

x/distribution/keeper/test_common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func CreateTestInputAdvanced(
126126
blacklistedAddrs[distrAcc.GetAddress().String()] = true
127127

128128
cdc := MakeTestCodec()
129-
pk := params.NewKeeper(cdc, keyParams, tkeyParams)
129+
pk := params.NewKeeper(params.ModuleCdc, keyParams, tkeyParams)
130130

131131
ctx := sdk.NewContext(ms, abci.Header{ChainID: "foochainid"}, isCheckTx, log.NewNopLogger())
132132
accountKeeper := auth.NewAccountKeeper(cdc, keyAcc, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount)

x/gov/keeper/test_common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func createTestInput(
146146
blacklistedAddrs[notBondedPool.GetAddress().String()] = true
147147
blacklistedAddrs[bondPool.GetAddress().String()] = true
148148

149-
pk := params.NewKeeper(cdc, keyParams, tkeyParams)
149+
pk := params.NewKeeper(params.ModuleCdc, keyParams, tkeyParams)
150150
accountKeeper := auth.NewAccountKeeper(cdc, keyAcc, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount)
151151
bankKeeper := bank.NewBaseKeeper(cdc, keyBank, accountKeeper, pk.Subspace(bank.DefaultParamspace), blacklistedAddrs)
152152
supplyKeeper := supply.NewKeeper(cdc, keySupply, accountKeeper, bankKeeper, maccPerms)

x/mock/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func NewApp() *App {
6969
TotalCoinsSupply: sdk.NewCoins(),
7070
}
7171

72-
app.ParamsKeeper = params.NewKeeper(app.Cdc, app.KeyParams, app.TKeyParams)
72+
app.ParamsKeeper = params.NewKeeper(params.ModuleCdc, app.KeyParams, app.TKeyParams)
7373
app.AccountKeeper = auth.NewAccountKeeper(
7474
app.Cdc,
7575
app.KeyAccount,

x/params/alias.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ var (
3030
NewParameterChangeProposal = types.NewParameterChangeProposal
3131
NewParamChange = types.NewParamChange
3232
ValidateChanges = types.ValidateChanges
33+
NewCodec = types.NewCodec
3334

3435
// variable aliases
3536
ModuleCdc = types.ModuleCdc
3637
)
3738

3839
type (
40+
Codec = types.Codec
3941
ParamSetPair = subspace.ParamSetPair
4042
ParamSetPairs = subspace.ParamSetPairs
4143
ParamSet = subspace.ParamSet

x/params/commmon_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ type s struct {
1717
I int
1818
}
1919

20-
func createTestCodec() *codec.Codec {
20+
func createTestCodec() codec.Marshaler {
2121
cdc := codec.New()
2222
sdk.RegisterCodec(cdc)
2323
cdc.RegisterConcrete(s{}, "test/s", nil)
2424
cdc.RegisterConcrete(invalid{}, "test/invalid", nil)
25-
return cdc
25+
return NewCodec(cdc)
2626
}
2727

2828
func defaultContext(key sdk.StoreKey, tkey sdk.StoreKey) sdk.Context {
@@ -38,7 +38,7 @@ func defaultContext(key sdk.StoreKey, tkey sdk.StoreKey) sdk.Context {
3838
return ctx
3939
}
4040

41-
func testComponents() (*codec.Codec, sdk.Context, sdk.StoreKey, sdk.StoreKey, Keeper) {
41+
func testComponents() (codec.Marshaler, sdk.Context, sdk.StoreKey, sdk.StoreKey, Keeper) {
4242
cdc := createTestCodec()
4343
mkey := sdk.NewKVStoreKey("test")
4444
tkey := sdk.NewTransientStoreKey("transient_test")

x/params/keeper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import (
1313

1414
// Keeper of the global paramstore
1515
type Keeper struct {
16-
cdc *codec.Codec
16+
cdc codec.Marshaler
1717
key sdk.StoreKey
1818
tkey sdk.StoreKey
1919
spaces map[string]*Subspace
2020
}
2121

2222
// NewKeeper constructs a params keeper
23-
func NewKeeper(cdc *codec.Codec, key, tkey sdk.StoreKey) Keeper {
23+
func NewKeeper(cdc codec.Marshaler, key, tkey sdk.StoreKey) Keeper {
2424
return Keeper{
2525
cdc: cdc,
2626
key: key,

x/params/proposal_handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func newTestInput(t *testing.T) testInput {
7474
err := cms.LoadLatestVersion()
7575
require.Nil(t, err)
7676

77-
keeper := params.NewKeeper(cdc, keyParams, tKeyParams)
77+
keeper := params.NewKeeper(types.ModuleCdc, keyParams, tKeyParams)
7878
ctx := sdk.NewContext(cms, abci.Header{}, false, log.NewNopLogger())
7979

8080
return testInput{ctx, cdc, keeper}

0 commit comments

Comments
 (0)