Skip to content

Commit

Permalink
Merge PR cosmos#5527: Bump Tendermint Version to v0.33.0
Browse files Browse the repository at this point in the history
* Bump Tendermint version to v0.33.0

* Deprecate old cmn package with new packages

* Update update DB APIs

* More DB updates

* Bump IAVL to v0.13.0

* Handle error returned by iavl.NewMutableTree

* Fix some IAVL stuffs

* Update IAVL

* More updates

* Passing tests

* Fix unit tests

Co-authored-by: Jack Zampolin <[email protected]>
  • Loading branch information
alexanderbez and jackzampolin committed Jan 16, 2020
1 parent c92a738 commit c1991e3
Show file tree
Hide file tree
Showing 88 changed files with 577 additions and 344 deletions.
14 changes: 11 additions & 3 deletions client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,18 @@ func NewCLIContextWithInputAndFrom(input io.Reader, from string) CLIContext {
genOnly := viper.GetBool(flags.FlagGenerateOnly)
fromAddress, fromName, err := GetFromFields(input, from, genOnly)
if err != nil {
fmt.Printf("failed to get from fields: %v", err)
fmt.Printf("failed to get from fields: %v\n", err)
os.Exit(1)
}

if !genOnly {
nodeURI = viper.GetString(flags.FlagNode)
if nodeURI != "" {
rpc = rpcclient.NewHTTP(nodeURI, "/websocket")
rpc, err = rpcclient.NewHTTP(nodeURI, "/websocket")
if err != nil {
fmt.Printf("failted to get client: %v\n", err)
os.Exit(1)
}
}
}

Expand Down Expand Up @@ -154,7 +158,11 @@ func (ctx CLIContext) WithTrustNode(trustNode bool) CLIContext {
// WithNodeURI returns a copy of the context with an updated node URI.
func (ctx CLIContext) WithNodeURI(nodeURI string) CLIContext {
ctx.NodeURI = nodeURI
ctx.Client = rpcclient.NewHTTP(nodeURI, "/websocket")
client, err := rpcclient.NewHTTP(nodeURI, "/websocket")
if err != nil {
panic(err)
}
ctx.Client = client
return ctx
}

Expand Down
8 changes: 4 additions & 4 deletions client/context/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/merkle"
cmn "github.com/tendermint/tendermint/libs/common"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
tmliteErr "github.com/tendermint/tendermint/lite/errors"
tmliteProxy "github.com/tendermint/tendermint/lite/proxy"
rpcclient "github.com/tendermint/tendermint/rpc/client"
Expand Down Expand Up @@ -45,7 +45,7 @@ func (ctx CLIContext) QueryWithData(path string, data []byte) ([]byte, int64, er
// QueryStore performs a query to a Tendermint node with the provided key and
// store name. It returns the result and height of the query upon success
// or an error if the query fails.
func (ctx CLIContext) QueryStore(key cmn.HexBytes, storeName string) ([]byte, int64, error) {
func (ctx CLIContext) QueryStore(key tmbytes.HexBytes, storeName string) ([]byte, int64, error) {
return ctx.queryStore(key, storeName, "key")
}

Expand Down Expand Up @@ -77,7 +77,7 @@ func (ctx CLIContext) GetFromName() string {
// or an error if the query fails. In addition, it will verify the returned
// proof if TrustNode is disabled. If proof verification fails or the query
// height is invalid, an error will be returned.
func (ctx CLIContext) query(path string, key cmn.HexBytes) (res []byte, height int64, err error) {
func (ctx CLIContext) query(path string, key tmbytes.HexBytes) (res []byte, height int64, err error) {
node, err := ctx.GetNode()
if err != nil {
return res, height, err
Expand Down Expand Up @@ -167,7 +167,7 @@ func (ctx CLIContext) verifyProof(queryPath string, resp abci.ResponseQuery) err
// queryStore performs a query to a Tendermint node with the provided a store
// name and path. It returns the result and height of the query upon success
// or an error if the query fails.
func (ctx CLIContext) queryStore(key cmn.HexBytes, storeName, endPath string) ([]byte, int64, error) {
func (ctx CLIContext) queryStore(key tmbytes.HexBytes, storeName, endPath string) ([]byte, int64, error) {
path := fmt.Sprintf("/store/%s/%s", storeName, endPath)
return ctx.query(path, key)
}
Expand Down
7 changes: 6 additions & 1 deletion client/context/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ func CreateVerifier(ctx CLIContext, cacheSize int) (tmlite.Verifier, error) {
return nil, errors.New("must provide a valid RPC client or RPC URI to create verifier")
}

var err error

// create an RPC client based off of the RPC URI if no RPC client exists
client := ctx.Client
if client == nil {
client = rpcclient.NewHTTP(ctx.NodeURI, "/websocket")
client, err = rpcclient.NewHTTP(ctx.NodeURI, "/websocket")
if err != nil {
return nil, err
}
}

return tmliteproxy.NewVerifier(
Expand Down
3 changes: 2 additions & 1 deletion client/context/verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"io/ioutil"
"testing"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/client/context"
)

func TestCreateVerifier(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions client/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ const (
FlagOutputDocument = "output-document" // inspired by wget -O
FlagSkipConfirmation = "yes"
FlagKeyringBackend = "keyring-backend"
FlagPage = "page"
FlagLimit = "limit"
)

// LineBreak can be included in a command list to provide a blank line
Expand Down
6 changes: 2 additions & 4 deletions client/rpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ func getBlock(cliCtx context.CLIContext, height *int64) ([]byte, error) {
return nil, err
}

err = tmliteProxy.ValidateBlockMeta(res.BlockMeta, check)
if err != nil {
if err := tmliteProxy.ValidateHeader(&res.Block.Header, check); err != nil {
return nil, err
}

err = tmliteProxy.ValidateBlock(res.Block, check)
if err != nil {
if err = tmliteProxy.ValidateBlock(res.Block, check); err != nil {
return nil, err
}
}
Expand Down
39 changes: 34 additions & 5 deletions client/rpc/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func ValidatorCommand(cdc *codec.Codec) *cobra.Command {

cliCtx := context.NewCLIContext().WithCodec(cdc)

result, err := GetValidators(cliCtx, height)
result, err := GetValidators(cliCtx, height, viper.GetInt(flags.FlagPage), viper.GetInt(flags.FlagLimit))
if err != nil {
return err
}
Expand All @@ -60,6 +60,9 @@ func ValidatorCommand(cdc *codec.Codec) *cobra.Command {
viper.BindPFlag(flags.FlagTrustNode, cmd.Flags().Lookup(flags.FlagTrustNode))
cmd.Flags().Bool(flags.FlagIndentResponse, false, "indent JSON response")
viper.BindPFlag(flags.FlagIndentResponse, cmd.Flags().Lookup(flags.FlagIndentResponse))
cmd.Flags().Int(flags.FlagPage, 0, "Query a specific page of paginated results")
viper.BindPFlag(flags.FlagPage, cmd.Flags().Lookup(flags.FlagPage))
cmd.Flags().Int(flags.FlagLimit, 100, "Query number of results returned per page")

return cmd
}
Expand Down Expand Up @@ -114,14 +117,14 @@ func bech32ValidatorOutput(validator *tmtypes.Validator) (ValidatorOutput, error
}

// GetValidators from client
func GetValidators(cliCtx context.CLIContext, height *int64) (ResultValidatorsOutput, error) {
func GetValidators(cliCtx context.CLIContext, height *int64, page, limit int) (ResultValidatorsOutput, error) {
// get the node
node, err := cliCtx.GetNode()
if err != nil {
return ResultValidatorsOutput{}, err
}

validatorsRes, err := node.Validators(height)
validatorsRes, err := node.Validators(height, page, limit)
if err != nil {
return ResultValidatorsOutput{}, err
}
Expand Down Expand Up @@ -159,6 +162,18 @@ func ValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)

page, err := strconv.ParseInt(vars["page"], 10, 64)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse page")
return
}

limit, err := strconv.ParseInt(vars["limit"], 10, 64)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse limit")
return
}

height, err := strconv.ParseInt(vars["height"], 10, 64)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse block height; assumed format is '/validatorsets/{height}'")
Expand All @@ -175,7 +190,7 @@ func ValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return
}

output, err := GetValidators(cliCtx, &height)
output, err := GetValidators(cliCtx, &height, int(page), int(limit))
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
Expand All @@ -187,7 +202,21 @@ func ValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
// Latest Validator Set REST handler
func LatestValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
output, err := GetValidators(cliCtx, nil)
vars := mux.Vars(r)

page, err := strconv.ParseInt(vars["page"], 10, 64)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse page")
return
}

limit, err := strconv.ParseInt(vars["limit"], 10, 64)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse limit")
return
}

output, err := GetValidators(cliCtx, nil, int(page), int(limit))
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
Expand Down
2 changes: 2 additions & 0 deletions crypto/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ func ExamplePrintRegisteredTypes() {
//| ---- | ---- | ------ | ----- | ------ |
//| PrivKeyLedgerSecp256k1 | tendermint/PrivKeyLedgerSecp256k1 | 0x10CAB393 | variable | |
//| PubKeyEd25519 | tendermint/PubKeyEd25519 | 0x1624DE64 | 0x20 | |
//| PubKeySr25519 | tendermint/PubKeySr25519 | 0x0DFB1005 | 0x20 | |
//| PubKeySecp256k1 | tendermint/PubKeySecp256k1 | 0xEB5AE987 | 0x21 | |
//| PubKeyMultisigThreshold | tendermint/PubKeyMultisigThreshold | 0x22C1F7E2 | variable | |
//| PrivKeyEd25519 | tendermint/PrivKeyEd25519 | 0xA3288910 | 0x40 | |
//| PrivKeySr25519 | tendermint/PrivKeySr25519 | 0x2F82D78B | 0x20 | |
//| PrivKeySecp256k1 | tendermint/PrivKeySecp256k1 | 0xE1B0F79B | 0x20 | |
}

Expand Down
52 changes: 42 additions & 10 deletions crypto/keys/keybase.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ func (kb dbKeybase) CreateMulti(name string, pub tmcrypto.PubKey) (Info, error)
func (kb dbKeybase) List() ([]Info, error) {
var res []Info

iter := kb.db.Iterator(nil, nil)
iter, err := kb.db.Iterator(nil, nil)
if err != nil {
return nil, err
}

defer iter.Close()

for ; iter.Valid(); iter.Next() {
Expand All @@ -153,7 +157,11 @@ func (kb dbKeybase) List() ([]Info, error) {

// Get returns the public information about one key.
func (kb dbKeybase) Get(name string) (Info, error) {
bs := kb.db.Get(infoKey(name))
bs, err := kb.db.Get(infoKey(name))
if err != nil {
return nil, err
}

if len(bs) == 0 {
return nil, keyerror.NewErrKeyNotFound(name)
}
Expand All @@ -164,12 +172,20 @@ func (kb dbKeybase) Get(name string) (Info, error) {
// GetByAddress returns Info based on a provided AccAddress. An error is returned
// if the address does not exist.
func (kb dbKeybase) GetByAddress(address types.AccAddress) (Info, error) {
ik := kb.db.Get(addrKey(address))
ik, err := kb.db.Get(addrKey(address))
if err != nil {
return nil, err
}

if len(ik) == 0 {
return nil, fmt.Errorf("key with address %s not found", address)
}

bs := kb.db.Get(ik)
bs, err := kb.db.Get(ik)
if err != nil {
return nil, err
}

return unmarshalInfo(bs)
}

Expand Down Expand Up @@ -242,7 +258,11 @@ func (kb dbKeybase) ExportPrivateKeyObject(name string, passphrase string) (tmcr
}

func (kb dbKeybase) Export(name string) (armor string, err error) {
bz := kb.db.Get(infoKey(name))
bz, err := kb.db.Get(infoKey(name))
if err != nil {
return "", err
}

if bz == nil {
return "", fmt.Errorf("no key to export with name %s", name)
}
Expand All @@ -253,7 +273,11 @@ func (kb dbKeybase) Export(name string) (armor string, err error) {
// ExportPubKey returns public keys in ASCII armored format. It retrieves a Info
// object by its name and return the public key in a portable format.
func (kb dbKeybase) ExportPubKey(name string) (armor string, err error) {
bz := kb.db.Get(infoKey(name))
bz, err := kb.db.Get(infoKey(name))
if err != nil {
return "", err
}

if bz == nil {
return "", fmt.Errorf("no key to export with name %s", name)
}
Expand Down Expand Up @@ -302,9 +326,13 @@ func (kb dbKeybase) ImportPrivKey(name string, armor string, passphrase string)
}

func (kb dbKeybase) Import(name string, armor string) (err error) {
bz := kb.db.Get(infoKey(name))
bz, err := kb.db.Get(infoKey(name))
if err != nil {
return err
}

if len(bz) > 0 {
return errors.New("Cannot overwrite data for name " + name)
return errors.New("cannot overwrite data for name " + name)
}

infoBytes, err := mintkey.UnarmorInfoBytes(armor)
Expand All @@ -320,9 +348,13 @@ func (kb dbKeybase) Import(name string, armor string) (err error) {
// a public key only, i.e. it will not be possible to sign with it as it lacks the
// secret key.
func (kb dbKeybase) ImportPubKey(name string, armor string) (err error) {
bz := kb.db.Get(infoKey(name))
bz, err := kb.db.Get(infoKey(name))
if err != nil {
return err
}

if len(bz) > 0 {
return errors.New("Cannot overwrite data for name " + name)
return errors.New("cannot overwrite data for name " + name)
}

pubBytes, algo, err := mintkey.UnarmorPubKeyBytes(armor)
Expand Down
4 changes: 2 additions & 2 deletions crypto/keys/lazy_keybase.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"github.com/tendermint/tendermint/crypto"
cmn "github.com/tendermint/tendermint/libs/common"
tmos "github.com/tendermint/tendermint/libs/os"

sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand All @@ -20,7 +20,7 @@ type lazyKeybase struct {

// New creates a new instance of a lazy keybase.
func New(name, dir string, opts ...KeybaseOption) Keybase {
if err := cmn.EnsureDir(dir, 0700); err != nil {
if err := tmos.EnsureDir(dir, 0700); err != nil {
panic(fmt.Sprintf("failed to create Keybase directory: %s", err))
}

Expand Down
6 changes: 3 additions & 3 deletions crypto/keys/mintkey/mintkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
"github.com/tendermint/tendermint/crypto/xsalsa20symmetric"

cmn "github.com/tendermint/tendermint/libs/common"
tmos "github.com/tendermint/tendermint/libs/os"

"github.com/cosmos/cosmos-sdk/crypto/keys/keyerror"
)
Expand Down Expand Up @@ -134,7 +134,7 @@ func encryptPrivKey(privKey crypto.PrivKey, passphrase string) (saltBytes []byte
saltBytes = crypto.CRandBytes(16)
key, err := bcrypt.GenerateFromPassword(saltBytes, []byte(passphrase), BcryptSecurityParameter)
if err != nil {
cmn.Exit("Error generating bcrypt key from passphrase: " + err.Error())
tmos.Exit("Error generating bcrypt key from passphrase: " + err.Error())
}
key = crypto.Sha256(key) // get 32 bytes
privKeyBytes := privKey.Bytes()
Expand Down Expand Up @@ -171,7 +171,7 @@ func UnarmorDecryptPrivKey(armorStr string, passphrase string) (privKey crypto.P
func decryptPrivKey(saltBytes []byte, encBytes []byte, passphrase string) (privKey crypto.PrivKey, err error) {
key, err := bcrypt.GenerateFromPassword(saltBytes, []byte(passphrase), BcryptSecurityParameter)
if err != nil {
cmn.Exit("error generating bcrypt key from passphrase: " + err.Error())
tmos.Exit("error generating bcrypt key from passphrase: " + err.Error())
}
key = crypto.Sha256(key) // Get 32 bytes
privKeyBytes, err := xsalsa20symmetric.DecryptSymmetric(encBytes, key)
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require (
github.com/bartekn/go-bip39 v0.0.0-20171116152956-a05967ea095d
github.com/bgentry/speakeasy v0.1.0
github.com/btcsuite/btcd v0.0.0-20190115013929-ed77733ec07d
github.com/cosmos/go-bip39 v0.0.0-20180618194314-52158e4697b8
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d
github.com/cosmos/ledger-cosmos-go v0.11.1
github.com/gogo/protobuf v1.3.1
github.com/golang/mock v1.3.1-0.20190508161146-9fa652df1129
Expand All @@ -24,9 +24,9 @@ require (
github.com/tendermint/btcd v0.1.1
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15
github.com/tendermint/go-amino v0.15.1
github.com/tendermint/iavl v0.12.4
github.com/tendermint/tendermint v0.32.9
github.com/tendermint/tm-db v0.2.0
github.com/tendermint/iavl v0.13.0
github.com/tendermint/tendermint v0.33.0
github.com/tendermint/tm-db v0.4.0
gopkg.in/yaml.v2 v2.2.7
)

Expand Down
Loading

0 comments on commit c1991e3

Please sign in to comment.