diff --git a/cmd/commands/ibc.go b/cmd/commands/ibc.go index 242743319..f8d0e0b61 100644 --- a/cmd/commands/ibc.go +++ b/cmd/commands/ibc.go @@ -142,9 +142,6 @@ var ( IbcPacketTxCmd = cli.Command{ Name: "packet", Usage: "Send a new packet via IBC", - Flags: []cli.Flag{ - // - }, Subcommands: []cli.Command{ IbcPacketCreateTx, IbcPacketPostTx, diff --git a/demo/clean.sh b/demo/clean.sh index e2d519337..7d1892321 100644 --- a/demo/clean.sh +++ b/demo/clean.sh @@ -1,6 +1,6 @@ #! /bin/bash -killall -9 basecoin tendermint +killall -9 adam tendermint TMROOT=./data/chain1/tendermint tendermint unsafe_reset_all TMROOT=./data/chain2/tendermint tendermint unsafe_reset_all diff --git a/demo/data/chain1/basecoin/priv_validator.json b/demo/data/chain1/basecoin/key.json similarity index 74% rename from demo/data/chain1/basecoin/priv_validator.json rename to demo/data/chain1/basecoin/key.json index 15d791924..e610ba89d 100644 --- a/demo/data/chain1/basecoin/priv_validator.json +++ b/demo/data/chain1/basecoin/key.json @@ -1,10 +1,5 @@ { "address": "D397BC62B435F3CF50570FBAB4340FE52C60858F", - "last_height": 0, - "last_round": 0, - "last_signature": null, - "last_signbytes": "", - "last_step": 0, "priv_key": [ 1, "39E75AA1CF7BC710585977EFC375CD1730519186BD231478C339F2819C3C26E7B3588BDC92015ED3CDB6F57A86379E8C79A7111063610B7E625487C76496F4DF" diff --git a/demo/data/chain2/basecoin/priv_validator.json b/demo/data/chain2/basecoin/key.json similarity index 74% rename from demo/data/chain2/basecoin/priv_validator.json rename to demo/data/chain2/basecoin/key.json index 8f2eccade..90761696d 100644 --- a/demo/data/chain2/basecoin/priv_validator.json +++ b/demo/data/chain2/basecoin/key.json @@ -1,10 +1,5 @@ { "address": "053BA0F19616AFF975C8756A2CBFF04F408B4D47", - "last_height": 0, - "last_round": 0, - "last_signature": null, - "last_signbytes": "", - "last_step": 0, "priv_key": [ 1, "22920C428043D869987F253D7C9B2305E7010642C40CE88A52C9F6CE5ACC42080628C8E6C2D50B15764B443394E06C6A64F3082CE966A2A8C1A55A4D63D0FC5D" diff --git a/demo/start.sh b/demo/start.sh index da617910f..b856852de 100644 --- a/demo/start.sh +++ b/demo/start.sh @@ -18,19 +18,19 @@ echo "CHAIN_ID1: $CHAIN_ID1" echo "CHAIN_ID2: $CHAIN_ID2" # make reusable chain flags -CHAIN_FLAGS1="--chain_id $CHAIN_ID1 --from ./data/chain1/basecoin/priv_validator.json" -CHAIN_FLAGS2="--chain_id $CHAIN_ID2 --from ./data/chain2/basecoin/priv_validator.json --node tcp://localhost:36657" +CHAIN_FLAGS1="--chain_id $CHAIN_ID1 --from ./data/chain1/basecoin/key.json" +CHAIN_FLAGS2="--chain_id $CHAIN_ID2 --from ./data/chain2/basecoin/key.json --node tcp://localhost:36657" echo "" echo "... starting chains" echo "" # start the first node TMROOT=./data/chain1/tendermint tendermint node &> chain1_tendermint.log & -basecoin start --ibc-plugin --dir ./data/chain1/basecoin &> chain1_basecoin.log & +adam start --dir ./data/chain1/basecoin &> chain1_basecoin.log & # start the second node TMROOT=./data/chain2/tendermint tendermint node --node_laddr tcp://localhost:36656 --rpc_laddr tcp://localhost:36657 --proxy_app tcp://localhost:36658 &> chain2_tendermint.log & -basecoin start --address tcp://localhost:36658 --ibc-plugin --dir ./data/chain2/basecoin &> chain2_basecoin.log & +adam start --address tcp://localhost:36658 --dir ./data/chain2/basecoin &> chain2_basecoin.log & echo "" echo "... waiting for chains to start" @@ -40,20 +40,20 @@ sleep 10 echo "... registering chain1 on chain2" echo "" # register chain1 on chain2 -basecoin ibc --amount 10 $CHAIN_FLAGS2 register --chain_id $CHAIN_ID1 --genesis ./data/chain1/tendermint/genesis.json +adam tx ibc --amount 10 $CHAIN_FLAGS2 register --chain_id $CHAIN_ID1 --genesis ./data/chain1/tendermint/genesis.json echo "" echo "... creating egress packet on chain1" echo "" # create a packet on chain1 destined for chain2 PAYLOAD="DEADBEEF" #TODO -basecoin ibc --amount 10 $CHAIN_FLAGS1 packet create --from $CHAIN_ID1 --to $CHAIN_ID2 --type coin --payload $PAYLOAD --sequence 1 +adam tx ibc --amount 10 $CHAIN_FLAGS1 packet create --from $CHAIN_ID1 --to $CHAIN_ID2 --type coin --payload $PAYLOAD --sequence 1 echo "" echo "... querying for packet data" echo "" # query for the packet data and proof -QUERY_RESULT=$(basecoin query ibc,egress,$CHAIN_ID1,$CHAIN_ID2,1) +QUERY_RESULT=$(adam 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) @@ -75,7 +75,7 @@ echo "" echo "... querying for block data" echo "" # get the header and commit for the height -HEADER_AND_COMMIT=$(basecoin block $HEIGHT) +HEADER_AND_COMMIT=$(adam block $HEIGHT) HEADER=$(echo $HEADER_AND_COMMIT | jq .hex.header) HEADER=$(removeQuotes $HEADER) COMMIT=$(echo $HEADER_AND_COMMIT | jq .hex.commit) @@ -89,16 +89,19 @@ echo "" echo "... updating state of chain1 on chain2" echo "" # update the state of chain1 on chain2 -basecoin ibc --amount 10 $CHAIN_FLAGS2 update --header 0x$HEADER --commit 0x$COMMIT +adam tx ibc --amount 10 $CHAIN_FLAGS2 update --header 0x$HEADER --commit 0x$COMMIT 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 + 1)) --packet 0x$PACKET --proof 0x$PROOF +adam tx 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 +adam query --node tcp://localhost:36657 ibc,ingress,test_chain_2,test_chain_1,1 + +echo "" +echo "DONE!" diff --git a/docs/guide/ibc.md b/docs/guide/ibc.md index 96022310f..fe98941c1 100644 --- a/docs/guide/ibc.md +++ b/docs/guide/ibc.md @@ -9,6 +9,8 @@ and here we'll show you how to use the Basecoin IBC-plugin to send a packet of d Please note, this tutorial assumes you are familiar with [Basecoin plugins](/docs/guide/plugin-design.md) and with the [Basecoin CLI](/docs/guide/basecoin-basics), but we'll explain how IBC works. +You may also want to see the tutorials on [a simple example plugin](example-plugin.md) +and the list of [more advanced plugins](more-examples.md). The IBC plugin defines a new set of transactions as subtypes of the `AppTx`. The plugin's functionality is accessed by setting the `AppTx.Name` field to `"IBC"`, and setting the `Data` field to the serialized IBC transaction type. @@ -179,7 +181,10 @@ Now that we have all the background knowledge, let's actually walk through the t Make sure you have installed [tendermint](https://tendermint.com/intro/getting-started/download) and -[basecoin](/docs/guide/install.md). +[adam](/docs/guide/install.md). + +`adam` is the name for the program that will become the Cosmos Hub. +We call it Adam because it's the first blockchain in [the Cosmos Network](https://cosmos.network). Now let's start the two blockchains. In this tutorial, each chain will have only a single validator, @@ -196,14 +201,14 @@ We can start the two chains as follows: ``` TMROOT=./data/chain1/tendermint tendermint node &> chain1_tendermint.log & -basecoin start --ibc-plugin --dir ./data/chain1/basecoin &> chain1_basecoin.log & +adam start --dir ./data/chain1/basecoin &> chain1_adam.log & ``` and ``` TMROOT=./data/chain2/tendermint tendermint node --node_laddr tcp://localhost:36656 --rpc_laddr tcp://localhost:36657 --proxy_app tcp://localhost:36658 &> chain2_tendermint.log & -basecoin start --address tcp://localhost:36658 --ibc-plugin --dir ./data/chain2/basecoin &> chain2_basecoin.log & +adam start --address tcp://localhost:36658 --dir ./data/chain2/basecoin &> chain2_basecoin.log & ``` Note how we refer to the relevant data directories. Also note how we have to set the various addresses for the second node so as not to conflict with the first. @@ -225,27 +230,27 @@ For the sake of convenience, let's first set some environment variables: export CHAIN_ID1=test_chain_1 export CHAIN_ID2=test_chain_2 -export CHAIN_FLAGS1="--chain_id $CHAIN_ID1 --from ./data/chain1/basecoin/priv_validator.json" -export CHAIN_FLAGS2="--chain_id $CHAIN_ID2 --from ./data/chain2/basecoin/priv_validator.json --node tcp://localhost:36657" +export CHAIN_FLAGS1="--chain_id $CHAIN_ID1 --from ./data/chain1/basecoin/key.json" +export CHAIN_FLAGS2="--chain_id $CHAIN_ID2 --from ./data/chain2/basecoin/key.json --node tcp://localhost:36657" ``` Let's start by registering `test_chain_1` on `test_chain_2`: ``` -basecoin ibc --amount 10 $CHAIN_FLAGS2 register --chain_id $CHAIN_ID1 --genesis ./data/chain1/tendermint/genesis.json +adam tx ibc --amount 10 $CHAIN_FLAGS2 register --chain_id $CHAIN_ID1 --genesis ./data/chain1/tendermint/genesis.json ``` Now we can create the outgoing packet on `test_chain_1`: ``` -basecoin ibc --amount 10 $CHAIN_FLAGS1 packet create --from $CHAIN_ID1 --to $CHAIN_ID2 --type coin --payload 0xDEADBEEF --sequence 1 +adam tx ibc --amount 10 $CHAIN_FLAGS1 packet create --from $CHAIN_ID1 --to $CHAIN_ID2 --type coin --payload 0xDEADBEEF --sequence 1 ``` Note our payload is just `DEADBEEF`. Now that the packet is committed in the chain, let's get some proof by querying: ``` -basecoin query ibc,egress,$CHAIN_ID1,$CHAIN_ID2,1 +adam query ibc,egress,$CHAIN_ID1,$CHAIN_ID2,1 ``` The result contains the latest height, a value (ie. the hex-encoded binary serialization of our packet), @@ -256,7 +261,7 @@ We'll need a recent block header and a set of commit signatures. Fortunately, we can get them with the `block` command: ``` -basecoin block +adam block ``` where `` is the height returned in the previous query. @@ -266,7 +271,7 @@ The former is used as input for later commands; the latter is human-readable, so Let's send this updated information about `test_chain_1` to `test_chain_2`: ``` -basecoin ibc --amount 10 $CHAIN_FLAGS2 update --header 0x
--commit 0x +adam tx ibc --amount 10 $CHAIN_FLAGS2 update --header 0x
--commit 0x ``` where `
` and `` are the hex-encoded header and commit returned by the previous `block` command. @@ -276,7 +281,7 @@ along with proof the packet was committed on `test_chain_1`. Since `test_chain_2 of `test_chain_1`, it will be able to verify the proof! ``` -basecoin ibc --amount 10 $CHAIN_FLAGS2 packet post --from $CHAIN_ID1 --height --packet 0x --proof 0x +adam tx ibc --amount 10 $CHAIN_FLAGS2 packet post --from $CHAIN_ID1 --height --packet 0x --proof 0x ``` Here, `` is one greater than the height retuned by the previous `query` command, and `` and `` are the @@ -286,3 +291,11 @@ Tada! ## Conclusion + +In this tutorial we explained how IBC works, and demonstrated how to use it to communicate between two chains. +We did the simplest communciation possible: a one way transfer of data from chain1 to chain2. +The most important part was that we updated chain2 with the latest state (ie. header and commit) of chain1, +and then were able to post a proof to chain2 that a packet was committed to the outgoing state of chain1. + +In a future tutorial, we will demonstrate how to use IBC to actually transfer tokens between two blockchains, +but we'll do it with real testnets deployed across multiple nodes on the network. Stay tuned!