From 0de3ecc741bf1064a9a7a18db7ee42cb7598b05c Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 4 Aug 2017 20:02:23 +0200 Subject: [PATCH] Compiles and all tests pass - even IBC with new proofs --- docs/guide/counter/cmd/countercli/commands/query.go | 11 +++++++---- modules/ibc/commands/query.go | 8 ++++++-- modules/ibc/errors.go | 5 ++++- modules/ibc/middleware.go | 6 +++--- modules/ibc/test_helpers.go | 5 ++++- modules/ibc/tx.go | 8 ++++---- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/docs/guide/counter/cmd/countercli/commands/query.go b/docs/guide/counter/cmd/countercli/commands/query.go index 8debaf9c2b..e9fea6ccfd 100644 --- a/docs/guide/counter/cmd/countercli/commands/query.go +++ b/docs/guide/counter/cmd/countercli/commands/query.go @@ -2,7 +2,9 @@ package commands import ( "github.com/spf13/cobra" + "github.com/spf13/viper" + "github.com/tendermint/basecoin/client/commands" proofcmd "github.com/tendermint/basecoin/client/commands/proofs" "github.com/tendermint/basecoin/docs/guide/counter/plugins/counter" @@ -17,13 +19,14 @@ var CounterQueryCmd = &cobra.Command{ } func counterQueryCmd(cmd *cobra.Command, args []string) error { - key := stack.PrefixedKey(counter.NameCounter, counter.StateKey()) - var cp counter.State - proof, err := proofcmd.GetAndParseAppProof(key, &cp) + + prove := !viper.GetBool(commands.FlagTrustNode) + key := stack.PrefixedKey(counter.NameCounter, counter.StateKey()) + h, err := proofcmd.GetParsed(key, &cp, prove) if err != nil { return err } - return proofcmd.OutputProof(cp, proof.BlockHeight()) + return proofcmd.OutputProof(cp, h) } diff --git a/modules/ibc/commands/query.go b/modules/ibc/commands/query.go index 461b5aa0b1..682a4e1219 100644 --- a/modules/ibc/commands/query.go +++ b/modules/ibc/commands/query.go @@ -11,6 +11,7 @@ import ( proofcmd "github.com/tendermint/basecoin/client/commands/proofs" "github.com/tendermint/basecoin/modules/ibc" "github.com/tendermint/basecoin/stack" + wire "github.com/tendermint/go-wire" "github.com/tendermint/go-wire/data" ) @@ -186,8 +187,8 @@ func packetQueryCmd(cmd *cobra.Command, args []string) error { } // Input queue just display the results + var packet ibc.Packet if from != "" { - var packet ibc.Packet h, err := proofcmd.GetParsed(key, &packet, prove) if err != nil { return err @@ -196,11 +197,14 @@ func packetQueryCmd(cmd *cobra.Command, args []string) error { } // output queue, create a post packet - var packet ibc.Packet bs, height, proof, err := proofcmd.GetWithProof(key) if err != nil { return err } + err = wire.ReadBinaryBytes(bs, &packet) + if err != nil { + return err + } // create the post packet here. post := ibc.PostPacketTx{ diff --git a/modules/ibc/errors.go b/modules/ibc/errors.go index 8fafe7a73b..228c85e889 100644 --- a/modules/ibc/errors.go +++ b/modules/ibc/errors.go @@ -91,8 +91,11 @@ func IsPacketOutOfOrderErr(err error) bool { func ErrInvalidProof() error { return errors.WithCode(errInvalidProof, IBCCodeInvalidProof) } +func ErrInvalidProofWithReason(err error) error { + return errors.WithCode(err, IBCCodeInvalidProof) +} func IsInvalidProofErr(err error) bool { - return errors.IsSameError(errInvalidProof, err) + return errors.HasErrorCode(err, IBCCodeInvalidProof) } func ErrInvalidCommit(err error) error { diff --git a/modules/ibc/middleware.go b/modules/ibc/middleware.go index c81bcec48a..eafff78ac1 100644 --- a/modules/ibc/middleware.go +++ b/modules/ibc/middleware.go @@ -102,9 +102,9 @@ func (m Middleware) verifyPost(ctx basecoin.Context, store state.SimpleDB, // verify the merkle hash.... root := seed.Header.AppHash pBytes := packet.Bytes() - valid := tx.Proof.Verify(tx.Key, pBytes, root) - if !valid { - return ictx, itx, ErrInvalidProof() + err = tx.Proof.Verify(tx.Key, pBytes, root) + if err != nil { + return ictx, itx, ErrInvalidProofWithReason(err) } // add to input queue diff --git a/modules/ibc/test_helpers.go b/modules/ibc/test_helpers.go index d2272a0e08..5eba0f00a3 100644 --- a/modules/ibc/test_helpers.go +++ b/modules/ibc/test_helpers.go @@ -59,7 +59,10 @@ func genEmptySeed(keys certifiers.ValKeys, chain string, h int, func makePostPacket(tree *iavl.IAVLTree, packet Packet, fromID string, fromHeight int) PostPacketTx { key := []byte(fmt.Sprintf("some-long-prefix-%06d", packet.Sequence)) tree.Set(key, packet.Bytes()) - _, proof := tree.ConstructProof(key) + _, proof, _, err := tree.GetWithProof(key) + if err != nil { + panic(err) + } if proof == nil { panic("wtf?") } diff --git a/modules/ibc/tx.go b/modules/ibc/tx.go index 8ee4d934c4..a7decdc24e 100644 --- a/modules/ibc/tx.go +++ b/modules/ibc/tx.go @@ -3,7 +3,7 @@ package ibc import ( "github.com/tendermint/go-wire/data" "github.com/tendermint/light-client/certifiers" - merkle "github.com/tendermint/merkleeyes/iavl" + "github.com/tendermint/merkleeyes/iavl" "github.com/tendermint/basecoin" ) @@ -115,9 +115,9 @@ type PostPacketTx struct { // The block height in which Packet was committed, to check Proof FromChainHeight uint64 `json:"src_height"` // this proof must match the header and the packet.Bytes() - Proof *merkle.IAVLProof `json:"proof"` - Key data.Bytes `json:"key"` - Packet Packet `json:"packet"` + Proof *iavl.KeyExistsProof `json:"proof"` + Key data.Bytes `json:"key"` + Packet Packet `json:"packet"` } // ValidateBasic makes sure this is consistent - used to satisfy TxInner