Merge pull request #7979 from cosmos/robert/bech32-pubkey-slashing
Bech32 PubKey: use protobuf in slashing keeper
This commit is contained in:
commit
a054da8d62
|
@ -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.
|
||||
|
|
|
@ -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"
|
||||
|
@ -42,33 +40,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
|
||||
|
@ -99,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))
|
||||
|
|
Loading…
Reference in New Issue