From c47055cb96ba361d5f086905131d74cf68142e67 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 12 Mar 2020 22:18:50 +0100 Subject: [PATCH 01/31] change abci file to use BinaryBare --- baseapp/abci.go | 2 +- baseapp/baseapp_test.go | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 57bcec661eff..834930196df5 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -331,7 +331,7 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) abci.Res return abci.ResponseQuery{ Codespace: sdkerrors.RootCodespace, Height: req.Height, - Value: codec.Cdc.MustMarshalBinaryLengthPrefixed(gInfo.GasUsed), + Value: codec.Cdc.MustMarshalBinaryBare(gInfo.GasUsed), } case "version": diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 840531865d31..99f1c8d40047 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -386,7 +386,7 @@ func TestTxDecoder(t *testing.T) { app := newBaseApp(t.Name()) tx := newTxCounter(1, 0) - txBytes := codec.MustMarshalBinaryLengthPrefixed(tx) + txBytes := codec.MustMarshalBinaryBare(tx) dTx, err := app.txDecoder(txBytes) require.NoError(t, err) @@ -625,7 +625,7 @@ func testTxDecoder(cdc *codec.Codec) sdk.TxDecoder { return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "tx bytes are empty") } - err := cdc.UnmarshalBinaryLengthPrefixed(txBytes, &tx) + err := cdc.UnmarshalBinaryBare(txBytes, &tx) if err != nil { return nil, sdkerrors.ErrTxDecode } @@ -733,7 +733,7 @@ func TestCheckTx(t *testing.T) { for i := int64(0); i < nTxs; i++ { tx := newTxCounter(i, 0) - txBytes, err := codec.MarshalBinaryLengthPrefixed(tx) + txBytes, err := codec.MarshalBinaryBare(tx) require.NoError(t, err) r := app.CheckTx(abci.RequestCheckTx{Tx: txBytes}) assert.True(t, r.IsOK(), fmt.Sprintf("%v", r)) @@ -787,7 +787,7 @@ func TestDeliverTx(t *testing.T) { counter := int64(blockN*txPerHeight + i) tx := newTxCounter(counter, counter) - txBytes, err := codec.MarshalBinaryLengthPrefixed(tx) + txBytes, err := codec.MarshalBinaryBare(tx) require.NoError(t, err) res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) @@ -831,7 +831,7 @@ func TestMultiMsgDeliverTx(t *testing.T) { header := abci.Header{Height: 1} app.BeginBlock(abci.RequestBeginBlock{Header: header}) tx := newTxCounter(0, 0, 1, 2) - txBytes, err := codec.MarshalBinaryLengthPrefixed(tx) + txBytes, err := codec.MarshalBinaryBare(tx) require.NoError(t, err) res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) require.True(t, res.IsOK(), fmt.Sprintf("%v", res)) @@ -851,7 +851,7 @@ func TestMultiMsgDeliverTx(t *testing.T) { tx = newTxCounter(1, 3) tx.Msgs = append(tx.Msgs, msgCounter2{0}) tx.Msgs = append(tx.Msgs, msgCounter2{1}) - txBytes, err = codec.MarshalBinaryLengthPrefixed(tx) + txBytes, err = codec.MarshalBinaryBare(tx) require.NoError(t, err) res = app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) require.True(t, res.IsOK(), fmt.Sprintf("%v", res)) @@ -912,7 +912,7 @@ func TestSimulateTx(t *testing.T) { app.BeginBlock(abci.RequestBeginBlock{Header: header}) tx := newTxCounter(count, count) - txBytes, err := cdc.MarshalBinaryLengthPrefixed(tx) + txBytes, err := cdc.MarshalBinaryBare(tx) require.Nil(t, err) // simulate a message, check gas reported @@ -936,7 +936,7 @@ func TestSimulateTx(t *testing.T) { require.True(t, queryResult.IsOK(), queryResult.Log) var res uint64 - err = codec.Cdc.UnmarshalBinaryLengthPrefixed(queryResult.Value, &res) + err = codec.Cdc.UnmarshalBinaryBare(queryResult.Value, &res) require.NoError(t, err) require.Equal(t, gasConsumed, res) app.EndBlock(abci.RequestEndBlock{}) @@ -1259,7 +1259,7 @@ func TestBaseAppAnteHandler(t *testing.T) { // the next txs ante handler execution (anteHandlerTxTest). tx := newTxCounter(0, 0) tx.setFailOnAnte(true) - txBytes, err := cdc.MarshalBinaryLengthPrefixed(tx) + txBytes, err := cdc.MarshalBinaryBare(tx) require.NoError(t, err) res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) require.False(t, res.IsOK(), fmt.Sprintf("%v", res)) @@ -1273,7 +1273,7 @@ func TestBaseAppAnteHandler(t *testing.T) { tx = newTxCounter(0, 0) tx.setFailOnHandler(true) - txBytes, err = cdc.MarshalBinaryLengthPrefixed(tx) + txBytes, err = cdc.MarshalBinaryBare(tx) require.NoError(t, err) res = app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) @@ -1288,7 +1288,7 @@ func TestBaseAppAnteHandler(t *testing.T) { // implicitly checked by previous tx executions tx = newTxCounter(1, 0) - txBytes, err = cdc.MarshalBinaryLengthPrefixed(tx) + txBytes, err = cdc.MarshalBinaryBare(tx) require.NoError(t, err) res = app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) @@ -1529,7 +1529,7 @@ func TestWithRouter(t *testing.T) { counter := int64(blockN*txPerHeight + i) tx := newTxCounter(counter, counter) - txBytes, err := codec.MarshalBinaryLengthPrefixed(tx) + txBytes, err := codec.MarshalBinaryBare(tx) require.NoError(t, err) res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) From 0ba84260a369e38ac5d31a0945d914fb24dfd815 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 12 Mar 2020 23:06:50 +0100 Subject: [PATCH 02/31] change all calls to EncodeLengthPrefixed to BinaryBare in distribution keeper store. --- x/distribution/keeper/store.go | 38 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/x/distribution/keeper/store.go b/x/distribution/keeper/store.go index ffdd807163ed..ef039f1904a8 100644 --- a/x/distribution/keeper/store.go +++ b/x/distribution/keeper/store.go @@ -50,14 +50,14 @@ func (k Keeper) GetFeePool(ctx sdk.Context) (feePool types.FeePool) { if b == nil { panic("Stored fee pool should not have been nil") } - k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &feePool) + k.cdc.MustUnmarshalBinaryBare(b, &feePool) return } // set the global fee pool distribution info func (k Keeper) SetFeePool(ctx sdk.Context, feePool types.FeePool) { store := ctx.KVStore(k.storeKey) - b := k.cdc.MustMarshalBinaryLengthPrefixed(&feePool) + b := k.cdc.MustMarshalBinaryBare(&feePool) store.Set(types.FeePoolKey, b) } @@ -71,14 +71,14 @@ func (k Keeper) GetPreviousProposerConsAddr(ctx sdk.Context) sdk.ConsAddress { } addrValue := gogotypes.BytesValue{} - k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &addrValue) - return sdk.ConsAddress(addrValue.GetValue()) + k.cdc.MustUnmarshalBinaryBare(bz, &addrValue) + return addrValue.GetValue() } // set the proposer public key for this block func (k Keeper) SetPreviousProposerConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.BytesValue{Value: consAddr}) + bz := k.cdc.MustMarshalBinaryBare(&gogotypes.BytesValue{Value: consAddr}) store.Set(types.ProposerKey, bz) } @@ -86,14 +86,14 @@ func (k Keeper) SetPreviousProposerConsAddr(ctx sdk.Context, consAddr sdk.ConsAd func (k Keeper) GetDelegatorStartingInfo(ctx sdk.Context, val sdk.ValAddress, del sdk.AccAddress) (period types.DelegatorStartingInfo) { store := ctx.KVStore(k.storeKey) b := store.Get(types.GetDelegatorStartingInfoKey(val, del)) - k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &period) + k.cdc.MustUnmarshalBinaryBare(b, &period) return } // set the starting info associated with a delegator func (k Keeper) SetDelegatorStartingInfo(ctx sdk.Context, val sdk.ValAddress, del sdk.AccAddress, period types.DelegatorStartingInfo) { store := ctx.KVStore(k.storeKey) - b := k.cdc.MustMarshalBinaryLengthPrefixed(&period) + b := k.cdc.MustMarshalBinaryBare(&period) store.Set(types.GetDelegatorStartingInfoKey(val, del), b) } @@ -116,7 +116,7 @@ func (k Keeper) IterateDelegatorStartingInfos(ctx sdk.Context, handler func(val defer iter.Close() for ; iter.Valid(); iter.Next() { var info types.DelegatorStartingInfo - k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &info) + k.cdc.MustUnmarshalBinaryBare(iter.Value(), &info) val, del := types.GetDelegatorStartingInfoAddresses(iter.Key()) if handler(val, del, info) { break @@ -128,14 +128,14 @@ func (k Keeper) IterateDelegatorStartingInfos(ctx sdk.Context, handler func(val func (k Keeper) GetValidatorHistoricalRewards(ctx sdk.Context, val sdk.ValAddress, period uint64) (rewards types.ValidatorHistoricalRewards) { store := ctx.KVStore(k.storeKey) b := store.Get(types.GetValidatorHistoricalRewardsKey(val, period)) - k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &rewards) + k.cdc.MustUnmarshalBinaryBare(b, &rewards) return } // set historical rewards for a particular period func (k Keeper) SetValidatorHistoricalRewards(ctx sdk.Context, val sdk.ValAddress, period uint64, rewards types.ValidatorHistoricalRewards) { store := ctx.KVStore(k.storeKey) - b := k.cdc.MustMarshalBinaryLengthPrefixed(&rewards) + b := k.cdc.MustMarshalBinaryBare(&rewards) store.Set(types.GetValidatorHistoricalRewardsKey(val, period), b) } @@ -146,7 +146,7 @@ func (k Keeper) IterateValidatorHistoricalRewards(ctx sdk.Context, handler func( defer iter.Close() for ; iter.Valid(); iter.Next() { var rewards types.ValidatorHistoricalRewards - k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &rewards) + k.cdc.MustUnmarshalBinaryBare(iter.Value(), &rewards) addr, period := types.GetValidatorHistoricalRewardsAddressPeriod(iter.Key()) if handler(addr, period, rewards) { break @@ -187,7 +187,7 @@ func (k Keeper) GetValidatorHistoricalReferenceCount(ctx sdk.Context) (count uin defer iter.Close() for ; iter.Valid(); iter.Next() { var rewards types.ValidatorHistoricalRewards - k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &rewards) + k.cdc.MustUnmarshalBinaryBare(iter.Value(), &rewards) count += uint64(rewards.ReferenceCount) } return @@ -197,14 +197,14 @@ func (k Keeper) GetValidatorHistoricalReferenceCount(ctx sdk.Context) (count uin func (k Keeper) GetValidatorCurrentRewards(ctx sdk.Context, val sdk.ValAddress) (rewards types.ValidatorCurrentRewards) { store := ctx.KVStore(k.storeKey) b := store.Get(types.GetValidatorCurrentRewardsKey(val)) - k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &rewards) + k.cdc.MustUnmarshalBinaryBare(b, &rewards) return } // set current rewards for a validator func (k Keeper) SetValidatorCurrentRewards(ctx sdk.Context, val sdk.ValAddress, rewards types.ValidatorCurrentRewards) { store := ctx.KVStore(k.storeKey) - b := k.cdc.MustMarshalBinaryLengthPrefixed(&rewards) + b := k.cdc.MustMarshalBinaryBare(&rewards) store.Set(types.GetValidatorCurrentRewardsKey(val), b) } @@ -221,7 +221,7 @@ func (k Keeper) IterateValidatorCurrentRewards(ctx sdk.Context, handler func(val defer iter.Close() for ; iter.Valid(); iter.Next() { var rewards types.ValidatorCurrentRewards - k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &rewards) + k.cdc.MustUnmarshalBinaryBare(iter.Value(), &rewards) addr := types.GetValidatorCurrentRewardsAddress(iter.Key()) if handler(addr, rewards) { break @@ -236,7 +236,7 @@ func (k Keeper) GetValidatorAccumulatedCommission(ctx sdk.Context, val sdk.ValAd if b == nil { return types.ValidatorAccumulatedCommission{} } - k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &commission) + k.cdc.MustUnmarshalBinaryBare(b, &commission) return } @@ -246,9 +246,9 @@ func (k Keeper) SetValidatorAccumulatedCommission(ctx sdk.Context, val sdk.ValAd store := ctx.KVStore(k.storeKey) if commission.Commission.IsZero() { - bz = k.cdc.MustMarshalBinaryLengthPrefixed(&types.ValidatorAccumulatedCommission{}) + bz = k.cdc.MustMarshalBinaryBare(&types.ValidatorAccumulatedCommission{}) } else { - bz = k.cdc.MustMarshalBinaryLengthPrefixed(&commission) + bz = k.cdc.MustMarshalBinaryBare(&commission) } store.Set(types.GetValidatorAccumulatedCommissionKey(val), bz) @@ -267,7 +267,7 @@ func (k Keeper) IterateValidatorAccumulatedCommissions(ctx sdk.Context, handler defer iter.Close() for ; iter.Valid(); iter.Next() { var commission types.ValidatorAccumulatedCommission - k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &commission) + k.cdc.MustUnmarshalBinaryBare(iter.Value(), &commission) addr := types.GetValidatorAccumulatedCommissionAddress(iter.Key()) if handler(addr, commission) { break From 3144b4730957241dc5545d7ddbd81abf8a6495e7 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 12 Mar 2020 23:13:07 +0100 Subject: [PATCH 03/31] change all calls to EncodeLengthPrefixed to BinaryBare in mint keeper store. --- x/mint/keeper/keeper.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/mint/keeper/keeper.go b/x/mint/keeper/keeper.go index 9c708f6b5bff..73652e41c88b 100644 --- a/x/mint/keeper/keeper.go +++ b/x/mint/keeper/keeper.go @@ -57,14 +57,14 @@ func (k Keeper) GetMinter(ctx sdk.Context) (minter types.Minter) { panic("stored minter should not have been nil") } - k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &minter) + k.cdc.MustUnmarshalBinaryBare(b, &minter) return } // set the minter func (k Keeper) SetMinter(ctx sdk.Context, minter types.Minter) { store := ctx.KVStore(k.storeKey) - b := k.cdc.MustMarshalBinaryLengthPrefixed(&minter) + b := k.cdc.MustMarshalBinaryBare(&minter) store.Set(types.MinterKey, b) } From 6af1f7e8de0bf1e612e2da583f4c3f48fc3bfd2b Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 12 Mar 2020 23:16:28 +0100 Subject: [PATCH 04/31] change all calls to EncodeLengthPrefixed to BinaryBare in auth keeper store. --- x/auth/keeper/keeper.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index df5228fa7f03..e07e9dfba902 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -77,7 +77,7 @@ func (ak AccountKeeper) GetNextAccountNumber(ctx sdk.Context) uint64 { } else { val := gogotypes.UInt64Value{} - err := ak.cdc.UnmarshalBinaryLengthPrefixed(bz, &val) + err := ak.cdc.UnmarshalBinaryBare(bz, &val) if err != nil { panic(err) } @@ -85,7 +85,7 @@ func (ak AccountKeeper) GetNextAccountNumber(ctx sdk.Context) uint64 { accNumber = val.GetValue() } - bz = ak.cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.UInt64Value{Value: accNumber + 1}) + bz = ak.cdc.MustMarshalBinaryBare(&gogotypes.UInt64Value{Value: accNumber + 1}) store.Set(types.GlobalAccountNumberKey, bz) return accNumber From 12fce2245de504524c6c19847c099b30ccc7c95c Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 12 Mar 2020 23:20:21 +0100 Subject: [PATCH 05/31] change all calls to EncodeLengthPrefixed to BinaryBare in distribution keeper store. --- x/distribution/keeper/store.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/x/distribution/keeper/store.go b/x/distribution/keeper/store.go index ef039f1904a8..302e2ee81e92 100644 --- a/x/distribution/keeper/store.go +++ b/x/distribution/keeper/store.go @@ -279,14 +279,14 @@ func (k Keeper) IterateValidatorAccumulatedCommissions(ctx sdk.Context, handler func (k Keeper) GetValidatorOutstandingRewards(ctx sdk.Context, val sdk.ValAddress) (rewards types.ValidatorOutstandingRewards) { store := ctx.KVStore(k.storeKey) bz := store.Get(types.GetValidatorOutstandingRewardsKey(val)) - k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &rewards) + k.cdc.MustUnmarshalBinaryBare(bz, &rewards) return } // set validator outstanding rewards func (k Keeper) SetValidatorOutstandingRewards(ctx sdk.Context, val sdk.ValAddress, rewards types.ValidatorOutstandingRewards) { store := ctx.KVStore(k.storeKey) - b := k.cdc.MustMarshalBinaryLengthPrefixed(&rewards) + b := k.cdc.MustMarshalBinaryBare(&rewards) store.Set(types.GetValidatorOutstandingRewardsKey(val), b) } @@ -303,7 +303,7 @@ func (k Keeper) IterateValidatorOutstandingRewards(ctx sdk.Context, handler func defer iter.Close() for ; iter.Valid(); iter.Next() { rewards := types.ValidatorOutstandingRewards{} - k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &rewards) + k.cdc.MustUnmarshalBinaryBare(iter.Value(), &rewards) addr := types.GetValidatorOutstandingRewardsAddress(iter.Key()) if handler(addr, rewards) { break @@ -318,14 +318,14 @@ func (k Keeper) GetValidatorSlashEvent(ctx sdk.Context, val sdk.ValAddress, heig if b == nil { return types.ValidatorSlashEvent{}, false } - k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &event) + k.cdc.MustUnmarshalBinaryBare(b, &event) return event, true } // set slash event for height func (k Keeper) SetValidatorSlashEvent(ctx sdk.Context, val sdk.ValAddress, height, period uint64, event types.ValidatorSlashEvent) { store := ctx.KVStore(k.storeKey) - b := k.cdc.MustMarshalBinaryLengthPrefixed(&event) + b := k.cdc.MustMarshalBinaryBare(&event) store.Set(types.GetValidatorSlashEventKey(val, height, period), b) } @@ -340,7 +340,7 @@ func (k Keeper) IterateValidatorSlashEventsBetween(ctx sdk.Context, val sdk.ValA defer iter.Close() for ; iter.Valid(); iter.Next() { var event types.ValidatorSlashEvent - k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &event) + k.cdc.MustUnmarshalBinaryBare(iter.Value(), &event) _, height := types.GetValidatorSlashEventAddressHeight(iter.Key()) if handler(height, event) { break @@ -355,7 +355,7 @@ func (k Keeper) IterateValidatorSlashEvents(ctx sdk.Context, handler func(val sd defer iter.Close() for ; iter.Valid(); iter.Next() { var event types.ValidatorSlashEvent - k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &event) + k.cdc.MustUnmarshalBinaryBare(iter.Value(), &event) val, height := types.GetValidatorSlashEventAddressHeight(iter.Key()) if handler(val, height, event) { break From 81ecf2eed7f0cdc4becade00c17d415fb96f6faf Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 12 Mar 2020 23:22:47 +0100 Subject: [PATCH 06/31] change all calls to EncodeLengthPrefixed to BinaryBare in staking keeper store. --- x/staking/keeper/keeper.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index b809e070ca95..feddaf3b96f8 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -85,13 +85,13 @@ func (k Keeper) GetLastTotalPower(ctx sdk.Context) sdk.Int { } ip := sdk.IntProto{} - k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &ip) + k.cdc.MustUnmarshalBinaryBare(bz, &ip) return ip.Int } // Set the last total validator power. func (k Keeper) SetLastTotalPower(ctx sdk.Context, power sdk.Int) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(&sdk.IntProto{Int: power}) + bz := k.cdc.MustMarshalBinaryBare(&sdk.IntProto{Int: power}) store.Set(types.LastTotalPowerKey, bz) } From d967f266268ff629fb55d8e5ef77df1e5f0b74dd Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 12 Mar 2020 23:39:56 +0100 Subject: [PATCH 07/31] change all calls to EncodeLengthPrefixed to BinaryBare in staking keeper store. --- x/staking/keeper/delegation.go | 12 ++++++------ x/staking/keeper/val_state_change.go | 2 +- x/staking/keeper/validator.go | 14 +++++++------- x/staking/keeper/validator_test.go | 1 - 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/x/staking/keeper/delegation.go b/x/staking/keeper/delegation.go index e5c1912daf36..469bb5eaba04 100644 --- a/x/staking/keeper/delegation.go +++ b/x/staking/keeper/delegation.go @@ -223,14 +223,14 @@ func (k Keeper) GetUBDQueueTimeSlice(ctx sdk.Context, timestamp time.Time) (dvPa } pairs := types.DVPairs{} - k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &pairs) + k.cdc.MustUnmarshalBinaryBare(bz, &pairs) return pairs.Pairs } // Sets a specific unbonding queue timeslice. func (k Keeper) SetUBDQueueTimeSlice(ctx sdk.Context, timestamp time.Time, keys []types.DVPair) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(&types.DVPairs{Pairs: keys}) + bz := k.cdc.MustMarshalBinaryBare(&types.DVPairs{Pairs: keys}) store.Set(types.GetUnbondingDelegationTimeKey(timestamp), bz) } @@ -265,7 +265,7 @@ func (k Keeper) DequeueAllMatureUBDQueue(ctx sdk.Context, currTime time.Time) (m for ; unbondingTimesliceIterator.Valid(); unbondingTimesliceIterator.Next() { timeslice := types.DVPairs{} value := unbondingTimesliceIterator.Value() - k.cdc.MustUnmarshalBinaryLengthPrefixed(value, ×lice) + k.cdc.MustUnmarshalBinaryBare(value, ×lice) matureUnbonds = append(matureUnbonds, timeslice.Pairs...) store.Delete(unbondingTimesliceIterator.Key()) @@ -412,14 +412,14 @@ func (k Keeper) GetRedelegationQueueTimeSlice(ctx sdk.Context, timestamp time.Ti } triplets := types.DVVTriplets{} - k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &triplets) + k.cdc.MustUnmarshalBinaryBare(bz, &triplets) return triplets.Triplets } // Sets a specific redelegation queue timeslice. func (k Keeper) SetRedelegationQueueTimeSlice(ctx sdk.Context, timestamp time.Time, keys []types.DVVTriplet) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(&types.DVVTriplets{Triplets: keys}) + bz := k.cdc.MustMarshalBinaryBare(&types.DVVTriplets{Triplets: keys}) store.Set(types.GetRedelegationTimeKey(timestamp), bz) } @@ -457,7 +457,7 @@ func (k Keeper) DequeueAllMatureRedelegationQueue(ctx sdk.Context, currTime time for ; redelegationTimesliceIterator.Valid(); redelegationTimesliceIterator.Next() { timeslice := types.DVVTriplets{} value := redelegationTimesliceIterator.Value() - k.cdc.MustUnmarshalBinaryLengthPrefixed(value, ×lice) + k.cdc.MustUnmarshalBinaryBare(value, ×lice) matureRedelegations = append(matureRedelegations, timeslice.Triplets...) store.Delete(redelegationTimesliceIterator.Key()) diff --git a/x/staking/keeper/val_state_change.go b/x/staking/keeper/val_state_change.go index 9927d6ed2329..34325024069b 100644 --- a/x/staking/keeper/val_state_change.go +++ b/x/staking/keeper/val_state_change.go @@ -138,7 +138,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab oldPowerBytes, found := last[valAddrBytes] newPower := validator.ConsensusPower() - newPowerBytes := k.cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.Int64Value{Value: newPower}) + newPowerBytes := k.cdc.MustMarshalBinaryBare(&gogotypes.Int64Value{Value: newPower}) // update the validator set if power has changed if !found || !bytes.Equal(oldPowerBytes, newPowerBytes) { diff --git a/x/staking/keeper/validator.go b/x/staking/keeper/validator.go index c8d4d597e9b3..3e3e635df014 100644 --- a/x/staking/keeper/validator.go +++ b/x/staking/keeper/validator.go @@ -278,14 +278,14 @@ func (k Keeper) GetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress) } intV := gogotypes.Int64Value{} - k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &intV) + k.cdc.MustUnmarshalBinaryBare(bz, &intV) return intV.GetValue() } // Set the last validator power. func (k Keeper) SetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress, power int64) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.Int64Value{Value: power}) + bz := k.cdc.MustMarshalBinaryBare(&gogotypes.Int64Value{Value: power}) store.Set(types.GetLastValidatorPowerKey(operator), bz) } @@ -311,7 +311,7 @@ func (k Keeper) IterateLastValidatorPowers(ctx sdk.Context, handler func(operato addr := sdk.ValAddress(iter.Key()[len(types.LastValidatorPowerKey):]) intV := &gogotypes.Int64Value{} - k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), intV) + k.cdc.MustUnmarshalBinaryBare(iter.Value(), intV) if handler(addr, intV.GetValue()) { break } @@ -358,14 +358,14 @@ func (k Keeper) GetValidatorQueueTimeSlice(ctx sdk.Context, timestamp time.Time) } va := sdk.ValAddresses{} - k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &va) + k.cdc.MustUnmarshalBinaryBare(bz, &va) return va.Addresses } // Sets a specific validator queue timeslice. func (k Keeper) SetValidatorQueueTimeSlice(ctx sdk.Context, timestamp time.Time, keys []sdk.ValAddress) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(&sdk.ValAddresses{Addresses: keys}) + bz := k.cdc.MustMarshalBinaryBare(&sdk.ValAddresses{Addresses: keys}) store.Set(types.GetValidatorQueueTimeKey(timestamp), bz) } @@ -413,7 +413,7 @@ func (k Keeper) GetAllMatureValidatorQueue(ctx sdk.Context, currTime time.Time) for ; validatorTimesliceIterator.Valid(); validatorTimesliceIterator.Next() { timeslice := sdk.ValAddresses{} - k.cdc.MustUnmarshalBinaryLengthPrefixed(validatorTimesliceIterator.Value(), ×lice) + k.cdc.MustUnmarshalBinaryBare(validatorTimesliceIterator.Value(), ×lice) matureValsAddrs = append(matureValsAddrs, timeslice.Addresses...) } @@ -429,7 +429,7 @@ func (k Keeper) UnbondAllMatureValidatorQueue(ctx sdk.Context) { for ; validatorTimesliceIterator.Valid(); validatorTimesliceIterator.Next() { timeslice := sdk.ValAddresses{} - k.cdc.MustUnmarshalBinaryLengthPrefixed(validatorTimesliceIterator.Value(), ×lice) + k.cdc.MustUnmarshalBinaryBare(validatorTimesliceIterator.Value(), ×lice) for _, valAddr := range timeslice.Addresses { val, found := k.GetValidator(ctx, valAddr) diff --git a/x/staking/keeper/validator_test.go b/x/staking/keeper/validator_test.go index f7295a5421de..d6518c722df4 100644 --- a/x/staking/keeper/validator_test.go +++ b/x/staking/keeper/validator_test.go @@ -7,7 +7,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/simapp" From 950402e18bf4142e0c1b263f9344cd0c8cf2719d Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 12 Mar 2020 23:43:45 +0100 Subject: [PATCH 08/31] change all calls to EncodeLengthPrefixed to BinaryBare in gov keeper store. --- x/gov/keeper/deposit.go | 8 ++++---- x/gov/keeper/vote.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/x/gov/keeper/deposit.go b/x/gov/keeper/deposit.go index d1a55140d590..28783f59cb63 100644 --- a/x/gov/keeper/deposit.go +++ b/x/gov/keeper/deposit.go @@ -16,14 +16,14 @@ func (keeper Keeper) GetDeposit(ctx sdk.Context, proposalID uint64, depositorAdd return deposit, false } - keeper.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &deposit) + keeper.cdc.MustUnmarshalBinaryBare(bz, &deposit) return deposit, true } // SetDeposit sets a Deposit to the gov store func (keeper Keeper) SetDeposit(ctx sdk.Context, deposit types.Deposit) { store := ctx.KVStore(keeper.storeKey) - bz := keeper.cdc.MustMarshalBinaryLengthPrefixed(&deposit) + bz := keeper.cdc.MustMarshalBinaryBare(&deposit) store.Set(types.DepositKey(deposit.ProposalID, deposit.Depositor), bz) } @@ -68,7 +68,7 @@ func (keeper Keeper) IterateAllDeposits(ctx sdk.Context, cb func(deposit types.D defer iterator.Close() for ; iterator.Valid(); iterator.Next() { var deposit types.Deposit - keeper.cdc.MustUnmarshalBinaryLengthPrefixed(iterator.Value(), &deposit) + keeper.cdc.MustUnmarshalBinaryBare(iterator.Value(), &deposit) if cb(deposit) { break @@ -84,7 +84,7 @@ func (keeper Keeper) IterateDeposits(ctx sdk.Context, proposalID uint64, cb func defer iterator.Close() for ; iterator.Valid(); iterator.Next() { var deposit types.Deposit - keeper.cdc.MustUnmarshalBinaryLengthPrefixed(iterator.Value(), &deposit) + keeper.cdc.MustUnmarshalBinaryBare(iterator.Value(), &deposit) if cb(deposit) { break diff --git a/x/gov/keeper/vote.go b/x/gov/keeper/vote.go index 819130e6473b..2abd6ca713a9 100644 --- a/x/gov/keeper/vote.go +++ b/x/gov/keeper/vote.go @@ -62,14 +62,14 @@ func (keeper Keeper) GetVote(ctx sdk.Context, proposalID uint64, voterAddr sdk.A return vote, false } - keeper.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &vote) + keeper.cdc.MustUnmarshalBinaryBare(bz, &vote) return vote, true } // SetVote sets a Vote to the gov store func (keeper Keeper) SetVote(ctx sdk.Context, vote types.Vote) { store := ctx.KVStore(keeper.storeKey) - bz := keeper.cdc.MustMarshalBinaryLengthPrefixed(&vote) + bz := keeper.cdc.MustMarshalBinaryBare(&vote) store.Set(types.VoteKey(vote.ProposalID, vote.Voter), bz) } @@ -81,7 +81,7 @@ func (keeper Keeper) IterateAllVotes(ctx sdk.Context, cb func(vote types.Vote) ( defer iterator.Close() for ; iterator.Valid(); iterator.Next() { var vote types.Vote - keeper.cdc.MustUnmarshalBinaryLengthPrefixed(iterator.Value(), &vote) + keeper.cdc.MustUnmarshalBinaryBare(iterator.Value(), &vote) if cb(vote) { break @@ -97,7 +97,7 @@ func (keeper Keeper) IterateVotes(ctx sdk.Context, proposalID uint64, cb func(vo defer iterator.Close() for ; iterator.Valid(); iterator.Next() { var vote types.Vote - keeper.cdc.MustUnmarshalBinaryLengthPrefixed(iterator.Value(), &vote) + keeper.cdc.MustUnmarshalBinaryBare(iterator.Value(), &vote) if cb(vote) { break From 9b5f9a524eaf48cb3dc2209da36c06d17ff5d26b Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 12 Mar 2020 23:58:20 +0100 Subject: [PATCH 09/31] change all calls to EncodeLengthPrefixed to BinaryBare in slashing keeper store. --- x/slashing/keeper/keeper.go | 4 ++-- x/slashing/keeper/signing_info.go | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/x/slashing/keeper/keeper.go b/x/slashing/keeper/keeper.go index 43f21a516edb..f34756afc853 100644 --- a/x/slashing/keeper/keeper.go +++ b/x/slashing/keeper/keeper.go @@ -53,7 +53,7 @@ func (k Keeper) GetPubkey(ctx sdk.Context, address crypto.Address) (crypto.PubKe store := ctx.KVStore(k.storeKey) var pubkey gogotypes.StringValue - err := k.cdc.UnmarshalBinaryLengthPrefixed(store.Get(types.GetAddrPubkeyRelationKey(address)), &pubkey) + err := k.cdc.UnmarshalBinaryBare(store.Get(types.GetAddrPubkeyRelationKey(address)), &pubkey) if err != nil { return nil, fmt.Errorf("address %s not found", sdk.ConsAddress(address)) } @@ -97,7 +97,7 @@ func (k Keeper) Jail(ctx sdk.Context, consAddr sdk.ConsAddress) { func (k Keeper) setAddrPubkeyRelation(ctx sdk.Context, addr crypto.Address, pubkey string) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.StringValue{Value: pubkey}) + bz := k.cdc.MustMarshalBinaryBare(&gogotypes.StringValue{Value: pubkey}) store.Set(types.GetAddrPubkeyRelationKey(addr), bz) } diff --git a/x/slashing/keeper/signing_info.go b/x/slashing/keeper/signing_info.go index 0e1a82c62fa2..860b3e1315cd 100644 --- a/x/slashing/keeper/signing_info.go +++ b/x/slashing/keeper/signing_info.go @@ -18,7 +18,7 @@ func (k Keeper) GetValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress found = false return } - k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &info) + k.cdc.MustUnmarshalBinaryBare(bz, &info) found = true return } @@ -33,7 +33,7 @@ func (k Keeper) HasValidatorSigningInfo(ctx sdk.Context, consAddr sdk.ConsAddres // SetValidatorSigningInfo sets the validator signing info to a consensus address key func (k Keeper) SetValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress, info types.ValidatorSigningInfo) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(&info) + bz := k.cdc.MustMarshalBinaryBare(&info) store.Set(types.GetValidatorSigningInfoKey(address), bz) } @@ -47,7 +47,7 @@ func (k Keeper) IterateValidatorSigningInfos(ctx sdk.Context, for ; iter.Valid(); iter.Next() { address := types.GetValidatorSigningInfoAddress(iter.Key()) var info types.ValidatorSigningInfo - k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &info) + k.cdc.MustUnmarshalBinaryBare(iter.Value(), &info) if handler(address, info) { break } @@ -63,7 +63,7 @@ func (k Keeper) GetValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.Con // lazy: treat empty key as not missed return false } - k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &missed) + k.cdc.MustUnmarshalBinaryBare(bz, &missed) return missed.Value } @@ -83,7 +83,7 @@ func (k Keeper) IterateValidatorMissedBlockBitArray(ctx sdk.Context, continue } - k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &missed) + k.cdc.MustUnmarshalBinaryBare(bz, &missed) if handler(index, missed.Value) { break } @@ -132,7 +132,7 @@ func (k Keeper) IsTombstoned(ctx sdk.Context, consAddr sdk.ConsAddress) bool { // missed a block in the current window func (k Keeper) SetValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64, missed bool) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.BoolValue{Value: missed}) + bz := k.cdc.MustMarshalBinaryBare(&gogotypes.BoolValue{Value: missed}) store.Set(types.GetValidatorMissedBlockBitArrayKey(address, index), bz) } From 3b7aecf090aa7ecd17da7e0b0f5f170545520e1f Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 00:06:18 +0100 Subject: [PATCH 10/31] update decoder test --- x/auth/simulation/decoder.go | 4 ++-- x/auth/simulation/decoder_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x/auth/simulation/decoder.go b/x/auth/simulation/decoder.go index d157aab94349..7d5d0d7b52cc 100644 --- a/x/auth/simulation/decoder.go +++ b/x/auth/simulation/decoder.go @@ -22,8 +22,8 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { case bytes.Equal(kvA.Key, types.GlobalAccountNumberKey): var globalAccNumberA, globalAccNumberB uint64 - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &globalAccNumberA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &globalAccNumberB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &globalAccNumberA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &globalAccNumberB) return fmt.Sprintf("GlobalAccNumberA: %d\nGlobalAccNumberB: %d", globalAccNumberA, globalAccNumberB) default: diff --git a/x/auth/simulation/decoder_test.go b/x/auth/simulation/decoder_test.go index 2ef143f15ef9..729ca9d79320 100644 --- a/x/auth/simulation/decoder_test.go +++ b/x/auth/simulation/decoder_test.go @@ -34,7 +34,7 @@ func TestDecodeStore(t *testing.T) { kvPairs := tmkv.Pairs{ tmkv.Pair{Key: types.AddressStoreKey(delAddr1), Value: cdc.MustMarshalBinaryBare(acc)}, - tmkv.Pair{Key: types.GlobalAccountNumberKey, Value: cdc.MustMarshalBinaryLengthPrefixed(globalAccNumber)}, + tmkv.Pair{Key: types.GlobalAccountNumberKey, Value: cdc.MustMarshalBinaryBare(globalAccNumber)}, tmkv.Pair{Key: []byte{0x99}, Value: []byte{0x99}}, } tests := []struct { From 30add0676cd88f4bca0a53680073e4733635e7ef Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 00:23:08 +0100 Subject: [PATCH 11/31] migrate decoder --- x/slashing/simulation/decoder.go | 12 ++++++------ x/slashing/simulation/decoder_test.go | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/x/slashing/simulation/decoder.go b/x/slashing/simulation/decoder.go index 48a12705a780..9555737d889c 100644 --- a/x/slashing/simulation/decoder.go +++ b/x/slashing/simulation/decoder.go @@ -18,20 +18,20 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { switch { case bytes.Equal(kvA.Key[:1], types.ValidatorSigningInfoKey): var infoA, infoB types.ValidatorSigningInfo - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &infoA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &infoB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &infoA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &infoB) return fmt.Sprintf("%v\n%v", infoA, infoB) case bytes.Equal(kvA.Key[:1], types.ValidatorMissedBlockBitArrayKey): var missedA, missedB gogotypes.BoolValue - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &missedA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &missedB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &missedA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &missedB) return fmt.Sprintf("missedA: %v\nmissedB: %v", missedA.Value, missedB.Value) case bytes.Equal(kvA.Key[:1], types.AddrPubkeyRelationKey): var pubKeyA, pubKeyB crypto.PubKey - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &pubKeyA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &pubKeyB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &pubKeyA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &pubKeyB) bechPKA := sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pubKeyA) bechPKB := sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pubKeyB) return fmt.Sprintf("PubKeyA: %s\nPubKeyB: %s", bechPKA, bechPKB) diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index 522bff74750d..8d0c8b41e562 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -41,9 +41,9 @@ func TestDecodeStore(t *testing.T) { missed := gogotypes.BoolValue{Value: true} kvPairs := tmkv.Pairs{ - tmkv.Pair{Key: types.GetValidatorSigningInfoKey(consAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(info)}, - tmkv.Pair{Key: types.GetValidatorMissedBlockBitArrayKey(consAddr1, 6), Value: cdc.MustMarshalBinaryLengthPrefixed(&missed)}, - tmkv.Pair{Key: types.GetAddrPubkeyRelationKey(delAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(delPk1)}, + tmkv.Pair{Key: types.GetValidatorSigningInfoKey(consAddr1), Value: cdc.MustMarshalBinaryBare(info)}, + tmkv.Pair{Key: types.GetValidatorMissedBlockBitArrayKey(consAddr1, 6), Value: cdc.MustMarshalBinaryBare(&missed)}, + tmkv.Pair{Key: types.GetAddrPubkeyRelationKey(delAddr1), Value: cdc.MustMarshalBinaryBare(delPk1)}, tmkv.Pair{Key: []byte{0x99}, Value: []byte{0x99}}, } From 3900e4e64083a4836c9d748a377be1ff14decf8e Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 00:28:18 +0100 Subject: [PATCH 12/31] migrate gov simulation decoder --- x/gov/simulation/decoder.go | 12 ++++++------ x/gov/simulation/decoder_test.go | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/x/gov/simulation/decoder.go b/x/gov/simulation/decoder.go index 6e4c3169ac1f..c415117aa485 100644 --- a/x/gov/simulation/decoder.go +++ b/x/gov/simulation/decoder.go @@ -16,8 +16,8 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { switch { case bytes.Equal(kvA.Key[:1], types.ProposalsKeyPrefix): var proposalA, proposalB types.Proposal - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &proposalA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &proposalB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &proposalA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &proposalB) return fmt.Sprintf("%v\n%v", proposalA, proposalB) case bytes.Equal(kvA.Key[:1], types.ActiveProposalQueuePrefix), @@ -29,14 +29,14 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { case bytes.Equal(kvA.Key[:1], types.DepositsKeyPrefix): var depositA, depositB types.Deposit - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &depositA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &depositB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &depositA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &depositB) return fmt.Sprintf("%v\n%v", depositA, depositB) case bytes.Equal(kvA.Key[:1], types.VotesKeyPrefix): var voteA, voteB types.Vote - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &voteA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &voteB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &voteA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &voteB) return fmt.Sprintf("%v\n%v", voteA, voteB) default: diff --git a/x/gov/simulation/decoder_test.go b/x/gov/simulation/decoder_test.go index 025dbeedc71c..5ae3cab53a60 100644 --- a/x/gov/simulation/decoder_test.go +++ b/x/gov/simulation/decoder_test.go @@ -42,10 +42,10 @@ func TestDecodeStore(t *testing.T) { vote := types.NewVote(1, delAddr1, types.OptionYes) kvPairs := tmkv.Pairs{ - tmkv.Pair{Key: types.ProposalKey(1), Value: cdc.MustMarshalBinaryLengthPrefixed(proposal)}, + tmkv.Pair{Key: types.ProposalKey(1), Value: cdc.MustMarshalBinaryBare(proposal)}, tmkv.Pair{Key: types.InactiveProposalQueueKey(1, endTime), Value: proposalIDBz}, - tmkv.Pair{Key: types.DepositKey(1, delAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(deposit)}, - tmkv.Pair{Key: types.VoteKey(1, delAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(vote)}, + tmkv.Pair{Key: types.DepositKey(1, delAddr1), Value: cdc.MustMarshalBinaryBare(deposit)}, + tmkv.Pair{Key: types.VoteKey(1, delAddr1), Value: cdc.MustMarshalBinaryBare(vote)}, tmkv.Pair{Key: []byte{0x99}, Value: []byte{0x99}}, } From f082fde46deb4595adbe15b32fb71a1a18980c0a Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 12:32:27 +0100 Subject: [PATCH 13/31] migrate baseapp_test --- baseapp/baseapp_test.go | 6 +++--- x/mint/simulation/decoder.go | 4 ++-- x/mint/simulation/decoder_test.go | 2 +- x/slashing/types/signing_info.go | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 99f1c8d40047..2350ba64ceeb 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -1036,7 +1036,7 @@ func TestRunInvalidTransaction(t *testing.T) { registerTestCodec(newCdc) newCdc.RegisterConcrete(&msgNoDecode{}, "cosmos-sdk/baseapp/msgNoDecode", nil) - txBytes, err := newCdc.MarshalBinaryLengthPrefixed(tx) + txBytes, err := newCdc.MarshalBinaryBare(tx) require.NoError(t, err) res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) @@ -1359,7 +1359,7 @@ func TestGasConsumptionBadTx(t *testing.T) { tx := newTxCounter(5, 0) tx.setFailOnAnte(true) - txBytes, err := cdc.MarshalBinaryLengthPrefixed(tx) + txBytes, err := cdc.MarshalBinaryBare(tx) require.NoError(t, err) res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) @@ -1367,7 +1367,7 @@ func TestGasConsumptionBadTx(t *testing.T) { // require next tx to fail due to black gas limit tx = newTxCounter(5, 0) - txBytes, err = cdc.MarshalBinaryLengthPrefixed(tx) + txBytes, err = cdc.MarshalBinaryBare(tx) require.NoError(t, err) res = app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) diff --git a/x/mint/simulation/decoder.go b/x/mint/simulation/decoder.go index 5cdac40e88a7..8ff2baeb0e19 100644 --- a/x/mint/simulation/decoder.go +++ b/x/mint/simulation/decoder.go @@ -15,8 +15,8 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { switch { case bytes.Equal(kvA.Key, types.MinterKey): var minterA, minterB types.Minter - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &minterA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &minterB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &minterA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &minterB) return fmt.Sprintf("%v\n%v", minterA, minterB) default: panic(fmt.Sprintf("invalid mint key %X", kvA.Key)) diff --git a/x/mint/simulation/decoder_test.go b/x/mint/simulation/decoder_test.go index 47ed9bebbed5..48dfa62bb384 100644 --- a/x/mint/simulation/decoder_test.go +++ b/x/mint/simulation/decoder_test.go @@ -24,7 +24,7 @@ func TestDecodeStore(t *testing.T) { minter := types.NewMinter(sdk.OneDec(), sdk.NewDec(15)) kvPairs := tmkv.Pairs{ - tmkv.Pair{Key: types.MinterKey, Value: cdc.MustMarshalBinaryLengthPrefixed(minter)}, + tmkv.Pair{Key: types.MinterKey, Value: cdc.MustMarshalBinaryBare(minter)}, tmkv.Pair{Key: []byte{0x99}, Value: []byte{0x99}}, } tests := []struct { diff --git a/x/slashing/types/signing_info.go b/x/slashing/types/signing_info.go index 315cac792c56..a9cc15f6ec0e 100644 --- a/x/slashing/types/signing_info.go +++ b/x/slashing/types/signing_info.go @@ -40,6 +40,6 @@ func (i ValidatorSigningInfo) String() string { // unmarshal a validator signing info from a store value func UnmarshalValSigningInfo(cdc codec.Marshaler, value []byte) (signingInfo ValidatorSigningInfo, err error) { - err = cdc.UnmarshalBinaryLengthPrefixed(value, &signingInfo) + err = cdc.UnmarshalBinaryBare(value, &signingInfo) return signingInfo, err } From fbefe8a35bd33cf5082d41e65b16e7fb26244032 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 12:35:42 +0100 Subject: [PATCH 14/31] refactor QuerySubspace --- client/context/query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/context/query.go b/client/context/query.go index c0c45a226fb7..cfe08969f285 100644 --- a/client/context/query.go +++ b/client/context/query.go @@ -64,7 +64,7 @@ func (ctx CLIContext) QuerySubspace(subspace []byte, storeName string) (res []sd return res, height, err } - ctx.Codec.MustUnmarshalBinaryLengthPrefixed(resRaw, &res) + ctx.Codec.MustUnmarshalBinaryBare(resRaw, &res) return } From e419105085b9d9e0488fac20d35700257d61c3af Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 12:45:42 +0100 Subject: [PATCH 15/31] refactor coedc std codec --- codec/std/codec.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/codec/std/codec.go b/codec/std/codec.go index ce56ee61bca8..03f12020da24 100644 --- a/codec/std/codec.go +++ b/codec/std/codec.go @@ -44,14 +44,14 @@ func (c *Codec) MarshalAccount(accI authexported.Account) ([]byte, error) { return nil, err } - return c.Marshaler.MarshalBinaryLengthPrefixed(acc) + return c.Marshaler.MarshalBinaryBare(acc) } // UnmarshalAccount returns an Account interface from raw encoded account bytes // of a Proto-based Account type. An error is returned upon decoding failure. func (c *Codec) UnmarshalAccount(bz []byte) (authexported.Account, error) { acc := &Account{} - if err := c.Marshaler.UnmarshalBinaryLengthPrefixed(bz, acc); err != nil { + if err := c.Marshaler.UnmarshalBinaryBare(bz, acc); err != nil { return nil, err } @@ -83,14 +83,14 @@ func (c *Codec) MarshalSupply(supplyI supplyexported.SupplyI) ([]byte, error) { return nil, err } - return c.Marshaler.MarshalBinaryLengthPrefixed(supply) + return c.Marshaler.MarshalBinaryBare(supply) } // UnmarshalSupply returns a SupplyI interface from raw encoded account bytes // of a Proto-based SupplyI type. An error is returned upon decoding failure. func (c *Codec) UnmarshalSupply(bz []byte) (supplyexported.SupplyI, error) { supply := &Supply{} - if err := c.Marshaler.UnmarshalBinaryLengthPrefixed(bz, supply); err != nil { + if err := c.Marshaler.UnmarshalBinaryBare(bz, supply); err != nil { return nil, err } @@ -122,7 +122,7 @@ func (c *Codec) MarshalEvidence(evidenceI eviexported.Evidence) ([]byte, error) return nil, err } - return c.Marshaler.MarshalBinaryLengthPrefixed(evidence) + return c.Marshaler.MarshalBinaryBare(evidence) } // UnmarshalEvidence returns an Evidence interface from raw encoded evidence @@ -130,7 +130,7 @@ func (c *Codec) MarshalEvidence(evidenceI eviexported.Evidence) ([]byte, error) // failure. func (c *Codec) UnmarshalEvidence(bz []byte) (eviexported.Evidence, error) { evidence := &Evidence{} - if err := c.Marshaler.UnmarshalBinaryLengthPrefixed(bz, evidence); err != nil { + if err := c.Marshaler.UnmarshalBinaryBare(bz, evidence); err != nil { return nil, err } @@ -162,7 +162,7 @@ func (c *Codec) MarshalProposal(p gov.Proposal) ([]byte, error) { return nil, err } - return c.Marshaler.MarshalBinaryLengthPrefixed(proposal) + return c.Marshaler.MarshalBinaryBare(proposal) } // UnmarshalProposal decodes a Proposal defined by the x/gov module and uses the @@ -170,7 +170,7 @@ func (c *Codec) MarshalProposal(p gov.Proposal) ([]byte, error) { // to deserialize. func (c *Codec) UnmarshalProposal(bz []byte) (gov.Proposal, error) { proposal := &Proposal{} - if err := c.Marshaler.UnmarshalBinaryLengthPrefixed(bz, proposal); err != nil { + if err := c.Marshaler.UnmarshalBinaryBare(bz, proposal); err != nil { return gov.Proposal{}, err } From 67cbf19cf66999eaa1136571d585603d5641a705 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 12:56:20 +0100 Subject: [PATCH 16/31] migrate keybase --- crypto/keys/keybase_base.go | 2 +- crypto/keys/types.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crypto/keys/keybase_base.go b/crypto/keys/keybase_base.go index 47c7e60d729a..86ed00677d25 100644 --- a/crypto/keys/keybase_base.go +++ b/crypto/keys/keybase_base.go @@ -124,7 +124,7 @@ func (kb baseKeybase) DecodeSignature(info Info, msg []byte) (sig []byte, pub tm return nil, nil, err } - if err := CryptoCdc.UnmarshalBinaryLengthPrefixed([]byte(signed), sig); err != nil { + if err := CryptoCdc.UnmarshalBinaryBare([]byte(signed), sig); err != nil { return nil, nil, errors.Wrap(err, "failed to decode signature") } diff --git a/crypto/keys/types.go b/crypto/keys/types.go index 89f5cb2d539b..c91f2905b24e 100644 --- a/crypto/keys/types.go +++ b/crypto/keys/types.go @@ -337,12 +337,12 @@ func (i multiInfo) GetPath() (*hd.BIP44Params, error) { // encoding info func marshalInfo(i Info) []byte { - return CryptoCdc.MustMarshalBinaryLengthPrefixed(i) + return CryptoCdc.MustMarshalBinaryBare(i) } // decoding info func unmarshalInfo(bz []byte) (info Info, err error) { - err = CryptoCdc.UnmarshalBinaryLengthPrefixed(bz, &info) + err = CryptoCdc.UnmarshalBinaryBare(bz, &info) return } From 57ad6acbd5d492feb9956e8d6801d43671e8240d Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 13:02:47 +0100 Subject: [PATCH 17/31] migrate iavl store --- store/iavl/store.go | 2 +- store/iavl/store_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/store/iavl/store.go b/store/iavl/store.go index 311d0f887a66..3cc2a83b5ce1 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -312,7 +312,7 @@ func (st *Store) Query(req abci.RequestQuery) (res abci.ResponseQuery) { } iterator.Close() - res.Value = cdc.MustMarshalBinaryLengthPrefixed(KVs) + res.Value = cdc.MustMarshalBinaryBare(KVs) default: return sdkerrors.QueryResult(sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unexpected query path: %v", req.Path)) diff --git a/store/iavl/store_test.go b/store/iavl/store_test.go index ed138c84964f..ebfb32938fab 100644 --- a/store/iavl/store_test.go +++ b/store/iavl/store_test.go @@ -521,9 +521,9 @@ func TestIAVLStoreQuery(t *testing.T) { {Key: k1, Value: v3}, {Key: k2, Value: v2}, } - valExpSubEmpty := cdc.MustMarshalBinaryLengthPrefixed(KVs0) - valExpSub1 := cdc.MustMarshalBinaryLengthPrefixed(KVs1) - valExpSub2 := cdc.MustMarshalBinaryLengthPrefixed(KVs2) + valExpSubEmpty := cdc.MustMarshalBinaryBare(KVs0) + valExpSub1 := cdc.MustMarshalBinaryBare(KVs1) + valExpSub2 := cdc.MustMarshalBinaryBare(KVs2) cid := iavlStore.Commit() ver := cid.Version From 35b2ae40b975c97b95f3e3567665009d1b9e0e83 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 13:05:51 +0100 Subject: [PATCH 18/31] migrate root multi --- store/rootmulti/proof.go | 4 ++-- store/rootmulti/store.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/store/rootmulti/proof.go b/store/rootmulti/proof.go index a2fef8ae3ce9..af0f919c367b 100644 --- a/store/rootmulti/proof.go +++ b/store/rootmulti/proof.go @@ -68,7 +68,7 @@ func MultiStoreProofOpDecoder(pop merkle.ProofOp) (merkle.ProofOperator, error) // XXX: a bit strange as we'll discard this, but it works var op MultiStoreProofOp - err := cdc.UnmarshalBinaryLengthPrefixed(pop.Data, &op) + err := cdc.UnmarshalBinaryBare(pop.Data, &op) if err != nil { return nil, fmt.Errorf("decoding ProofOp.Data into MultiStoreProofOp: %w", err) } @@ -79,7 +79,7 @@ func MultiStoreProofOpDecoder(pop merkle.ProofOp) (merkle.ProofOperator, error) // ProofOp return a merkle proof operation from a given multi-store proof // operation. func (op MultiStoreProofOp) ProofOp() merkle.ProofOp { - bz := cdc.MustMarshalBinaryLengthPrefixed(op) + bz := cdc.MustMarshalBinaryBare(op) return merkle.ProofOp{ Type: ProofOpMultiStore, Key: op.key, diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index c88657741617..6b1cfde815ea 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -617,7 +617,7 @@ func getLatestVersion(db dbm.DB) int64 { return 0 } - err = cdc.UnmarshalBinaryLengthPrefixed(latestBytes, &latest) + err = cdc.UnmarshalBinaryBare(latestBytes, &latest) if err != nil { panic(err) } @@ -627,7 +627,7 @@ func getLatestVersion(db dbm.DB) int64 { // Set the latest version. func setLatestVersion(batch dbm.Batch, version int64) { - latestBytes, _ := cdc.MarshalBinaryLengthPrefixed(version) + latestBytes, _ := cdc.MarshalBinaryBare(version) batch.Set([]byte(latestVersionKey), latestBytes) } @@ -668,7 +668,7 @@ func getCommitInfo(db dbm.DB, ver int64) (commitInfo, error) { var cInfo commitInfo - err = cdc.UnmarshalBinaryLengthPrefixed(cInfoBytes, &cInfo) + err = cdc.UnmarshalBinaryBare(cInfoBytes, &cInfo) if err != nil { return commitInfo{}, errors.Wrap(err, "failed to get store") } @@ -678,7 +678,7 @@ func getCommitInfo(db dbm.DB, ver int64) (commitInfo, error) { // Set a commitInfo for given version. func setCommitInfo(batch dbm.Batch, version int64, cInfo commitInfo) { - cInfoBytes := cdc.MustMarshalBinaryLengthPrefixed(cInfo) + cInfoBytes := cdc.MustMarshalBinaryBare(cInfo) cInfoKey := fmt.Sprintf(commitInfoKeyFmt, version) batch.Set([]byte(cInfoKey), cInfoBytes) } From b7409039630f6efebeb92bbd348307c7c40d7588 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 13:22:29 +0100 Subject: [PATCH 19/31] migrate ante basic --- x/auth/ante/basic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index 05e570ca2854..37bc4f1c0f2a 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -130,7 +130,7 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim PubKey: pubkey, } - sigBz := codec.Cdc.MustMarshalBinaryLengthPrefixed(simSig) + sigBz := codec.Cdc.MustMarshalBinaryBare(simSig) cost := sdk.Gas(len(sigBz) + 6) // If the pubkey is a multi-signature pubkey, then we estimate for the maximum From 82848efb8633723835f5d9b2a83c8fcc46a35967 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 13:30:16 +0100 Subject: [PATCH 20/31] migrate tx type to bare --- x/auth/client/query.go | 2 +- x/auth/client/tx.go | 2 +- x/auth/client/tx_test.go | 4 ++-- x/gov/client/utils/query_test.go | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/x/auth/client/query.go b/x/auth/client/query.go index ad00ca740371..85bd747bc3c5 100644 --- a/x/auth/client/query.go +++ b/x/auth/client/query.go @@ -172,7 +172,7 @@ func formatTxResult(cdc *codec.Codec, resTx *ctypes.ResultTx, resBlock *ctypes.R func parseTx(cdc *codec.Codec, txBytes []byte) (sdk.Tx, error) { var tx types.StdTx - err := cdc.UnmarshalBinaryLengthPrefixed(txBytes, &tx) + err := cdc.UnmarshalBinaryBare(txBytes, &tx) if err != nil { return nil, err } diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index 3c35aebe61c0..d9212bed5fbe 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -289,7 +289,7 @@ func adjustGasEstimate(estimate uint64, adjustment float64) uint64 { func parseQueryResponse(cdc *codec.Codec, rawRes []byte) (uint64, error) { var gasUsed uint64 - if err := cdc.UnmarshalBinaryLengthPrefixed(rawRes, &gasUsed); err != nil { + if err := cdc.UnmarshalBinaryBare(rawRes, &gasUsed); err != nil { return 0, err } diff --git a/x/auth/client/tx_test.go b/x/auth/client/tx_test.go index 1fb4ca3d22d6..643f253a21f8 100644 --- a/x/auth/client/tx_test.go +++ b/x/auth/client/tx_test.go @@ -23,7 +23,7 @@ var ( func TestParseQueryResponse(t *testing.T) { cdc := makeCodec() - sdkResBytes := cdc.MustMarshalBinaryLengthPrefixed(uint64(10)) + sdkResBytes := cdc.MustMarshalBinaryBare(uint64(10)) gas, err := parseQueryResponse(cdc, sdkResBytes) assert.Equal(t, gas, uint64(10)) assert.Nil(t, err) @@ -39,7 +39,7 @@ func TestCalculateGas(t *testing.T) { if wantErr { return nil, 0, errors.New("") } - return cdc.MustMarshalBinaryLengthPrefixed(gasUsed), 0, nil + return cdc.MustMarshalBinaryBare(gasUsed), 0, nil } } diff --git a/x/gov/client/utils/query_test.go b/x/gov/client/utils/query_test.go index eb4d71e0b061..adc83eb48a80 100644 --- a/x/gov/client/utils/query_test.go +++ b/x/gov/client/utils/query_test.go @@ -137,9 +137,9 @@ func TestGetPaginatedVotes(t *testing.T) { cdc = newTestCodec() ) for i := range tc.txs { - tx, err := cdc.MarshalBinaryLengthPrefixed(&tc.txs[i]) + tx, err := cdc.MarshalBinaryBare(&tc.txs[i]) require.NoError(t, err) - marshalled[i] = tmtypes.Tx(tx) + marshalled[i] = tx } client := TxSearchMock{txs: marshalled} ctx := context.CLIContext{}.WithCodec(cdc).WithTrustNode(true).WithClient(client) From 9ff06edbc5bf9a4751e67e283e948b9de8468aa3 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 14:13:24 +0100 Subject: [PATCH 21/31] migrate auth client --- x/auth/client/cli/broadcast.go | 2 +- x/auth/client/cli/decode.go | 2 +- x/auth/client/cli/encode.go | 2 +- x/auth/client/rest/broadcast.go | 2 +- x/auth/client/rest/decode.go | 2 +- x/auth/client/rest/encode.go | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/x/auth/client/cli/broadcast.go b/x/auth/client/cli/broadcast.go index e5a62e388ed4..288b7c7de911 100644 --- a/x/auth/client/cli/broadcast.go +++ b/x/auth/client/cli/broadcast.go @@ -31,7 +31,7 @@ $ tx broadcast ./mytxn.json return } - txBytes, err := cliCtx.Codec.MarshalBinaryLengthPrefixed(stdTx) + txBytes, err := cliCtx.Codec.MarshalBinaryBare(stdTx) if err != nil { return } diff --git a/x/auth/client/cli/decode.go b/x/auth/client/cli/decode.go index c9253d8fb4a3..f4eb7e954fb1 100644 --- a/x/auth/client/cli/decode.go +++ b/x/auth/client/cli/decode.go @@ -44,7 +44,7 @@ func runDecodeTxString(codec *amino.Codec) func(cmd *cobra.Command, args []strin } var stdTx authtypes.StdTx - err = cliCtx.Codec.UnmarshalBinaryLengthPrefixed(txBytes, &stdTx) + err = cliCtx.Codec.UnmarshalBinaryBare(txBytes, &stdTx) if err != nil { return err } diff --git a/x/auth/client/cli/encode.go b/x/auth/client/cli/encode.go index fa39a58cab93..245bb0e0f675 100644 --- a/x/auth/client/cli/encode.go +++ b/x/auth/client/cli/encode.go @@ -37,7 +37,7 @@ If you supply a dash (-) argument in place of an input filename, the command rea } // re-encode it via the Amino wire protocol - txBytes, err := cliCtx.Codec.MarshalBinaryLengthPrefixed(stdTx) + txBytes, err := cliCtx.Codec.MarshalBinaryBare(stdTx) if err != nil { return err } diff --git a/x/auth/client/rest/broadcast.go b/x/auth/client/rest/broadcast.go index e7609194c390..92a94eefccd5 100644 --- a/x/auth/client/rest/broadcast.go +++ b/x/auth/client/rest/broadcast.go @@ -34,7 +34,7 @@ func BroadcastTxRequest(cliCtx context.CLIContext) http.HandlerFunc { return } - txBytes, err := cliCtx.Codec.MarshalBinaryLengthPrefixed(req.Tx) + txBytes, err := cliCtx.Codec.MarshalBinaryBare(req.Tx) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return diff --git a/x/auth/client/rest/decode.go b/x/auth/client/rest/decode.go index 98c4f0c6da04..dfe7436b8e72 100644 --- a/x/auth/client/rest/decode.go +++ b/x/auth/client/rest/decode.go @@ -46,7 +46,7 @@ func DecodeTxRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { } var stdTx authtypes.StdTx - err = cliCtx.Codec.UnmarshalBinaryLengthPrefixed(txBytes, &stdTx) + err = cliCtx.Codec.UnmarshalBinaryBare(txBytes, &stdTx) if err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) return diff --git a/x/auth/client/rest/encode.go b/x/auth/client/rest/encode.go index e2d9f4fea319..b2fe6681e10e 100644 --- a/x/auth/client/rest/encode.go +++ b/x/auth/client/rest/encode.go @@ -35,7 +35,7 @@ func EncodeTxRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { } // re-encode it via the Amino wire protocol - txBytes, err := cliCtx.Codec.MarshalBinaryLengthPrefixed(req) + txBytes, err := cliCtx.Codec.MarshalBinaryBare(req) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return From f10ac702bf961f24a9657bb21e1bb2b4638f977a Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 14:20:52 +0100 Subject: [PATCH 22/31] update auth types --- x/auth/types/stdtx.go | 4 ++-- x/auth/types/stdtx_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index a9a6cd3e9daf..6c5d38c1bf37 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -254,7 +254,7 @@ func DefaultTxDecoder(cdc *codec.Codec) sdk.TxDecoder { // StdTx.Msg is an interface. The concrete types // are registered by MakeTxCodec - err := cdc.UnmarshalBinaryLengthPrefixed(txBytes, &tx) + err := cdc.UnmarshalBinaryBare(txBytes, &tx) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, err.Error()) } @@ -266,7 +266,7 @@ func DefaultTxDecoder(cdc *codec.Codec) sdk.TxDecoder { // DefaultTxEncoder logic for standard transaction encoding func DefaultTxEncoder(cdc *codec.Codec) sdk.TxEncoder { return func(tx sdk.Tx) ([]byte, error) { - return cdc.MarshalBinaryLengthPrefixed(tx) + return cdc.MarshalBinaryBare(tx) } } diff --git a/x/auth/types/stdtx_test.go b/x/auth/types/stdtx_test.go index a8ce9d721076..676a6bef7142 100644 --- a/x/auth/types/stdtx_test.go +++ b/x/auth/types/stdtx_test.go @@ -131,7 +131,7 @@ func TestDefaultTxEncoder(t *testing.T) { tx := NewStdTx(msgs, fee, sigs, "") - cdcBytes, err := cdc.MarshalBinaryLengthPrefixed(tx) + cdcBytes, err := cdc.MarshalBinaryBare(tx) require.NoError(t, err) encoderBytes, err := encoder(tx) From 98bd455bc494a846601a48897f3f64f59a28d238 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 14:36:48 +0100 Subject: [PATCH 23/31] update decoder --- x/distribution/simulation/decoder.go | 28 +++++++++++------------ x/distribution/simulation/decoder_test.go | 14 ++++++------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/x/distribution/simulation/decoder.go b/x/distribution/simulation/decoder.go index 79298073a94d..ce991efca431 100644 --- a/x/distribution/simulation/decoder.go +++ b/x/distribution/simulation/decoder.go @@ -16,8 +16,8 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { switch { case bytes.Equal(kvA.Key[:1], types.FeePoolKey): var feePoolA, feePoolB types.FeePool - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &feePoolA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &feePoolB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &feePoolA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &feePoolB) return fmt.Sprintf("%v\n%v", feePoolA, feePoolB) case bytes.Equal(kvA.Key[:1], types.ProposerKey): @@ -25,8 +25,8 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { case bytes.Equal(kvA.Key[:1], types.ValidatorOutstandingRewardsPrefix): var rewardsA, rewardsB types.ValidatorOutstandingRewards - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &rewardsA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &rewardsB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &rewardsA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &rewardsB) return fmt.Sprintf("%v\n%v", rewardsA, rewardsB) case bytes.Equal(kvA.Key[:1], types.DelegatorWithdrawAddrPrefix): @@ -34,32 +34,32 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { case bytes.Equal(kvA.Key[:1], types.DelegatorStartingInfoPrefix): var infoA, infoB types.DelegatorStartingInfo - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &infoA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &infoB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &infoA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &infoB) return fmt.Sprintf("%v\n%v", infoA, infoB) case bytes.Equal(kvA.Key[:1], types.ValidatorHistoricalRewardsPrefix): var rewardsA, rewardsB types.ValidatorHistoricalRewards - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &rewardsA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &rewardsB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &rewardsA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &rewardsB) return fmt.Sprintf("%v\n%v", rewardsA, rewardsB) case bytes.Equal(kvA.Key[:1], types.ValidatorCurrentRewardsPrefix): var rewardsA, rewardsB types.ValidatorCurrentRewards - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &rewardsA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &rewardsB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &rewardsA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &rewardsB) return fmt.Sprintf("%v\n%v", rewardsA, rewardsB) case bytes.Equal(kvA.Key[:1], types.ValidatorAccumulatedCommissionPrefix): var commissionA, commissionB types.ValidatorAccumulatedCommission - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &commissionA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &commissionB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &commissionA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &commissionB) return fmt.Sprintf("%v\n%v", commissionA, commissionB) case bytes.Equal(kvA.Key[:1], types.ValidatorSlashEventPrefix): var eventA, eventB types.ValidatorSlashEvent - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &eventA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &eventB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &eventA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &eventB) return fmt.Sprintf("%v\n%v", eventA, eventB) default: diff --git a/x/distribution/simulation/decoder_test.go b/x/distribution/simulation/decoder_test.go index 059c2d625afd..8eb1c00d44f1 100644 --- a/x/distribution/simulation/decoder_test.go +++ b/x/distribution/simulation/decoder_test.go @@ -43,15 +43,15 @@ func TestDecodeDistributionStore(t *testing.T) { slashEvent := types.NewValidatorSlashEvent(10, sdk.OneDec()) kvPairs := tmkv.Pairs{ - tmkv.Pair{Key: types.FeePoolKey, Value: cdc.MustMarshalBinaryLengthPrefixed(feePool)}, + tmkv.Pair{Key: types.FeePoolKey, Value: cdc.MustMarshalBinaryBare(feePool)}, tmkv.Pair{Key: types.ProposerKey, Value: consAddr1.Bytes()}, - tmkv.Pair{Key: types.GetValidatorOutstandingRewardsKey(valAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(outstanding)}, + tmkv.Pair{Key: types.GetValidatorOutstandingRewardsKey(valAddr1), Value: cdc.MustMarshalBinaryBare(outstanding)}, tmkv.Pair{Key: types.GetDelegatorWithdrawAddrKey(delAddr1), Value: delAddr1.Bytes()}, - tmkv.Pair{Key: types.GetDelegatorStartingInfoKey(valAddr1, delAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(info)}, - tmkv.Pair{Key: types.GetValidatorHistoricalRewardsKey(valAddr1, 100), Value: cdc.MustMarshalBinaryLengthPrefixed(historicalRewards)}, - tmkv.Pair{Key: types.GetValidatorCurrentRewardsKey(valAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(currentRewards)}, - tmkv.Pair{Key: types.GetValidatorAccumulatedCommissionKey(valAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(commission)}, - tmkv.Pair{Key: types.GetValidatorSlashEventKeyPrefix(valAddr1, 13), Value: cdc.MustMarshalBinaryLengthPrefixed(slashEvent)}, + tmkv.Pair{Key: types.GetDelegatorStartingInfoKey(valAddr1, delAddr1), Value: cdc.MustMarshalBinaryBare(info)}, + tmkv.Pair{Key: types.GetValidatorHistoricalRewardsKey(valAddr1, 100), Value: cdc.MustMarshalBinaryBare(historicalRewards)}, + tmkv.Pair{Key: types.GetValidatorCurrentRewardsKey(valAddr1), Value: cdc.MustMarshalBinaryBare(currentRewards)}, + tmkv.Pair{Key: types.GetValidatorAccumulatedCommissionKey(valAddr1), Value: cdc.MustMarshalBinaryBare(commission)}, + tmkv.Pair{Key: types.GetValidatorSlashEventKeyPrefix(valAddr1, 13), Value: cdc.MustMarshalBinaryBare(slashEvent)}, tmkv.Pair{Key: []byte{0x99}, Value: []byte{0x99}}, } From d235280e8c12e7293c537a6b3f1153191e443b5f Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 14:43:04 +0100 Subject: [PATCH 24/31] migrate supply decoder --- x/supply/simulation/decoder.go | 4 ++-- x/supply/simulation/decoder_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x/supply/simulation/decoder.go b/x/supply/simulation/decoder.go index b67e07651be4..f025b50464e2 100644 --- a/x/supply/simulation/decoder.go +++ b/x/supply/simulation/decoder.go @@ -16,8 +16,8 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { switch { case bytes.Equal(kvA.Key[:1], keeper.SupplyKey): var supplyA, supplyB types.Supply - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &supplyA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &supplyB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &supplyA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &supplyB) return fmt.Sprintf("%v\n%v", supplyB, supplyB) default: diff --git a/x/supply/simulation/decoder_test.go b/x/supply/simulation/decoder_test.go index 413e0a930e9d..d5e196ed41f1 100644 --- a/x/supply/simulation/decoder_test.go +++ b/x/supply/simulation/decoder_test.go @@ -27,7 +27,7 @@ func TestDecodeStore(t *testing.T) { totalSupply := types.NewSupply(sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000))) kvPairs := tmkv.Pairs{ - tmkv.Pair{Key: keeper.SupplyKey, Value: cdc.MustMarshalBinaryLengthPrefixed(totalSupply)}, + tmkv.Pair{Key: keeper.SupplyKey, Value: cdc.MustMarshalBinaryBare(totalSupply)}, tmkv.Pair{Key: []byte{0x99}, Value: []byte{0x99}}, } From 1f1cfaca0d7fef282398c81bf023db4cce826620 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 15:30:18 +0100 Subject: [PATCH 25/31] migrate stake encoding --- x/staking/types/delegation.go | 12 ++++++------ x/staking/types/historical_info.go | 4 ++-- x/staking/types/params.go | 2 +- x/staking/types/validator.go | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/x/staking/types/delegation.go b/x/staking/types/delegation.go index 51fca1d38e48..34852d73d9f4 100644 --- a/x/staking/types/delegation.go +++ b/x/staking/types/delegation.go @@ -39,7 +39,7 @@ func NewDelegation(delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress, s // MustMarshalDelegation returns the delegation bytes. Panics if fails func MustMarshalDelegation(cdc codec.Marshaler, delegation Delegation) []byte { - return cdc.MustMarshalBinaryLengthPrefixed(&delegation) + return cdc.MustMarshalBinaryBare(&delegation) } // MustUnmarshalDelegation return the unmarshaled delegation from bytes. @@ -54,7 +54,7 @@ func MustUnmarshalDelegation(cdc codec.Marshaler, value []byte) Delegation { // return the delegation func UnmarshalDelegation(cdc codec.Marshaler, value []byte) (delegation Delegation, err error) { - err = cdc.UnmarshalBinaryLengthPrefixed(value, &delegation) + err = cdc.UnmarshalBinaryBare(value, &delegation) return delegation, err } @@ -127,7 +127,7 @@ func (ubd *UnbondingDelegation) RemoveEntry(i int64) { // return the unbonding delegation func MustMarshalUBD(cdc codec.Marshaler, ubd UnbondingDelegation) []byte { - return cdc.MustMarshalBinaryLengthPrefixed(&ubd) + return cdc.MustMarshalBinaryBare(&ubd) } // unmarshal a unbonding delegation from a store value @@ -141,7 +141,7 @@ func MustUnmarshalUBD(cdc codec.Marshaler, value []byte) UnbondingDelegation { // unmarshal a unbonding delegation from a store value func UnmarshalUBD(cdc codec.Marshaler, value []byte) (ubd UnbondingDelegation, err error) { - err = cdc.UnmarshalBinaryLengthPrefixed(value, &ubd) + err = cdc.UnmarshalBinaryBare(value, &ubd) return ubd, err } @@ -219,7 +219,7 @@ func (red *Redelegation) RemoveEntry(i int64) { // MustMarshalRED returns the Redelegation bytes. Panics if fails. func MustMarshalRED(cdc codec.Marshaler, red Redelegation) []byte { - return cdc.MustMarshalBinaryLengthPrefixed(&red) + return cdc.MustMarshalBinaryBare(&red) } // MustUnmarshalRED unmarshals a redelegation from a store value. Panics if fails. @@ -233,7 +233,7 @@ func MustUnmarshalRED(cdc codec.Marshaler, value []byte) Redelegation { // UnmarshalRED unmarshals a redelegation from a store value func UnmarshalRED(cdc codec.Marshaler, value []byte) (red Redelegation, err error) { - err = cdc.UnmarshalBinaryLengthPrefixed(value, &red) + err = cdc.UnmarshalBinaryBare(value, &red) return red, err } diff --git a/x/staking/types/historical_info.go b/x/staking/types/historical_info.go index 98f2ea86a5cd..002a53a85410 100644 --- a/x/staking/types/historical_info.go +++ b/x/staking/types/historical_info.go @@ -21,7 +21,7 @@ func NewHistoricalInfo(header abci.Header, valSet Validators) HistoricalInfo { // MustMarshalHistoricalInfo wll marshal historical info and panic on error func MustMarshalHistoricalInfo(cdc codec.Marshaler, hi HistoricalInfo) []byte { - return cdc.MustMarshalBinaryLengthPrefixed(&hi) + return cdc.MustMarshalBinaryBare(&hi) } // MustUnmarshalHistoricalInfo wll unmarshal historical info and panic on error @@ -35,7 +35,7 @@ func MustUnmarshalHistoricalInfo(cdc codec.Marshaler, value []byte) HistoricalIn // UnmarshalHistoricalInfo will unmarshal historical info and return any error func UnmarshalHistoricalInfo(cdc codec.Marshaler, value []byte) (hi HistoricalInfo, err error) { - err = cdc.UnmarshalBinaryLengthPrefixed(value, &hi) + err = cdc.UnmarshalBinaryBare(value, &hi) return hi, err } diff --git a/x/staking/types/params.go b/x/staking/types/params.go index 8d2b14ec694e..ac21113d7ec7 100644 --- a/x/staking/types/params.go +++ b/x/staking/types/params.go @@ -95,7 +95,7 @@ func MustUnmarshalParams(cdc *codec.Codec, value []byte) Params { // unmarshal the current staking params value from store key func UnmarshalParams(cdc *codec.Codec, value []byte) (params Params, err error) { - err = cdc.UnmarshalBinaryLengthPrefixed(value, ¶ms) + err = cdc.UnmarshalBinaryBare(value, ¶ms) if err != nil { return } diff --git a/x/staking/types/validator.go b/x/staking/types/validator.go index 2304596ae2b9..52dfdc33f77d 100644 --- a/x/staking/types/validator.go +++ b/x/staking/types/validator.go @@ -108,7 +108,7 @@ func (v Validators) Swap(i, j int) { // return the redelegation func MustMarshalValidator(cdc codec.Marshaler, validator Validator) []byte { - return cdc.MustMarshalBinaryLengthPrefixed(&validator) + return cdc.MustMarshalBinaryBare(&validator) } // unmarshal a redelegation from a store value @@ -122,7 +122,7 @@ func MustUnmarshalValidator(cdc codec.Marshaler, value []byte) Validator { // unmarshal a redelegation from a store value func UnmarshalValidator(cdc codec.Marshaler, value []byte) (v Validator, err error) { - err = cdc.UnmarshalBinaryLengthPrefixed(value, &v) + err = cdc.UnmarshalBinaryBare(value, &v) return v, err } From 4b3221b983c85b7386c9d795126dcda13f108b62 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 15:32:23 +0100 Subject: [PATCH 26/31] migrate staking simulation --- x/staking/simulation/decoder.go | 20 ++++++++++---------- x/staking/simulation/decoder_test.go | 10 +++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/x/staking/simulation/decoder.go b/x/staking/simulation/decoder.go index de5d50de9f7d..86f1cecc9e00 100644 --- a/x/staking/simulation/decoder.go +++ b/x/staking/simulation/decoder.go @@ -16,14 +16,14 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { switch { case bytes.Equal(kvA.Key[:1], types.LastTotalPowerKey): var powerA, powerB sdk.Int - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &powerA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &powerB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &powerA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &powerB) return fmt.Sprintf("%v\n%v", powerA, powerB) case bytes.Equal(kvA.Key[:1], types.ValidatorsKey): var validatorA, validatorB types.Validator - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &validatorA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &validatorB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &validatorA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &validatorB) return fmt.Sprintf("%v\n%v", validatorA, validatorB) case bytes.Equal(kvA.Key[:1], types.LastValidatorPowerKey), @@ -33,22 +33,22 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { case bytes.Equal(kvA.Key[:1], types.DelegationKey): var delegationA, delegationB types.Delegation - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &delegationA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &delegationB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &delegationA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &delegationB) return fmt.Sprintf("%v\n%v", delegationA, delegationB) case bytes.Equal(kvA.Key[:1], types.UnbondingDelegationKey), bytes.Equal(kvA.Key[:1], types.UnbondingDelegationByValIndexKey): var ubdA, ubdB types.UnbondingDelegation - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &ubdA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &ubdB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &ubdA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &ubdB) return fmt.Sprintf("%v\n%v", ubdA, ubdB) case bytes.Equal(kvA.Key[:1], types.RedelegationKey), bytes.Equal(kvA.Key[:1], types.RedelegationByValSrcIndexKey): var redA, redB types.Redelegation - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &redA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &redB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &redA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &redB) return fmt.Sprintf("%v\n%v", redA, redB) default: diff --git a/x/staking/simulation/decoder_test.go b/x/staking/simulation/decoder_test.go index 5e0407c59c07..40dd39710e84 100644 --- a/x/staking/simulation/decoder_test.go +++ b/x/staking/simulation/decoder_test.go @@ -40,12 +40,12 @@ func TestDecodeStore(t *testing.T) { red := types.NewRedelegation(delAddr1, valAddr1, valAddr1, 12, bondTime, sdk.OneInt(), sdk.OneDec()) kvPairs := tmkv.Pairs{ - tmkv.Pair{Key: types.LastTotalPowerKey, Value: cdc.MustMarshalBinaryLengthPrefixed(sdk.OneInt())}, - tmkv.Pair{Key: types.GetValidatorKey(valAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(val)}, + tmkv.Pair{Key: types.LastTotalPowerKey, Value: cdc.MustMarshalBinaryBare(sdk.OneInt())}, + tmkv.Pair{Key: types.GetValidatorKey(valAddr1), Value: cdc.MustMarshalBinaryBare(val)}, tmkv.Pair{Key: types.LastValidatorPowerKey, Value: valAddr1.Bytes()}, - tmkv.Pair{Key: types.GetDelegationKey(delAddr1, valAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(del)}, - tmkv.Pair{Key: types.GetUBDKey(delAddr1, valAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(ubd)}, - tmkv.Pair{Key: types.GetREDKey(delAddr1, valAddr1, valAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(red)}, + tmkv.Pair{Key: types.GetDelegationKey(delAddr1, valAddr1), Value: cdc.MustMarshalBinaryBare(del)}, + tmkv.Pair{Key: types.GetUBDKey(delAddr1, valAddr1), Value: cdc.MustMarshalBinaryBare(ubd)}, + tmkv.Pair{Key: types.GetREDKey(delAddr1, valAddr1, valAddr1), Value: cdc.MustMarshalBinaryBare(red)}, tmkv.Pair{Key: []byte{0x99}, Value: []byte{0x99}}, } From e3e360546a0ab8d794d1550e7f3052f41d8cdb14 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 17:19:49 +0100 Subject: [PATCH 27/31] migrate genutil --- x/genutil/gentx.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/genutil/gentx.go b/x/genutil/gentx.go index 577fedcef6a9..064a67387b8b 100644 --- a/x/genutil/gentx.go +++ b/x/genutil/gentx.go @@ -102,7 +102,7 @@ func DeliverGenTxs( var tx authtypes.StdTx cdc.MustUnmarshalJSON(genTx, &tx) - bz := cdc.MustMarshalBinaryLengthPrefixed(tx) + bz := cdc.MustMarshalBinaryBare(tx) res := deliverTx(abci.RequestDeliverTx{Tx: bz}) if !res.IsOK() { From 3b9726f908db7f9809c0d44dff7418c6bb83a9b9 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 17:21:58 +0100 Subject: [PATCH 28/31] migrate simapp test helpers --- simapp/test_helpers.go | 2 +- simapp/utils_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 300235fe1c59..cf6dc8164efc 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -228,7 +228,7 @@ func SignCheckDeliver( priv..., ) - txBytes, err := cdc.MarshalBinaryLengthPrefixed(tx) + txBytes, err := cdc.MarshalBinaryBare(tx) require.Nil(t, err) // Must simulate now as CheckTx doesn't run Msgs anymore diff --git a/simapp/utils_test.go b/simapp/utils_test.go index 710c2b9d4863..729ceddc286a 100644 --- a/simapp/utils_test.go +++ b/simapp/utils_test.go @@ -31,7 +31,7 @@ func TestGetSimulationLog(t *testing.T) { }, { auth.StoreKey, - []tmkv.Pair{{Key: auth.GlobalAccountNumberKey, Value: cdc.MustMarshalBinaryLengthPrefixed(uint64(10))}}, + []tmkv.Pair{{Key: auth.GlobalAccountNumberKey, Value: cdc.MustMarshalBinaryBare(uint64(10))}}, "10", }, { From 8ff2f569f8ffdfad7c8ccc93de933cce1f19b9ad Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 17:25:32 +0100 Subject: [PATCH 29/31] migrate docs --- docs/architecture/adr-019-protobuf-state-encoding.md | 6 +++--- docs/core/store.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/architecture/adr-019-protobuf-state-encoding.md b/docs/architecture/adr-019-protobuf-state-encoding.md index 78a338cccb12..3f6a85b2af12 100644 --- a/docs/architecture/adr-019-protobuf-state-encoding.md +++ b/docs/architecture/adr-019-protobuf-state-encoding.md @@ -86,7 +86,7 @@ Example: // ... } - bz := cdc.MustMarshalBinaryLengthPrefixed(ts) + bz := cdc.MustMarshalBinaryBare(ts) ``` However, modules can vary greatly in purpose and design and so we must support the ability for modules @@ -161,12 +161,12 @@ func (c *Codec) MarshalAccount(accI authexported.Account) ([]byte, error) { return nil, err } - return c.Marshaler.MarshalBinaryLengthPrefixed(acc) + return c.Marshaler.MarshalBinaryBare(acc) } func (c *Codec) UnmarshalAccount(bz []byte) (authexported.Account, error) { acc := &Account{} - if err := c.Marshaler.UnmarshalBinaryLengthPrefixed(bz, acc); err != nil { + if err := c.Marshaler.UnmarshalBinaryBare(bz, acc); err != nil { return nil, err } diff --git a/docs/core/store.md b/docs/core/store.md index 35b3d0f2a2e1..31a8db919a0a 100644 --- a/docs/core/store.md +++ b/docs/core/store.md @@ -130,7 +130,7 @@ iterator := sdk.KVStorePrefixIterator(store, prefix) // proxy for store.Iterator defer iterator.Close() for ; iterator.Valid(); iterator.Next() { var object types.Object - keeper.cdc.MustUnmarshalBinaryLengthPrefixed(iterator.Value(), &object) + keeper.cdc.MustUnmarshalBinaryBare(iterator.Value(), &object) if cb(object) { break From 78f8b3d078eb5b66660e6bafd40bc74918c9a6f3 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 17:43:12 +0100 Subject: [PATCH 30/31] upgrade changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0345af7539d8..241452090743 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -148,6 +148,7 @@ Buffers for state serialization instead of Amino. to define their own concrete `MsgSubmitProposal` types. * The module now accepts a `Codec` interface which extends the `codec.Marshaler` interface by requiring a concrete codec to know how to serialize `Proposal` types. +* (codec) Now we favor the use of MarshalBinaryBare instead of LengthPrefixed in all cases that is not needed. ### Improvements From ca252732a36150d1a6b16d0c3b8d2553d2668816 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 13 Mar 2020 18:42:57 +0100 Subject: [PATCH 31/31] Update CHANGELOG.md Co-Authored-By: Alexander Bezobchuk --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 241452090743..1a19fb7b3961 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -148,7 +148,7 @@ Buffers for state serialization instead of Amino. to define their own concrete `MsgSubmitProposal` types. * The module now accepts a `Codec` interface which extends the `codec.Marshaler` interface by requiring a concrete codec to know how to serialize `Proposal` types. -* (codec) Now we favor the use of MarshalBinaryBare instead of LengthPrefixed in all cases that is not needed. +* (codec) [\#5799](https://github.com/cosmos/cosmos-sdk/pull/5799) Now we favor the use of MarshalBinaryBare instead of LengthPrefixed in all cases that is not needed. ### Improvements