From 0034e4845826bf97032d08a13c37d68d414cc573 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 19 Nov 2020 01:10:11 +0100 Subject: [PATCH 1/3] Bech32 PubKey: use protobuf in slashing keeper --- x/slashing/keeper/keeper.go | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/x/slashing/keeper/keeper.go b/x/slashing/keeper/keeper.go index 999e82404bd..5264e45948a 100644 --- a/x/slashing/keeper/keeper.go +++ b/x/slashing/keeper/keeper.go @@ -42,33 +42,27 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { } // AddPubkey sets a address-pubkey relation -func (k Keeper) AddPubkey(ctx sdk.Context, pubkey cryptotypes.PubKey) { - addr := pubkey.Address() - - pkStr, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, pubkey) +func (k Keeper) AddPubkey(ctx sdk.Context, pubkey cryptotypes.PubKey) error { + bz, err := codec.MarshalAny(k.cdc, pubkey) if err != nil { - panic(fmt.Errorf("error while setting address-pubkey relation: %s", addr)) + return err } - - k.setAddrPubkeyRelation(ctx, addr, pkStr) + store := ctx.KVStore(k.storeKey) + key := types.AddrPubkeyRelationKey(pubkey.Address()) + store.Set(key, bz) + return nil } // GetPubkey returns the pubkey from the adddress-pubkey relation -func (k Keeper) GetPubkey(ctx sdk.Context, address cryptotypes.Address) (cryptotypes.PubKey, error) { +func (k Keeper) GetPubkey(ctx sdk.Context, a cryptotypes.Address) (cryptotypes.PubKey, error) { store := ctx.KVStore(k.storeKey) - - var pubkey gogotypes.StringValue - err := k.cdc.UnmarshalBinaryBare(store.Get(types.AddrPubkeyRelationKey(address)), &pubkey) - if err != nil { - return nil, fmt.Errorf("address %s not found", sdk.ConsAddress(address)) + bz := store.Get(types.AddrPubkeyRelationKey(a)) + if bz == nil { + return nil, fmt.Errorf("address %s not found", sdk.ConsAddress(a)) } - - pkStr, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, pubkey.Value) - if err != nil { - return pkStr, err - } - - return pkStr, nil + var pk cryptotypes.PubKey + err := codec.UnmarshalAny(k.cdc, &pk, bz) + return pk, err } // Slash attempts to slash a validator. The slash is delegated to the staking From a4130f5821ab9cc44022de06a7f0c44faef53619 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 19 Nov 2020 02:19:19 +0100 Subject: [PATCH 2/3] remove unused function --- x/slashing/keeper/keeper.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/x/slashing/keeper/keeper.go b/x/slashing/keeper/keeper.go index 5264e45948a..b5304a6c5e2 100644 --- a/x/slashing/keeper/keeper.go +++ b/x/slashing/keeper/keeper.go @@ -3,8 +3,6 @@ package keeper import ( "fmt" - gogotypes "github.com/gogo/protobuf/types" - "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/codec" @@ -93,13 +91,6 @@ func (k Keeper) Jail(ctx sdk.Context, consAddr sdk.ConsAddress) { k.sk.Jail(ctx, consAddr) } -func (k Keeper) setAddrPubkeyRelation(ctx sdk.Context, addr cryptotypes.Address, pubkey string) { - store := ctx.KVStore(k.storeKey) - - bz := k.cdc.MustMarshalBinaryBare(&gogotypes.StringValue{Value: pubkey}) - store.Set(types.AddrPubkeyRelationKey(addr), bz) -} - func (k Keeper) deleteAddrPubkeyRelation(ctx sdk.Context, addr cryptotypes.Address) { store := ctx.KVStore(k.storeKey) store.Delete(types.AddrPubkeyRelationKey(addr)) From fdac39813cb6627df843ab7852308330f45d26d2 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 19 Nov 2020 13:33:27 +0100 Subject: [PATCH 3/3] changelog update --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index efca4d9bd33..7b2c97295b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,11 +37,14 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] ### Improvements -- (SDK) [\#7925](https://github.com/cosmos/cosmos-sdk/pull/7925) Updated dependencies to use gRPC v1.33.2 +* (SDK) [\#7925](https://github.com/cosmos/cosmos-sdk/pull/7925) Updated dependencies to use gRPC v1.33.2 * Updated gRPC dependency to v1.33.2 * Updated iavl dependency to v0.15-rc2 * (version) [\#7848](https://github.com/cosmos/cosmos-sdk/pull/7848) [\#7941](https://github.com/cosmos/cosmos-sdk/pull/7941) `version --long` output now shows the list of build dependencies and replaced build dependencies. +### State Machine Breaking Changes +* (x/upgrade) [\#7979](https://github.com/cosmos/cosmos-sdk/pull/7979) keeper pubkey storage serialization migration from bech32 to protobuf. + ### Bug Fixes * (crypto) [\#7966](https://github.com/cosmos/cosmos-sdk/issues/7966) `Bip44Params` `String()` function now correctly returns the absolute HD path by adding the `m/` prefix.