Skip to content

Commit

Permalink
Merge branch 'master' into aaronc/fix-migrations-from-zero
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronc authored Mar 25, 2021
2 parents fac9078 + 7568b66 commit 631e807
Show file tree
Hide file tree
Showing 68 changed files with 953 additions and 935 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ issues:
- text: "ST1016:"
linters:
- stylecheck
- path: "legacy"
text: "SA1019:"
linters:
- staticcheck

max-issues-per-linter: 10000
max-same-issues: 10000

Expand Down
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#8363](https://github.com/cosmos/cosmos-sdk/pull/8363) Addresses no longer have a fixed 20-byte length. From the SDK modules' point of view, any 1-255 bytes-long byte array is a valid address.
* [\#8346](https://github.com/cosmos/cosmos-sdk/pull/8346) All CLI `tx` commands generate ServiceMsgs by default. Graceful Amino support has been added to ServiceMsgs to support signing legacy Msgs.
* (crypto/ed25519) [\#8690] Adopt zip1215 ed2559 verification rules.
* [\#8849](https://github.com/cosmos/cosmos-sdk/pull/8849) Upgrade module no longer supports time based upgrades.
* [\#8849](https://github.com/cosmos/cosmos-sdk/pull/8849) Upgrade module no longer supports time based upgrades.
* [\#8880](https://github.com/cosmos/cosmos-sdk/pull/8880) The CLI `simd migrate v0.40 ...` command has been renamed to `simd migrate v0.42`.
* [\#7477](https://github.com/cosmos/cosmos-sdk/pull/7477) Changed Bech32 Public Key serialization in the client facing functionality (CLI, MsgServer, QueryServer):
* updated the keyring display structure (it uses protobuf JSON serialization) - the output is more verbose.
* Renamed `MarshalAny` and `UnmarshalAny` to `MarshalInterface` and `UnmarshalInterface` respectively. These functions must take an interface as parameter (not a concrete type nor `Any` object). Underneath they use `Any` wrapping for correct protobuf serialization.
* CLI: removed `--text` flag from `show-node-id` command; the text format for public keys is not used any more - instead we use ProtoJSON.

### API Breaking Changes

Expand All @@ -65,6 +69,12 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/upgrade) [\#8743](https://github.com/cosmos/cosmos-sdk/pull/8743) `UpgradeHandler` includes a new argument `VersionMap` which helps facilitate in-place migrations.
* (x/auth) [\#8129](https://github.com/cosmos/cosmos-sdk/pull/8828) Updated `SigVerifiableTx.GetPubKeys` method signature to return error.
* [\#8682](https://github.com/cosmos/cosmos-sdk/pull/8682) `ante.NewAnteHandler` updated to receive all positional params as `ante.HandlerOptions` struct. If required fields aren't set, throws error accordingly.
* (x/staking/types) [\#7447](https://github.com/cosmos/cosmos-sdk/issues/7447) Remove bech32 PubKey support:
* `ValidatorI` interface update: `GetConsPubKey` renamed to `TmConsPubKey` (this is to clarify the return type: consensus public key must be a tendermint key); `TmConsPubKey`, `GetConsAddr` methods return error.
* `Validator` updated according to the `ValidatorI` changes described above.
* `ToTmValidator` function: added `error` to return values.
* `Validator.ConsensusPubkey` type changed from `string` to `codectypes.Any`.
* `MsgCreateValidator.Pubkey` type changed from `string` to `codectypes.Any`.
* (client) [\#8926](https://github.com/cosmos/cosmos-sdk/pull/8926) `client/tx.PrepareFactory` has been converted to a private function, as it's only used internally.
* (auth/tx) [\#8926](https://github.com/cosmos/cosmos-sdk/pull/8926) The `ProtoTxProvider` interface used as a workaround for transaction simulation has been removed.

Expand All @@ -79,7 +89,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (x/staking) [\#8909](https://github.com/cosmos/cosmos-sdk/pull/8909) Require self delegation in `MsgCreateValidator` to be at least one consensus power.
* (x/staking) [\#8909](https://github.com/cosmos/cosmos-sdk/pull/8909) Require self delegation in `MsgCreateValidator` to be at least one consensus power.
* (x/bank) [\#8614](https://github.com/cosmos/cosmos-sdk/issues/8614) Add `Name` and `Symbol` fields to denom metadata
* (x/auth) [\#8522](https://github.com/cosmos/cosmos-sdk/pull/8522) Allow to query all stored accounts
* (crypto/types) [\#8600](https://github.com/cosmos/cosmos-sdk/pull/8600) `CompactBitArray`: optimize the `NumTrueBitsBefore` method and add an `Equal` method.
Expand Down Expand Up @@ -189,6 +199,7 @@ he Cosmos Hub) should not use this release or any release in the v0.41.x series.
* (x/ibc) [\#8266](https://github.com/cosmos/cosmos-sdk/issues/8266) Add amino JSON support for IBC MsgTransfer in order to support Ledger text signing transfer transactions.
* (x/ibc) [\#8404](https://github.com/cosmos/cosmos-sdk/pull/8404) Reorder IBC `ChanOpenAck` and `ChanOpenConfirm` handler execution to perform core handler first, followed by application callbacks.


### Bug Fixes

* (simapp) [\#8418](https://github.com/cosmos/cosmos-sdk/pull/8418) Add balance coin to supply when adding a new genesis account
Expand Down
98 changes: 17 additions & 81 deletions client/debug/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package debug

import (
"encoding/base64"
"encoding/hex"
"fmt"
"strconv"
Expand All @@ -10,13 +9,12 @@ import (
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/version"
)

// Cmd creates a main CLI command
func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "debug",
Expand All @@ -31,90 +29,31 @@ func Cmd() *cobra.Command {
return cmd
}

// getPubKeyFromString returns a Tendermint PubKey (PubKeyEd25519) by attempting
// to decode the pubkey string from hex, base64, and finally bech32. If all
// encodings fail, an error is returned.
func getPubKeyFromString(pkstr string) (cryptotypes.PubKey, error) {
bz, err := hex.DecodeString(pkstr)
if err == nil {
if len(bz) == ed25519.PubKeySize {
return &ed25519.PubKey{Key: bz}, nil
}
}

bz, err = base64.StdEncoding.DecodeString(pkstr)
if err == nil {
if len(bz) == ed25519.PubKeySize {
return &ed25519.PubKey{Key: bz}, nil
}
}

pk, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeAccPub, pkstr)
if err == nil {
return pk, nil
}

pk, err = sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeValPub, pkstr)
if err == nil {
return pk, nil
}

pk, err = sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, pkstr)
if err == nil {
return pk, nil
}

return nil, fmt.Errorf("pubkey '%s' invalid; expected hex, base64, or bech32 of correct size", pkstr)
// getPubKeyFromString decodes SDK PubKey using JSON marshaler.
func getPubKeyFromString(ctx client.Context, pkstr string) (cryptotypes.PubKey, error) {
var pk cryptotypes.PubKey
err := ctx.JSONMarshaler.UnmarshalInterfaceJSON([]byte(pkstr), &pk)
return pk, err
}

func PubkeyCmd() *cobra.Command {
return &cobra.Command{
Use: "pubkey [pubkey]",
Short: "Decode a ED25519 pubkey from hex, base64, or bech32",
Long: fmt.Sprintf(`Decode a pubkey from hex, base64, or bech32.
Short: "Decode a pubkey from proto JSON",
Long: fmt.Sprintf(`Decode a pubkey from proto JSON and display it's address.
Example:
$ %s debug pubkey TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
$ %s debug pubkey cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg
`, version.AppName, version.AppName),
$ %s debug pubkey '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AurroA7jvfPd1AadmmOvWM2rJSwipXfRf8yD6pLbA2DJ"}'
`, version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

pk, err := getPubKeyFromString(args[0])
if err != nil {
return err
}

edPK, ok := pk.(*ed25519.PubKey)
if !ok {
return errors.Wrapf(errors.ErrInvalidType, "invalid pubkey type; expected ED25519")
}

pubKeyJSONBytes, err := clientCtx.LegacyAmino.MarshalJSON(edPK)
if err != nil {
return err
}
accPub, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, edPK)
if err != nil {
return err
}
valPub, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeValPub, edPK)
pk, err := getPubKeyFromString(clientCtx, args[0])
if err != nil {
return err
}
consenusPub, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, edPK)
if err != nil {
return err
}

cmd.Println("Address:", edPK.Address())
cmd.Printf("Hex: %X\n", edPK.Key)
cmd.Println("JSON (base64):", string(pubKeyJSONBytes))
cmd.Println("Bech32 Acc:", accPub)
cmd.Println("Bech32 Validator Operator:", valPub)
cmd.Println("Bech32 Validator Consensus:", consenusPub)

cmd.Println("Address:", pk.Address())
cmd.Println("PubKey Hex:", hex.EncodeToString(pk.Bytes()))
return nil
},
}
Expand All @@ -125,7 +64,7 @@ func AddrCmd() *cobra.Command {
Use: "addr [address]",
Short: "Convert an address between hex and bech32",
Long: fmt.Sprintf(`Convert an address between hex encoding and bech32.
Example:
$ %s debug addr cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg
`, version.AppName),
Expand All @@ -152,13 +91,10 @@ $ %s debug addr cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg
}
}

accAddr := sdk.AccAddress(addr)
valAddr := sdk.ValAddress(addr)

cmd.Println("Address:", addr)
cmd.Printf("Address (hex): %X\n", addr)
cmd.Printf("Bech32 Acc: %s\n", accAddr)
cmd.Printf("Bech32 Val: %s\n", valAddr)
cmd.Printf("Bech32 Acc: %s\n", sdk.AccAddress(addr))
cmd.Printf("Bech32 Val: %s\n", sdk.ValAddress(addr))
return nil
},
}
Expand All @@ -169,7 +105,7 @@ func RawBytesCmd() *cobra.Command {
Use: "raw-bytes [raw-bytes]",
Short: "Convert raw bytes output (eg. [10 21 13 255]) to hex",
Long: fmt.Sprintf(`Convert raw-bytes to hex.
Example:
$ %s debug raw-bytes [72 101 108 108 111 44 32 112 108 97 121 103 114 111 117 110 100]
`, version.AppName),
Expand Down
68 changes: 26 additions & 42 deletions client/grpc/tmservice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,33 +95,7 @@ func (s queryServer) GetLatestValidatorSet(ctx context.Context, req *GetLatestVa
if err != nil {
return nil, err
}

validatorsRes, err := rpc.GetValidators(ctx, s.clientCtx, nil, &page, &limit)
if err != nil {
return nil, err
}

outputValidatorsRes := &GetLatestValidatorSetResponse{
BlockHeight: validatorsRes.BlockHeight,
Validators: make([]*Validator, len(validatorsRes.Validators)),
Pagination: &qtypes.PageResponse{
Total: validatorsRes.Total,
},
}

for i, validator := range validatorsRes.Validators {
anyPub, err := codectypes.NewAnyWithValue(validator.PubKey)
if err != nil {
return nil, err
}
outputValidatorsRes.Validators[i] = &Validator{
Address: validator.Address.String(),
ProposerPriority: validator.ProposerPriority,
PubKey: anyPub,
VotingPower: validator.VotingPower,
}
}
return outputValidatorsRes, nil
return validatorsOutput(ctx, s.clientCtx, nil, page, limit)
}

func (m *GetLatestValidatorSetResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
Expand Down Expand Up @@ -149,32 +123,42 @@ func (s queryServer) GetValidatorSetByHeight(ctx context.Context, req *GetValida
if req.Height > chainHeight {
return nil, status.Error(codes.InvalidArgument, "requested block height is bigger then the chain length")
}

validatorsRes, err := rpc.GetValidators(ctx, s.clientCtx, &req.Height, &page, &limit)

r, err := validatorsOutput(ctx, s.clientCtx, &req.Height, page, limit)
if err != nil {
return nil, err
}
return &GetValidatorSetByHeightResponse{
BlockHeight: r.BlockHeight,
Validators: r.Validators,
Pagination: r.Pagination,
}, nil
}

outputValidatorsRes := &GetValidatorSetByHeightResponse{
BlockHeight: validatorsRes.BlockHeight,
Validators: make([]*Validator, len(validatorsRes.Validators)),
Pagination: &qtypes.PageResponse{Total: validatorsRes.Total},
func validatorsOutput(ctx context.Context, cctx client.Context, height *int64, page, limit int) (*GetLatestValidatorSetResponse, error) {
vs, err := rpc.GetValidators(ctx, cctx, height, &page, &limit)
if err != nil {
return nil, err
}

for i, validator := range validatorsRes.Validators {
anyPub, err := codectypes.NewAnyWithValue(validator.PubKey)
resp := GetLatestValidatorSetResponse{
BlockHeight: vs.BlockHeight,
Validators: make([]*Validator, len(vs.Validators)),
Pagination: &qtypes.PageResponse{
Total: vs.Total,
},
}
for i, v := range vs.Validators {
anyPub, err := codectypes.NewAnyWithValue(v.PubKey)
if err != nil {
return nil, err
}
outputValidatorsRes.Validators[i] = &Validator{
Address: validator.Address.String(),
ProposerPriority: validator.ProposerPriority,
resp.Validators[i] = &Validator{
Address: v.Address.String(),
ProposerPriority: v.ProposerPriority,
PubKey: anyPub,
VotingPower: validator.VotingPower,
VotingPower: v.VotingPower,
}
}
return outputValidatorsRes, nil
return &resp, nil
}

// GetNodeInfo implements ServiceServer.GetNodeInfo
Expand Down
Loading

0 comments on commit 631e807

Please sign in to comment.