From e578d1f07babbe7460bd15824413375fe8502e80 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 29 Jan 2017 22:43:07 -0800 Subject: [PATCH] fixes to make demo work --- cmd/basecoin/ibc.go | 6 ++---- cmd/basecoin/query.go | 8 ++++---- demo/data/chain1/tendermint/genesis.json | 4 ++-- demo/data/chain2/tendermint/genesis.json | 4 ++-- demo/start.sh | 26 ++++++++++++++++++++---- plugins/ibc/ibc.go | 2 +- 6 files changed, 33 insertions(+), 17 deletions(-) diff --git a/cmd/basecoin/ibc.go b/cmd/basecoin/ibc.go index a0bab1299..83d27d0bf 100644 --- a/cmd/basecoin/ibc.go +++ b/cmd/basecoin/ibc.go @@ -44,8 +44,6 @@ func cmdIBCRegisterTx(c *cli.Context) error { } func cmdIBCUpdateTx(c *cli.Context) error { - parent := c.Parent() - headerBytes, err := hex.DecodeString(stripHex(c.String("header"))) if err != nil { return errors.New(cmn.Fmt("Header (%v) is invalid hex: %v", c.String("header"), err)) @@ -77,7 +75,7 @@ func cmdIBCUpdateTx(c *cli.Context) error { }{ibcTx})) name := "IBC" - return appTx(parent, name, data) + return appTx(c.Parent(), name, data) } func cmdIBCPacketCreateTx(c *cli.Context) error { @@ -126,7 +124,7 @@ func cmdIBCPacketPostTx(c *cli.Context) error { } var packet ibc.Packet - var proof merkle.IAVLProof + proof := new(merkle.IAVLProof) if err := wire.ReadBinaryBytes(packetBytes, &packet); err != nil { return errors.New(cmn.Fmt("Error unmarshalling packet: %v", err)) diff --git a/cmd/basecoin/query.go b/cmd/basecoin/query.go index 2aba1b8f5..01b293d11 100644 --- a/cmd/basecoin/query.go +++ b/cmd/basecoin/query.go @@ -81,10 +81,10 @@ func cmdBlock(c *cli.Context) error { return errors.New(cmn.Fmt("Height must be an int, got %v: %v", heightString, err)) } - block, err := getBlock(c, height) + /*block, err := getBlock(c, height) if err != nil { return err - } + }*/ nextBlock, err := getBlock(c, height+1) if err != nil { return err @@ -95,11 +95,11 @@ func cmdBlock(c *cli.Context) error { JSON BlockJSON `json:"json"` }{ BlockHex{ - Header: wire.BinaryBytes(block.Header), + Header: wire.BinaryBytes(nextBlock.Header), Commit: wire.BinaryBytes(nextBlock.LastCommit), }, BlockJSON{ - Header: block.Header, + Header: nextBlock.Header, Commit: nextBlock.LastCommit, }, }))) diff --git a/demo/data/chain1/tendermint/genesis.json b/demo/data/chain1/tendermint/genesis.json index 27beb1b82..91830dd23 100644 --- a/demo/data/chain1/tendermint/genesis.json +++ b/demo/data/chain1/tendermint/genesis.json @@ -1,6 +1,6 @@ { "app_hash": "", - "chain_id": "test-chain-AtzVUw", + "chain_id": "test_chain_1", "genesis_time": "0001-01-01T00:00:00.000Z", "validators": [ { @@ -12,4 +12,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/demo/data/chain2/tendermint/genesis.json b/demo/data/chain2/tendermint/genesis.json index b61008669..6c9f17c95 100644 --- a/demo/data/chain2/tendermint/genesis.json +++ b/demo/data/chain2/tendermint/genesis.json @@ -1,6 +1,6 @@ { "app_hash": "", - "chain_id": "test-chain-cLhwLM", + "chain_id": "test_chain_2", "genesis_time": "0001-01-01T00:00:00.000Z", "validators": [ { @@ -12,4 +12,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/demo/start.sh b/demo/start.sh index f552f36a3..da617910f 100644 --- a/demo/start.sh +++ b/demo/start.sh @@ -35,7 +35,7 @@ basecoin start --address tcp://localhost:36658 --ibc-plugin --dir ./data/chain2/ echo "" echo "... waiting for chains to start" echo "" -sleep 5 +sleep 10 echo "... registering chain1 on chain2" echo "" @@ -57,18 +57,30 @@ QUERY_RESULT=$(basecoin query ibc,egress,$CHAIN_ID1,$CHAIN_ID2,1) HEIGHT=$(echo $QUERY_RESULT | jq .height) PACKET=$(echo $QUERY_RESULT | jq .value) PROOF=$(echo $QUERY_RESULT | jq .proof) +PACKET=$(removeQuotes $PACKET) +PROOF=$(removeQuotes $PROOF) +echo "" echo "QUERY_RESULT: $QUERY_RESULT" echo "HEIGHT: $HEIGHT" echo "PACKET: $PACKET" echo "PROOF: $PROOF" + +echo "" +echo "... waiting for some blocks to be mined" +echo "" +sleep 5 + echo "" echo "... querying for block data" echo "" # get the header and commit for the height HEADER_AND_COMMIT=$(basecoin block $HEIGHT) -HEADER=$(echo $HEADER_AND_COMMIT | jq.hex.header) -COMMIT=$(echo $HEADER_AND_COMMIT | jq.hex.commit) +HEADER=$(echo $HEADER_AND_COMMIT | jq .hex.header) +HEADER=$(removeQuotes $HEADER) +COMMIT=$(echo $HEADER_AND_COMMIT | jq .hex.commit) +COMMIT=$(removeQuotes $COMMIT) +echo "" echo "HEADER_AND_COMMIT: $HEADER_AND_COMMIT" echo "HEADER: $HEADER" echo "COMMIT: $COMMIT" @@ -83,4 +95,10 @@ echo "" echo "... posting packet from chain1 on chain2" echo "" # post the packet from chain1 to chain2 -basecoin ibc --amount 10 $CHAIN_FLAGS2 packet post --from $CHAIN_ID1 --height $HEIGHT --packet $PACKET --proof $PROOF +basecoin ibc --amount 10 $CHAIN_FLAGS2 packet post --from $CHAIN_ID1 --height $((HEIGHT + 1)) --packet 0x$PACKET --proof 0x$PROOF + +echo "" +echo "... checking if the packet is present on chain2" +echo "" +# query for the packet on chain2 ! +basecoin query --node tcp://localhost:36657 ibc,ingress,test_chain_2,test_chain_1,1 diff --git a/plugins/ibc/ibc.go b/plugins/ibc/ibc.go index c33753874..8d6e0c389 100644 --- a/plugins/ibc/ibc.go +++ b/plugins/ibc/ibc.go @@ -337,7 +337,7 @@ func (sm *IBCStateMachine) runPacketPostTx(tx IBCPacketPostTx) { } if !exists { sm.res.Code = IBCCodeUnknownHeight - sm.res.Log = cmn.Fmt("Loading Header: %v", err.Error()) + sm.res.Log = cmn.Fmt("Loading Header: Unknown height") return }