Skip to content

Instantly share code, notes, and snippets.

@unnawut
Last active August 21, 2020 11:00
Show Gist options
  • Save unnawut/7d51432abfbbf552790d6e2080c3764b to your computer and use it in GitHub Desktop.
Save unnawut/7d51432abfbbf552790d6e2080c3764b to your computer and use it in GitHub Desktop.

These instructions have been tested on a fresh digital ocean instance:

Specs: Standard / 1 GB / 1 vCPU / 1 GB Memory / 25 GB Disk / SGP1 - Ubuntu 18.04.3 (LTS) x64

$ uname -a
Linux test-watcher-ubuntu-s-1vcpu-1gb-sgp1-01 4.15.0-66-generic #75-Ubuntu SMP Tue Oct 1 05:24:09 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Install erlang and elixir

apt-get update
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.7.4
echo -e '\n. $HOME/.asdf/asdf.sh' >> ~/.bash_profile
echo -e '\n. $HOME/.asdf/completions/asdf.bash' >> ~/.bash_profile
source ~/.bash_profile
asdf plugin-add elixir https://github.com/asdf-vm/asdf-elixir.git
asdf plugin-add erlang https://github.com/asdf-vm/asdf-erlang.git

asdf install erlang 22.3
asdf install elixir 1.10.2
asdf global erlang 22.3
asdf global elixir 1.10.2

mix do local.hex --force, local.rebar --force

Install postgres

apt-get install postgresql postgresql-contrib

sudo -u postgres psql <<EOF
  CREATE USER omisego_dev WITH CREATEDB ENCRYPTED PASSWORD 'omisego_dev';
  CREATE DATABASE omisego_dev OWNER 'omisego_dev';
EOF

Compile the watcher

git clone git@github.com:omgnetwork/elixir-omg.git
cd elixir-omg
sh bin/setup # This step will take a long time, i.e. 30 mins on $5 digital ocean instance

make install-hex-rebar
make build-watcher_info-prod

Configure the watcher

Save the content below to a file called env:

export ETHEREUM_NETWORK=MAINNET
export ETH_NODE=geth
export ETHEREUM_RPC_URL=https://mainnet.infura.io/v3/485372a7dd5f4be4a92f0ce2d227f376
export CHILD_CHAIN_URL=https://childchain.mainnet.v1.omg.network
export AUTHORITY_ADDRESS=0x22405c1782913fb676bc74ef54a60727b0e1026f
export TXHASH_CONTRACT=0x1c29b67acc33eba0d26f52a1e4d26625f52b53e6fbb0a4db915aeb052f7ec849
export CONTRACT_ADDRESS_PLASMA_FRAMEWORK=0x0d4c1222f5e839a911e2053860e45f18921d72ac
export DATABASE_URL=postgres://omisego_dev:omisego_dev@localhost:5432/omisego_dev
export ETHEREUM_EVENTS_CHECK_INTERVAL_MS=8000
export ETHEREUM_STALLED_SYNC_THRESHOLD_MS=300000
export ETHEREUM_BLOCK_TIME_SECONDS=15
export EXIT_PROCESSOR_SLA_MARGIN=5520
export EXIT_PROCESSOR_SLA_MARGIN_FORCED=TRUE
export NODE_HOST=127.0.0.1
export HOSTNAME=localhost
export PORT=7534
export DB_PATH=./data
export APP_ENV=local-development
export DD_DISABLED=true
export LOGGER_BACKEND=console

Then run source ./env for the environment variables to take effect. Note that these values live within your current shell's context. So you need to run source ./env again on system restart, exiting the shell, etc. To permanently set these values, see: https://unix.stackexchange.com/questions/117467/how-to-permanently-set-environmental-variables

Review all the configurations at https://github.com/omgnetwork/elixir-omg/blob/master/docs/deployment_configuration.md

Install the watcher

_build/prod/rel/watcher_info/bin/watcher_info eval "OMG.DB.ReleaseTasks.InitKeyValueDB.run()"

You should see the message: The database at "/app/.omg/data/watcher_info" has been created

_build/prod/rel/watcher_info/bin/watcher_info eval "OMG.WatcherInfo.ReleaseTasks.InitPostgresqlDB.migrate()"

You should see a stream of logs with tables and columns inserted.

_build/prod/rel/watcher_info/bin/watcher_info eval "OMG.WatcherInfo.ReleaseTasks.EthereumTasks.run()"

You should see the message: Running Ethereum tasks

Run the watcher

# Starts the watcher_info
_build/prod/rel/watcher_info/bin/watcher_info start

# Or to start in the background, run the command below instead
_build/prod/rel/watcher_info/bin/watcher_info daemon

You should see a stream block downloads: Child chain seen at block #1227000. Downloading blocks [1000]

You're set!

Verifying your watcher setup

curl -s -X POST https://localhost:7534/status.get \
-H "Content-Type: application/json" \
-d '{}' \
-w "\n" | jq

You should see the watcher status like below:

{
  "data": {
    "byzantine_events": [],
    "contract_addr": {
      "erc20_vault": "0x868358f8451afe3ab26a2cb5dc76079f1a74b4e9",
      "eth_vault": "0x45a1253d05349cc0eb36501aad39345c8d7bbef0",
      "payment_exit_game": "0xba78c439ed3c4ad871e5fad7699ec96797875f3a",
      "plasma_framework": "0x9d9ad8a9baa52a10a6958dfe31ac504f6d62427d"
    },
    "eth_syncing": false,
    "in_flight_exits": [],
    "last_mined_child_block_number": 338000,
    "last_mined_child_block_timestamp": 1594173347,
    "last_seen_eth_block_number": 6837572,
    "last_seen_eth_block_timestamp": 1594719109,
    "last_validated_child_block_number": 338000,
    "last_validated_child_block_timestamp": 1594173347,
    "services_synced_heights": [
      {
        "height": 6837571,
        "service": "block_getter"
      },
      ...
    ]
  },
  "service_name": "watcher_info",
  "success": true,
  "version": "1.0.3+46b5684"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment