Merge PR #2219: Update to Tendermint 0.24 (except NextValSet offsets)
This commit is contained in:
+22
-10
@@ -4,6 +4,8 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
@@ -15,14 +17,18 @@ import (
|
||||
cskeys "github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmlite "github.com/tendermint/tendermint/lite"
|
||||
tmliteProxy "github.com/tendermint/tendermint/lite/proxy"
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
||||
"os"
|
||||
)
|
||||
|
||||
const ctxAccStoreName = "acc"
|
||||
|
||||
var (
|
||||
verifier tmlite.Verifier
|
||||
)
|
||||
|
||||
// CLIContext implements a typical CLI context created in SDK modules for
|
||||
// transaction handling and queries.
|
||||
type CLIContext struct {
|
||||
@@ -39,7 +45,7 @@ type CLIContext struct {
|
||||
Async bool
|
||||
JSON bool
|
||||
PrintResponse bool
|
||||
Certifier tmlite.Certifier
|
||||
Verifier tmlite.Verifier
|
||||
DryRun bool
|
||||
GenerateOnly bool
|
||||
fromAddress types.AccAddress
|
||||
@@ -59,6 +65,11 @@ func NewCLIContext() CLIContext {
|
||||
from := viper.GetString(client.FlagFrom)
|
||||
fromAddress, fromName := fromFields(from)
|
||||
|
||||
// We need to use a single verifier for all contexts
|
||||
if verifier == nil {
|
||||
verifier = createVerifier()
|
||||
}
|
||||
|
||||
return CLIContext{
|
||||
Client: rpc,
|
||||
Output: os.Stdout,
|
||||
@@ -71,7 +82,7 @@ func NewCLIContext() CLIContext {
|
||||
Async: viper.GetBool(client.FlagAsync),
|
||||
JSON: viper.GetBool(client.FlagJson),
|
||||
PrintResponse: viper.GetBool(client.FlagPrintResponse),
|
||||
Certifier: createCertifier(),
|
||||
Verifier: verifier,
|
||||
DryRun: viper.GetBool(client.FlagDryRun),
|
||||
GenerateOnly: viper.GetBool(client.FlagGenerateOnly),
|
||||
fromAddress: fromAddress,
|
||||
@@ -79,7 +90,7 @@ func NewCLIContext() CLIContext {
|
||||
}
|
||||
}
|
||||
|
||||
func createCertifier() tmlite.Certifier {
|
||||
func createVerifier() tmlite.Verifier {
|
||||
trustNodeDefined := viper.IsSet(client.FlagTrustNode)
|
||||
if !trustNodeDefined {
|
||||
return nil
|
||||
@@ -108,15 +119,16 @@ func createCertifier() tmlite.Certifier {
|
||||
fmt.Printf("Must specify these options: %s when --trust-node is false\n", errMsg.String())
|
||||
os.Exit(1)
|
||||
}
|
||||
node := rpcclient.NewHTTP(nodeURI, "/websocket")
|
||||
verifier, err := tmliteProxy.NewVerifier(chainID, filepath.Join(home, ".gaialite"), node, log.NewNopLogger())
|
||||
|
||||
certifier, err := tmliteProxy.GetCertifier(chainID, home, nodeURI)
|
||||
if err != nil {
|
||||
fmt.Printf("Create certifier failed: %s\n", err.Error())
|
||||
fmt.Printf("Create verifier failed: %s\n", err.Error())
|
||||
fmt.Printf("Please check network connection and verify the address of the node to connect to\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return certifier
|
||||
return verifier
|
||||
}
|
||||
|
||||
func fromFields(from string) (fromAddr types.AccAddress, fromName string) {
|
||||
@@ -207,8 +219,8 @@ func (ctx CLIContext) WithUseLedger(useLedger bool) CLIContext {
|
||||
return ctx
|
||||
}
|
||||
|
||||
// WithCertifier - return a copy of the context with an updated Certifier
|
||||
func (ctx CLIContext) WithCertifier(certifier tmlite.Certifier) CLIContext {
|
||||
ctx.Certifier = certifier
|
||||
// WithVerifier - return a copy of the context with an updated Verifier
|
||||
func (ctx CLIContext) WithVerifier(verifier tmlite.Verifier) CLIContext {
|
||||
ctx.Verifier = verifier
|
||||
return ctx
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/store"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
"github.com/tendermint/tendermint/lite"
|
||||
tmliteErr "github.com/tendermint/tendermint/lite/errors"
|
||||
tmliteProxy "github.com/tendermint/tendermint/lite/proxy"
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
// GetNode returns an RPC client. If the context's client is not defined, an
|
||||
@@ -184,14 +184,14 @@ func (ctx CLIContext) query(path string, key cmn.HexBytes) (res []byte, err erro
|
||||
return resp.Value, nil
|
||||
}
|
||||
|
||||
// Certify verifies the consensus proof at given height.
|
||||
func (ctx CLIContext) Certify(height int64) (lite.Commit, error) {
|
||||
check, err := tmliteProxy.GetCertifiedCommit(height, ctx.Client, ctx.Certifier)
|
||||
// Verify verifies the consensus proof at given height.
|
||||
func (ctx CLIContext) Verify(height int64) (tmtypes.SignedHeader, error) {
|
||||
check, err := tmliteProxy.GetCertifiedCommit(height, ctx.Client, ctx.Verifier)
|
||||
switch {
|
||||
case tmliteErr.IsCommitNotFoundErr(err):
|
||||
return lite.Commit{}, ErrVerifyCommit(height)
|
||||
case tmliteErr.IsErrCommitNotFound(err):
|
||||
return tmtypes.SignedHeader{}, ErrVerifyCommit(height)
|
||||
case err != nil:
|
||||
return lite.Commit{}, err
|
||||
return tmtypes.SignedHeader{}, err
|
||||
}
|
||||
|
||||
return check, nil
|
||||
@@ -199,12 +199,12 @@ func (ctx CLIContext) Certify(height int64) (lite.Commit, error) {
|
||||
|
||||
// verifyProof perform response proof verification.
|
||||
func (ctx CLIContext) verifyProof(_ string, resp abci.ResponseQuery) error {
|
||||
if ctx.Certifier == nil {
|
||||
if ctx.Verifier == nil {
|
||||
return fmt.Errorf("missing valid certifier to verify data from distrusted node")
|
||||
}
|
||||
|
||||
// the AppHash for height H is in header H+1
|
||||
commit, err := ctx.Certify(resp.Height + 1)
|
||||
commit, err := ctx.Verify(resp.Height + 1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user