From a9408aa3b1c478d85118af01770c3d34d33668aa Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 29 Jan 2017 21:29:43 -0800 Subject: [PATCH] ibc demo --- demo/clean.sh | 13 +++ demo/data/chain1/basecoin/genesis.json | 12 +++ demo/data/chain1/basecoin/priv_validator.json | 17 ++++ demo/data/chain1/tendermint/config.toml | 11 +++ demo/data/chain1/tendermint/genesis.json | 15 ++++ .../chain1/tendermint/priv_validator.json | 16 ++++ demo/data/chain2/basecoin/genesis.json | 12 +++ demo/data/chain2/basecoin/priv_validator.json | 16 ++++ demo/data/chain2/tendermint/config.toml | 11 +++ demo/data/chain2/tendermint/genesis.json | 15 ++++ .../chain2/tendermint/priv_validator.json | 16 ++++ demo/start.sh | 86 +++++++++++++++++++ 12 files changed, 240 insertions(+) create mode 100644 demo/clean.sh create mode 100644 demo/data/chain1/basecoin/genesis.json create mode 100644 demo/data/chain1/basecoin/priv_validator.json create mode 100644 demo/data/chain1/tendermint/config.toml create mode 100644 demo/data/chain1/tendermint/genesis.json create mode 100644 demo/data/chain1/tendermint/priv_validator.json create mode 100644 demo/data/chain2/basecoin/genesis.json create mode 100644 demo/data/chain2/basecoin/priv_validator.json create mode 100644 demo/data/chain2/tendermint/config.toml create mode 100644 demo/data/chain2/tendermint/genesis.json create mode 100644 demo/data/chain2/tendermint/priv_validator.json create mode 100644 demo/start.sh diff --git a/demo/clean.sh b/demo/clean.sh new file mode 100644 index 0000000000..e2d519337d --- /dev/null +++ b/demo/clean.sh @@ -0,0 +1,13 @@ +#! /bin/bash + +killall -9 basecoin tendermint +TMROOT=./data/chain1/tendermint tendermint unsafe_reset_all +TMROOT=./data/chain2/tendermint tendermint unsafe_reset_all + +rm -rf ./data/chain1/basecoin/merkleeyes.db +rm -rf ./data/chain2/basecoin/merkleeyes.db + +rm ./*.log + +rm ./data/chain1/tendermint/*.bak +rm ./data/chain2/tendermint/*.bak diff --git a/demo/data/chain1/basecoin/genesis.json b/demo/data/chain1/basecoin/genesis.json new file mode 100644 index 0000000000..717a6345a0 --- /dev/null +++ b/demo/data/chain1/basecoin/genesis.json @@ -0,0 +1,12 @@ +[ + "base/chainID", "test_chain_1", + "base/account", { + "pub_key": [1, "B3588BDC92015ED3CDB6F57A86379E8C79A7111063610B7E625487C76496F4DF"], + "coins": [ + { + "denom": "blank", + "amount": 9007199254740992 + } + ] + } +] diff --git a/demo/data/chain1/basecoin/priv_validator.json b/demo/data/chain1/basecoin/priv_validator.json new file mode 100644 index 0000000000..15d7919240 --- /dev/null +++ b/demo/data/chain1/basecoin/priv_validator.json @@ -0,0 +1,17 @@ +{ + "address": "D397BC62B435F3CF50570FBAB4340FE52C60858F", + "last_height": 0, + "last_round": 0, + "last_signature": null, + "last_signbytes": "", + "last_step": 0, + "priv_key": [ + 1, + "39E75AA1CF7BC710585977EFC375CD1730519186BD231478C339F2819C3C26E7B3588BDC92015ED3CDB6F57A86379E8C79A7111063610B7E625487C76496F4DF" + ], + "pub_key": [ + 1, + "B3588BDC92015ED3CDB6F57A86379E8C79A7111063610B7E625487C76496F4DF" + ] +} + diff --git a/demo/data/chain1/tendermint/config.toml b/demo/data/chain1/tendermint/config.toml new file mode 100644 index 0000000000..9b97202d12 --- /dev/null +++ b/demo/data/chain1/tendermint/config.toml @@ -0,0 +1,11 @@ +# This is a TOML config file. +# For more information, see https://github.com/toml-lang/toml + +proxy_app = "tcp://127.0.0.1:46658" +moniker = "anonymous" +node_laddr = "tcp://0.0.0.0:46656" +seeds = "" +fast_sync = true +db_backend = "leveldb" +log_level = "notice" +rpc_laddr = "tcp://0.0.0.0:46657" diff --git a/demo/data/chain1/tendermint/genesis.json b/demo/data/chain1/tendermint/genesis.json new file mode 100644 index 0000000000..27beb1b826 --- /dev/null +++ b/demo/data/chain1/tendermint/genesis.json @@ -0,0 +1,15 @@ +{ + "app_hash": "", + "chain_id": "test-chain-AtzVUw", + "genesis_time": "0001-01-01T00:00:00.000Z", + "validators": [ + { + "amount": 10, + "name": "", + "pub_key": [ + 1, + "D6EBB92440CF375054AA59BCF0C99D596DEEDFFB2543CAE1BA1908B72CF9676A" + ] + } + ] +} \ No newline at end of file diff --git a/demo/data/chain1/tendermint/priv_validator.json b/demo/data/chain1/tendermint/priv_validator.json new file mode 100644 index 0000000000..1ea10c12da --- /dev/null +++ b/demo/data/chain1/tendermint/priv_validator.json @@ -0,0 +1,16 @@ +{ + "address": "EBB0B4A899973C524A6BB18A161056A55F590F41", + "last_height": 0, + "last_round": 0, + "last_signature": null, + "last_signbytes": "", + "last_step": 0, + "priv_key": [ + 1, + "5FFDC1EA5FA2CA4A0A5503C86D2D348C5B401AD80FAA1899508F1ED00D8982E8D6EBB92440CF375054AA59BCF0C99D596DEEDFFB2543CAE1BA1908B72CF9676A" + ], + "pub_key": [ + 1, + "D6EBB92440CF375054AA59BCF0C99D596DEEDFFB2543CAE1BA1908B72CF9676A" + ] +} \ No newline at end of file diff --git a/demo/data/chain2/basecoin/genesis.json b/demo/data/chain2/basecoin/genesis.json new file mode 100644 index 0000000000..1dcc0d658f --- /dev/null +++ b/demo/data/chain2/basecoin/genesis.json @@ -0,0 +1,12 @@ +[ + "base/chainID", "test_chain_2", + "base/account", { + "pub_key": [1, "0628C8E6C2D50B15764B443394E06C6A64F3082CE966A2A8C1A55A4D63D0FC5D"], + "coins": [ + { + "denom": "blank", + "amount": 9007199254740992 + } + ] + } +] diff --git a/demo/data/chain2/basecoin/priv_validator.json b/demo/data/chain2/basecoin/priv_validator.json new file mode 100644 index 0000000000..8f2eccadeb --- /dev/null +++ b/demo/data/chain2/basecoin/priv_validator.json @@ -0,0 +1,16 @@ +{ + "address": "053BA0F19616AFF975C8756A2CBFF04F408B4D47", + "last_height": 0, + "last_round": 0, + "last_signature": null, + "last_signbytes": "", + "last_step": 0, + "priv_key": [ + 1, + "22920C428043D869987F253D7C9B2305E7010642C40CE88A52C9F6CE5ACC42080628C8E6C2D50B15764B443394E06C6A64F3082CE966A2A8C1A55A4D63D0FC5D" + ], + "pub_key": [ + 1, + "0628C8E6C2D50B15764B443394E06C6A64F3082CE966A2A8C1A55A4D63D0FC5D" + ] +} diff --git a/demo/data/chain2/tendermint/config.toml b/demo/data/chain2/tendermint/config.toml new file mode 100644 index 0000000000..9b97202d12 --- /dev/null +++ b/demo/data/chain2/tendermint/config.toml @@ -0,0 +1,11 @@ +# This is a TOML config file. +# For more information, see https://github.com/toml-lang/toml + +proxy_app = "tcp://127.0.0.1:46658" +moniker = "anonymous" +node_laddr = "tcp://0.0.0.0:46656" +seeds = "" +fast_sync = true +db_backend = "leveldb" +log_level = "notice" +rpc_laddr = "tcp://0.0.0.0:46657" diff --git a/demo/data/chain2/tendermint/genesis.json b/demo/data/chain2/tendermint/genesis.json new file mode 100644 index 0000000000..b61008669a --- /dev/null +++ b/demo/data/chain2/tendermint/genesis.json @@ -0,0 +1,15 @@ +{ + "app_hash": "", + "chain_id": "test-chain-cLhwLM", + "genesis_time": "0001-01-01T00:00:00.000Z", + "validators": [ + { + "amount": 10, + "name": "", + "pub_key": [ + 1, + "9A76DDE4CA4EE660C073D288DBE4F8A128F23857881A95F18167682D47E7058F" + ] + } + ] +} \ No newline at end of file diff --git a/demo/data/chain2/tendermint/priv_validator.json b/demo/data/chain2/tendermint/priv_validator.json new file mode 100644 index 0000000000..8b3eb7e348 --- /dev/null +++ b/demo/data/chain2/tendermint/priv_validator.json @@ -0,0 +1,16 @@ +{ + "address": "D42CFCB9C42DF9A73143EEA89255D1DF027B6240", + "last_height": 0, + "last_round": 0, + "last_signature": null, + "last_signbytes": "", + "last_step": 0, + "priv_key": [ + 1, + "6353FAF4ADEB03EA496A9EAE5BE56C4C6A851CB705401788184FDC9198413C2C9A76DDE4CA4EE660C073D288DBE4F8A128F23857881A95F18167682D47E7058F" + ], + "pub_key": [ + 1, + "9A76DDE4CA4EE660C073D288DBE4F8A128F23857881A95F18167682D47E7058F" + ] +} \ No newline at end of file diff --git a/demo/start.sh b/demo/start.sh new file mode 100644 index 0000000000..f552f36a38 --- /dev/null +++ b/demo/start.sh @@ -0,0 +1,86 @@ +#! /bin/bash +set -eu + +cd $GOPATH/src/github.com/tendermint/basecoin/demo + +function removeQuotes() { + temp="${1%\"}" + temp="${temp#\"}" + echo "$temp" +} + +# grab the chain ids +CHAIN_ID1=$(cat ./data/chain1/basecoin/genesis.json | jq .[1]) +CHAIN_ID1=$(removeQuotes $CHAIN_ID1) +CHAIN_ID2=$(cat ./data/chain2/basecoin/genesis.json | jq .[1]) +CHAIN_ID2=$(removeQuotes $CHAIN_ID2) +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" + +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 & + +# 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 & + +echo "" +echo "... waiting for chains to start" +echo "" +sleep 5 + +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 + +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 + +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) +HEIGHT=$(echo $QUERY_RESULT | jq .height) +PACKET=$(echo $QUERY_RESULT | jq .value) +PROOF=$(echo $QUERY_RESULT | jq .proof) +echo "QUERY_RESULT: $QUERY_RESULT" +echo "HEIGHT: $HEIGHT" +echo "PACKET: $PACKET" +echo "PROOF: $PROOF" + +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) +echo "HEADER_AND_COMMIT: $HEADER_AND_COMMIT" +echo "HEADER: $HEADER" +echo "COMMIT: $COMMIT" + +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 + +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