Merge pull request #188 from tendermint/feature/blind-trust
Add a flag to skip all query proofs
This commit is contained in:
commit
0a7b8a3e96
|
@ -29,9 +29,10 @@ var (
|
||||||
|
|
||||||
//nolint
|
//nolint
|
||||||
const (
|
const (
|
||||||
SeedFlag = "seed"
|
SeedFlag = "seed"
|
||||||
HashFlag = "valhash"
|
HashFlag = "valhash"
|
||||||
GenesisFlag = "genesis"
|
GenesisFlag = "genesis"
|
||||||
|
FlagTrustNode = "trust-node"
|
||||||
|
|
||||||
ConfigFile = "config.toml"
|
ConfigFile = "config.toml"
|
||||||
)
|
)
|
||||||
|
@ -125,6 +126,11 @@ type Runable func(cmd *cobra.Command, args []string) error
|
||||||
// and the root command sets up viper, which is needed to find the home dir.
|
// and the root command sets up viper, which is needed to find the home dir.
|
||||||
func RequireInit(run Runable) Runable {
|
func RequireInit(run Runable) Runable {
|
||||||
return func(cmd *cobra.Command, args []string) error {
|
return func(cmd *cobra.Command, args []string) error {
|
||||||
|
// otherwise, run the wrappped command
|
||||||
|
if viper.GetBool(FlagTrustNode) {
|
||||||
|
return run(cmd, args)
|
||||||
|
}
|
||||||
|
|
||||||
// first check if we were Init'ed and if not, return an error
|
// first check if we were Init'ed and if not, return an error
|
||||||
root := viper.GetString(cli.HomeFlag)
|
root := viper.GetString(cli.HomeFlag)
|
||||||
init, err := WasInited(root)
|
init, err := WasInited(root)
|
||||||
|
|
|
@ -26,6 +26,7 @@ import (
|
||||||
func GetAndParseAppProof(key []byte, data interface{}) (lc.Proof, error) {
|
func GetAndParseAppProof(key []byte, data interface{}) (lc.Proof, error) {
|
||||||
height := GetHeight()
|
height := GetHeight()
|
||||||
node := commands.GetNode()
|
node := commands.GetNode()
|
||||||
|
|
||||||
prover := proofs.NewAppProver(node)
|
prover := proofs.NewAppProver(node)
|
||||||
|
|
||||||
proof, err := GetProof(node, prover, key, height)
|
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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ph := int(proof.BlockHeight())
|
|
||||||
|
// short-circuit with no proofs
|
||||||
|
if viper.GetBool(commands.FlagTrustNode) {
|
||||||
|
return proof, err
|
||||||
|
}
|
||||||
|
|
||||||
// here is the certifier, root of all knowledge
|
// here is the certifier, root of all knowledge
|
||||||
cert, err := commands.GetCertifier()
|
cert, err := commands.GetCertifier()
|
||||||
if err != nil {
|
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
|
// FIXME: cannot use cert.GetByHeight for now, as it also requires
|
||||||
// Validators and will fail on querying tendermint for non-current height.
|
// Validators and will fail on querying tendermint for non-current height.
|
||||||
// When this is supported, we should use it instead...
|
// When this is supported, we should use it instead...
|
||||||
|
ph := int(proof.BlockHeight())
|
||||||
client.WaitForHeight(node, ph, nil)
|
client.WaitForHeight(node, ph, nil)
|
||||||
commit, err := node.Commit(ph)
|
commit, err := node.Commit(ph)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -96,7 +103,7 @@ func ParseHexKey(args []string, argname string) ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetHeight() int {
|
func GetHeight() int {
|
||||||
return viper.GetInt(heightFlag)
|
return viper.GetInt(FlagHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
type proof struct {
|
type proof struct {
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package proofs
|
package proofs
|
||||||
|
|
||||||
import "github.com/spf13/cobra"
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/tendermint/basecoin/client/commands"
|
||||||
|
)
|
||||||
|
|
||||||
|
// nolint
|
||||||
const (
|
const (
|
||||||
heightFlag = "height"
|
FlagHeight = "height"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RootCmd represents the base command when called without any subcommands
|
// RootCmd represents the base command when called without any subcommands
|
||||||
|
@ -19,5 +23,8 @@ data to other peers as needed.
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RootCmd.Flags().Int(heightFlag, 0, "Height to query (skip to use latest block)")
|
RootCmd.PersistentFlags().Int(FlagHeight, 0, "Height to query (skip to use latest block)")
|
||||||
|
RootCmd.PersistentFlags().Bool(commands.FlagTrustNode, false,
|
||||||
|
"DANGEROUS: blindly trust all results from the server")
|
||||||
|
RootCmd.PersistentFlags().MarkHidden(commands.FlagTrustNode)
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,8 @@ test02SendTxWithFee() {
|
||||||
# assert replay protection
|
# assert replay protection
|
||||||
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=90mycoin --fee=10mycoin --sequence=2 --to=$RECV --name=$RICH 2>/dev/null)
|
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" $?
|
assertFalse "line=${LINENO}, replay: $TX" $?
|
||||||
|
|
||||||
|
# checking normally
|
||||||
checkAccount $SENDER "9007199254739900"
|
checkAccount $SENDER "9007199254739900"
|
||||||
checkAccount $RECV "1082"
|
checkAccount $RECV "1082"
|
||||||
|
|
||||||
|
@ -80,6 +82,18 @@ test02SendTxWithFee() {
|
||||||
if assertTrue "line=${LINENO}, no nonce query" $?; then
|
if assertTrue "line=${LINENO}, no nonce query" $?; then
|
||||||
assertEquals "line=${LINENO}, proper nonce" "2" $(echo $NONCE | jq .data)
|
assertEquals "line=${LINENO}, proper nonce" "2" $(echo $NONCE | jq .data)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# make sure this works without trust also
|
||||||
|
OLD_BC_HOME=$BC_HOME
|
||||||
|
export BC_HOME=/foo
|
||||||
|
export BC_TRUST_NODE=1
|
||||||
|
export BC_NODE=localhost:46657
|
||||||
|
checkSendFeeTx $HASH $TX_HEIGHT $SENDER "90" "10"
|
||||||
|
checkAccount $SENDER "9007199254739900"
|
||||||
|
checkAccount $RECV "1082"
|
||||||
|
unset BC_TRUST_NODE
|
||||||
|
unset BC_NODE
|
||||||
|
export BC_HOME=$OLD_BC_HOME
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue