Merge PR #5527: Bump Tendermint Version to v0.33.0
* 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 <jack.zampolin@gmail.com>
This commit is contained in:
committed by
Jack Zampolin
co-authored by
Jack Zampolin
parent
c92a7389ff
commit
c1991e31bd
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
+2
-4
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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}'")
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user