docs: update ibc
This commit is contained in:
parent
53f34f45ff
commit
b3834bc5d0
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
{
|
||||
"address": "D397BC62B435F3CF50570FBAB4340FE52C60858F",
|
||||
"last_height": 0,
|
||||
"last_round": 0,
|
||||
"last_signature": null,
|
||||
"last_signbytes": "",
|
||||
"last_step": 0,
|
||||
"priv_key": [
|
||||
1,
|
||||
"39E75AA1CF7BC710585977EFC375CD1730519186BD231478C339F2819C3C26E7B3588BDC92015ED3CDB6F57A86379E8C79A7111063610B7E625487C76496F4DF"
|
|
@ -1,10 +1,5 @@
|
|||
{
|
||||
"address": "053BA0F19616AFF975C8756A2CBFF04F408B4D47",
|
||||
"last_height": 0,
|
||||
"last_round": 0,
|
||||
"last_signature": null,
|
||||
"last_signbytes": "",
|
||||
"last_step": 0,
|
||||
"priv_key": [
|
||||
1,
|
||||
"22920C428043D869987F253D7C9B2305E7010642C40CE88A52C9F6CE5ACC42080628C8E6C2D50B15764B443394E06C6A64F3082CE966A2A8C1A55A4D63D0FC5D"
|
|
@ -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!"
|
||||
|
|
|
@ -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 <height>
|
||||
adam block <height>
|
||||
```
|
||||
|
||||
where `<height>` 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<header>--commit 0x<commit>
|
||||
adam tx ibc --amount 10 $CHAIN_FLAGS2 update --header 0x<header>--commit 0x<commit>
|
||||
```
|
||||
|
||||
where `<header>` and `<commit>` 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 <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>
|
||||
```
|
||||
|
||||
Here, `<height + 1>` is one greater than the height retuned by the previous `query` command, and `<packet>` and `<proof>` 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!
|
||||
|
|
Loading…
Reference in New Issue