From b98bfc01ae586b0f72f1c30a9a56b62dd4b660b3 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 28 Jul 2017 14:49:28 -0400 Subject: [PATCH] Add --trust-node flag to cli to skip proofs on queries --- client/commands/proofs/get.go | 11 +++++++++-- client/commands/proofs/root.go | 7 +++++-- tests/cli/basictx.sh | 13 +++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/client/commands/proofs/get.go b/client/commands/proofs/get.go index 34638698cc..e392e96db7 100644 --- a/client/commands/proofs/get.go +++ b/client/commands/proofs/get.go @@ -26,6 +26,7 @@ import ( func GetAndParseAppProof(key []byte, data interface{}) (lc.Proof, error) { height := GetHeight() node := commands.GetNode() + prover := proofs.NewAppProver(node) proof, err := GetProof(node, prover, key, height) @@ -43,7 +44,12 @@ func GetProof(node client.Client, prover lc.Prover, key []byte, height int) (pro if err != nil { return } - ph := int(proof.BlockHeight()) + + // short-circuit with no proofs + if viper.GetBool(FlagTrustNode) { + return proof, err + } + // here is the certifier, root of all knowledge cert, err := commands.GetCertifier() if err != nil { @@ -55,6 +61,7 @@ func GetProof(node client.Client, prover lc.Prover, key []byte, height int) (pro // FIXME: cannot use cert.GetByHeight for now, as it also requires // Validators and will fail on querying tendermint for non-current height. // When this is supported, we should use it instead... + ph := int(proof.BlockHeight()) client.WaitForHeight(node, ph, nil) commit, err := node.Commit(ph) if err != nil { @@ -96,7 +103,7 @@ func ParseHexKey(args []string, argname string) ([]byte, error) { } func GetHeight() int { - return viper.GetInt(heightFlag) + return viper.GetInt(FlagHeight) } type proof struct { diff --git a/client/commands/proofs/root.go b/client/commands/proofs/root.go index 15b49b8c90..65691980b3 100644 --- a/client/commands/proofs/root.go +++ b/client/commands/proofs/root.go @@ -2,8 +2,10 @@ package proofs import "github.com/spf13/cobra" +// nolint const ( - heightFlag = "height" + FlagHeight = "height" + FlagTrustNode = "trust-node" ) // RootCmd represents the base command when called without any subcommands @@ -19,5 +21,6 @@ data to other peers as needed. } func init() { - RootCmd.Flags().Int(heightFlag, 0, "Height to query (skip to use latest block)") + RootCmd.Flags().Int(FlagHeight, 0, "Height to query (skip to use latest block)") + RootCmd.Flags().Bool(FlagTrustNode, false, "DANGEROUS: blindly trust all results from the server") } diff --git a/tests/cli/basictx.sh b/tests/cli/basictx.sh index dadc833c71..767b097fea 100755 --- a/tests/cli/basictx.sh +++ b/tests/cli/basictx.sh @@ -66,9 +66,22 @@ test02SendTxWithFee() { # Make sure tx is indexed checkSendFeeTx $HASH $TX_HEIGHT $SENDER "90" "10" + # make sure this works without trust also + export BCTRUST_NODE=1 + checkSendFeeTx $HASH $TX_HEIGHT $SENDER "90" "10" + unset BCTRUST_NODE + # assert replay protection TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=90mycoin --fee=10mycoin --sequence=2 --to=$RECV --name=$RICH 2>/dev/null) assertFalse "line=${LINENO}, replay: $TX" $? + + # make sure this works without trust also + export BCTRUST_NODE=1 + checkAccount $SENDER "9007199254739900" + checkAccount $RECV "1082" + unset BCTRUST_NODE + + # checking normally checkAccount $SENDER "9007199254739900" checkAccount $RECV "1082"