Compiles and all tests pass - even IBC with new proofs

This commit is contained in:
Ethan Frey 2017-08-04 20:02:23 +02:00
parent 831c9ae3ec
commit 0de3ecc741
6 changed files with 28 additions and 15 deletions

View File

@ -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)
}

View File

@ -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{

View File

@ -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 {

View File

@ -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

View File

@ -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?")
}

View File

@ -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