How to run Incognito Chain Full Node on Mainnet

Hello everyone,

This tutorial is for anyone in the community who would like to build pApps.

The full node contains data of all Incognito Shards and Beacons which help validate and relay new transactions to corresponding shards, as well as fetching account balance, etc.

If you haven’t already, I recommend you read this post first: How to run Incognito Blockchain on your local server


There are two ways to accomplish this:

Method 1 - build and runn from code:

  1. Find latest tag here:
    https://github.com/incognitochain/incognito-chain/tags

  2. Clone repo and checkout tag
    git clone https://github.com/incognitochain/incognito-chain.git
    git checkout mainnet_20200525_2

  3. Copy keylist-mainnet.json to keylist.json:
    cp -f keylist-mainnet.json keylist.json

  4. Build Incognito binary
    go build -o incognito

  5. Create tmux session and attach to it:
    tmux new -s mainnet_fullnode
    tmux attach

  6. Register an Infura account copy endpoints of mainnet, set the local environment variable:

export GETH_NAME="mainnet.infura.io/v3/12047eb6d7e6439fa3449d00c769XXXX"
export GETH_PROTOCOL=https
export GETH_PORT=""
  1. Run Incognito Fullnode
./incognito --discoverpeersaddress "mainnet-bootnode.incognito.org:9330" --testnet false --nodemode "relay" --relayshards "all" --datadir "data/full_node" --listen "0.0.0.0:9433" --externaladdress "0.0.0.0:9433" --norpcauth --rpclisten "0.0.0.0:9334" --txpoolmaxtx 100000 --loglevel debug
  1. Wait a few hours to sync blockchain data
  2. Send request getbeaconbeststatedetail to your fullnode
  • Request:
curl --header "Content-Type: application/json" \
  --request GET \
  --data '{ "id": 1, "jsonrpc": "1.0", "method": "getbeaconbeststatedetail", "params": []}' \
  http://localhost:9334
  • Response: If your epoch number "Epoch": 932 is the same as what is shown on the website https://mainnet.incognito.org/, then your full node is synchronized and up to date.
{
	"Id": 1,
	"Result": {
		"BestBlockHash": "ce1a9c792843dcba3813a9546558555e5dbd7a68889024412a75e1133aefa783",
		"PreviousBestBlockHash": "9b8b1150ceafefded4447b504c6c9438bfbce2579aaebca0cb26ab3f3c5b11cf",
		"BestShardHash": {
			"0": "b672c68969228ba5b945e9d5b4f5c682019c639670825321cf13e276cc2b2440",
			...
		},
		"BestShardHeight": {
			"0": 324606,
			...
		},
		"Epoch": 932,
		"BeaconHeight": 325880,
		"BeaconProposerIndex": 0,
		"BeaconCommittee": [
			{
				"IncPubKey": "1GkFSKoZFLdNu9PktskxMZ33Ygcdo5iF92HqWHWKTjFtriyDV1",
				"MiningPubKey": {
					"bls": "1TU11qo94rtaSPQNFKR9WyBMWK9VGGfzctnZdd9dgDwnGmbGAW8hevPjtLt7FM5bAs4pddLMWm4xoP8TF9n2LHQQ7xbmhpLgHb5qnTJ5LDb3ZVqJm5kYBKUfXDDZaKrjVY3K2Gx4gEpUGuWZikbULbt4oMymdL99UY4i1sxcx3fPGosqbs492",
					"dsa": "15hzC9p5Pcj2qkTgcmxX7LKWcdAqdQXtr1u4hjPp8p4s24rfUeA"
				}
			},
			...
		],
		"CurrentRandomNumber": 3474846368,
		"CurrentRandomTimeStamp": 1585537156,
		"IsGetRandomNumber": false,
		"MaxBeaconCommitteeSize": 32,
		"MinBeaconCommitteeSize": 7,
		"MaxShardCommitteeSize": 32,
		"MinShardCommitteeSize": 22,
		"ActiveShards": 8,
		"LastCrossShardState": {
			"0": {
				"1": 323430,
				...
				"7": 320410
			...
		},
		"ShardHandle": null
	},
	"Error": null,
	"Params": [],
	"Method": "getbeaconbeststatedetail",
	"Jsonrpc": "1.0"
}

image

Method 2 - running Full Node from official Incognito Docker:

  1. Save this script as incognito-fullnode.sh
#!/bin/sh bash
run()
{
  validator_key=xxx
  bootnode="mainnet-bootnode.incognito.org:9330"
  is_shipping_logs=1
  latest_tag=$1
  current_tag=$2
  data_dir="data_fullnode"
  eth_data_dir="eth-mainnet-data"
  eth_data_dir_geth="eth-mainnet-data-geth"
  logshipper_data_dir="logshipper-mainnet-data"
  docker -v || bash -c "wget -qO- https://get.docker.com/ | sh"
  if [ ! -d "$PWD/${eth_data_dir}" ]
  then
    mkdir $PWD/${eth_data_dir}
    chmod -R 777 $PWD/${eth_data_dir}
  fi
  if [ ! -d "$PWD/${eth_data_dir_geth}" ]
  then
    mkdir $PWD/${eth_data_dir_geth}
    chmod -R 777 $PWD/${eth_data_dir_geth}
  fi
  docker rm -f inc_mainnet
  docker rm -f eth_mainnet
  if [ "$current_tag" != "" ]
  then
    docker image rm -f incognitochain/incognito-mainnet:${current_tag}
  fi
  docker pull incognitochain/incognito-mainnet:${latest_tag}
  docker network create --driver bridge inc_net || true
  # docker rm -f eth_mainnet
  docker rm -f eth_mainnet
  # parity
  # docker run -ti --restart=always --net inc_net -d -p 8545:8545  -p 30303:30303 -p 30303:30303/udp -v $PWD/${eth_data_dir}:/home/parity/.local/share/io.parity.ethereum/ --name eth_mainnet  parity/parity:stable --light --jsonrpc-interface all --jsonrpc-hosts all  --jsonrpc-apis all --mode last --base-path=/home/parity/.local/share/io.parity.ethereum/
  # geth
  docker run --restart=always --net inc_net -d --name eth_mainnet -p 8545:8545 -p 30303:30303 -v $PWD/${eth_data_dir_geth}:/geth -it ethereum/client-go --syncmode light --datadir /geth --rpcaddr 0.0.0.0 --rpcport 8545 --rpc --rpccorsdomain "*"
  docker run --restart=always --net inc_net -p 9334:9334 -p 9433:9433 -e BOOTNODE_IP=$bootnode -e FULLNODE=1 -e GETH_NAME=eth_mainnet -e MININGKEY=${validator_key} -e TESTNET=false -v $PWD/${data_dir}:/data -d --name inc_mainnet_fullnode incognitochain/incognito-mainnet:${latest_tag}
  if [ $is_shipping_logs -eq 1 ]
  then
    if [ ! -d "$PWD/${logshipper_data_dir}" ]
    then
      mkdir $PWD/${logshipper_data_dir}
      chmod -R 777 $PWD/${logshipper_data_dir}
    fi
    docker image rm -f incognitochain/logshipper:1.0.0
    docker run --restart=always -d --name inc_logshipper -e RAW_LOG_PATHS=/tmp/*.txt -e JSON_LOG_PATHS=/tmp/*.json -e LOGSTASH_ADDRESSES=34.94.14.147:5000 --mount type=bind,source=$PWD/${data_dir},target=/tmp --mount type=bind,source=$PWD/${logshipper_data_dir},target=/usr/share/filebeat/data incognitochain/logshipper:1.0.0
  fi
}
# kill existing run.sh processes
ps aux | grep '[i]ncognito-fullnode.sh' | awk '{ print $2}' | grep -v "^$$\$" | xargs kill -9
current_latest_tag=""
while [ 1 = 1 ]
do
  tags=`curl -X GET https://registry.hub.docker.com/v1/repositories/incognitochain/incognito-mainnet/tags  | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n'  | awk -F: '{print $3}' | sed -e 's/\n/;/g'`
  sorted_tags=($(echo ${tags[*]}| tr " " "\n" | sort -rn))
  latest_tag=${sorted_tags[0]}
  if [ "$current_latest_tag" != "$latest_tag" ]
  then
    run $latest_tag $current_latest_tag
    current_latest_tag=$latest_tag
  fi
  sleep 3600s
done &
  1. Running script: sudo bash incognito-fullnode.sh
  2. Double check your docker container:
khanhlh@staking-khanhle:~$ docker ps | grep incognito
7b2d7a5e3c95        incognitochain/incognito-mainnet:20200525_2   "/bin/sh run_incogni…"   About a minute ago   Up 58 seconds       0.0.0.0:9334->9334/tcp, 0.0.0.0:9433->9433/tcp   inc_mainnet_fullnode
  1. Wait a few hours to sync blockchain data
  2. Send request getbeaconbeststatedetail to your fullnode
  • Request:
curl --header "Content-Type: application/json" \
  --request GET \
  --data '{ "id": 1, "jsonrpc": "1.0", "method": "getbeaconbeststatedetail", "params": []}' \
  http://localhost:9334
{
	"Id": 1,
	"Result": {
		"BestBlockHash": "ce1a9c792843dcba3813a9546558555e5dbd7a68889024412a75e1133aefa783",
		"PreviousBestBlockHash": "9b8b1150ceafefded4447b504c6c9438bfbce2579aaebca0cb26ab3f3c5b11cf",
		"BestShardHash": {
			"0": "b672c68969228ba5b945e9d5b4f5c682019c639670825321cf13e276cc2b2440",
			...
		},
		"BestShardHeight": {
			"0": 324606,
			...
		},
		"Epoch": 932,
		"BeaconHeight": 325880,
		"BeaconProposerIndex": 0,
		"BeaconCommittee": [
			{
				"IncPubKey": "1GkFSKoZFLdNu9PktskxMZ33Ygcdo5iF92HqWHWKTjFtriyDV1",
				"MiningPubKey": {
					"bls": "1TU11qo94rtaSPQNFKR9WyBMWK9VGGfzctnZdd9dgDwnGmbGAW8hevPjtLt7FM5bAs4pddLMWm4xoP8TF9n2LHQQ7xbmhpLgHb5qnTJ5LDb3ZVqJm5kYBKUfXDDZaKrjVY3K2Gx4gEpUGuWZikbULbt4oMymdL99UY4i1sxcx3fPGosqbs492",
					"dsa": "15hzC9p5Pcj2qkTgcmxX7LKWcdAqdQXtr1u4hjPp8p4s24rfUeA"
				}
			},
			...
		],
		"CurrentRandomNumber": 3474846368,
		"CurrentRandomTimeStamp": 1585537156,
		"IsGetRandomNumber": false,
		"MaxBeaconCommitteeSize": 32,
		"MinBeaconCommitteeSize": 7,
		"MaxShardCommitteeSize": 32,
		"MinShardCommitteeSize": 22,
		"ActiveShards": 8,
		"LastCrossShardState": {
			"0": {
				"1": 323430,
				...
				"7": 320410
			...
		},
		"ShardHandle": null
	},
	"Error": null,
	"Params": [],
	"Method": "getbeaconbeststatedetail",
	"Jsonrpc": "1.0"
}

image


PS. You can also try these RPCs with your new Full Node.

Any questions? Post them below.

11 Likes

Hi,

I’d like to build and run a node but

$ git checkout dbv2_20200330_1
error: pathspec 'dbv2_20200330_1' did not match any file(s) known to git

What tag/commit hash should I checkout? As a validator, how will I know when to update the code going forward?

@3ncrypt3d,

It could be this tag was deleted. Please try these command:

git fetch -a
git checkout mainnet_20200416_1

If you try method 2, this one is latest image:
incognitochain/incognito-mainnet:20200416_1


I’m updating 1st post as well

1 Like