Quick and dirty -- build jormungandr piblic testnet node ###################
# HERE BE FUN DRAGONS -- last updated ~ Sat Oct 5 00:40:07 UTC 2019
###################

# *NOTE*
# these instructions have only been tested on linux machines

# Get pre-reqs (Ubuntu)
sudo apt-get install build-essential pkg-config git curl libssl-dev

# install rust the easy way
curl https://sh.rustup.rs -sSf | sh
source $HOME/.cargo/env
rustup install stable
rustup default stable

# get the source, checkout a working commit hash/tag or master
git clone https://github.com/input-output-hk/jormungandr.git
cd jormungandr
git pull # for good measure
git submodule update --init --recursive
# build the binaries (force will be reqired if you've built before)
cargo install --path jcli --force;cargo install --path jormungandr --force

# create a working dir to play in, and a var
mkdir -p ~/pub_testnet01/storage
cd ~/pub_testnet01
APIURL="http://127.0.0.1:3101/api"

# create your node config
# X.X.X.X == needs to be changed to your public facing IP address
# - run curl ifconfig.me if unsure of your public ip
# - if you are behind a NAT (home router/firewall) you will need to port forward
# /path-to == needs to be changed as ~ is not recognized
cat > ~/pub_testnet01/node_config.yaml << EOL
log:
  format: "plain"
  level: "info"
  output: "stderr"
p2p:
  listen_address: "/ip4/0.0.0.0/tcp/3100"
  public_address: "/ip4/X.X.X.X/tcp/3100"
  topics_of_interest:
    blocks: "high"
    messages: "high"
  trusted_peers:
    - "/ip4/144.76.40.23/tcp/3333"
    - "/ip4/163.172.195.51/tcp/4444"
    - "/ip4/136.244.106.95/tcp/3000"
    - "/ip4/91.121.85.221/tcp/3100"
    - "/ip4/68.183.155.37/tcp/3100"
    - "/ip4/3.123.177.192/tcp/3000"
    - "/ip4/3.123.155.47/tcp/3000"
    - "/ip4/3.115.57.216/tcp/3000"
    - "/ip4/3.112.185.217/tcp/3000"
    - "/ip4/18.139.40.4/tcp/3000"
    - "/ip4/18.140.134.230/tcp/3000"
rest:
  listen: "127.0.0.1:3101"
storage: "/path-to/pub_testnet01/storage"
*hit enter here -- at the > prompt type EOL as below*
> EOL


# start your node in the foreground
jormungandr --config ~/pub_testnet01/node_config.yaml --genesis-block-hash adbdd5ede31637f6c9bad5c271eec0bc3d0cb9efb86a5b913bb55cba549d0770


# start your node in the background
# - required if you want to exit the shell and leave the node running
nohup jormungandr --config ~/pub_testnet01/node_config.yaml --genesis-block-hash adbdd5ede31637f6c9bad5c271eec0bc3d0cb9efb86a5b913bb55cba549d0770 >> /path-to/pub_testnet01/node.out 2>&1 &
# to watch the output of the node run tail -f node.out


# you should see the files in the ~/pub_testnet01/storage start increasing in size
# - current size of sqlite file is around 30mb
ls -la ~/pub_testnet01/storage
total 29568
drwxrwxr-x 2 myuser myuser 4096 Sep 29 00:23 .
drwxrwxr-x 5 myuser myuser 4096 Sep 29 20:09 ..
-rw-r--r-- 1 myuser myuser 26066944 Sep 29 20:05 blocks.sqlite
-rw-r--r-- 1 myuser myuser 32768 Sep 29 20:09 blocks.sqlite-shm
-rw-r--r-- 1 myuser myuser 4165352 Sep 29 20:09 blocks.sqlite-wal


# to check to see if you're receiving new blocks:
# - if lastBlockTime value is blank you might be running into THIS ISSUE
# - some say if you wait long enough it will start to sync
# - others think getting someone to add your node to their node_config.yaml trusted_peers list fixes it
jcli rest v0 node stats get -h ${APIURL}
---
blockRecvCnt: 1009
lastBlockDate: "219.22133"
lastBlockFees: 0
lastBlockHash: cd6eb35ead45a42c7befea3aa5f2a89b0dc71ff2bc3306a962b8aeb24748a305
lastBlockHeight: "24562"
lastBlockSum: 0
lastBlockTime: "2019-09-29T20:11:21+00:00"
lastBlockTx: 0
txRecvCnt: 16
uptime: 9293

# once you see the blockRecvCnt incrementing your node is online -- Enjoy!

# NEXT STEP: Create an account and request funds from the faucet

# The Lovelace Community Pool is a no fee staking pool run by @kyleo
# Join us on Telegram

# If this was useful and you can/want to support us, our donation address is:
Ae2tdPwUPEYw3rz8KGHbnTusd9QWQ8ePhogEWkm1agugTtW51skA59DrKe8