Guardnode guideΒΆ

A step by step guide for setting up the Guardnode stack that includes a CommerceBlock service chain full node, a client chain full node and guardnode daemon guardning the client chain.

  1. Running the service chain full node

Download the docker-compose file from ocean github and follow the docs instructions on how to run the node using data persistence.

The full node wallet will need to be funded with CBT in order to provide services. This can be done by paying to an address generated by the node or import a private key from another wallet.

Use the command line interface to find about active requests:

ocean-cli getrequests

(Under development) Also possible with the dedicated guardnode electrum wallet.

  1. Running the client chain node

Pick one of the active requests with an active auction and run the client chain full node for this chain request by downloading the guardnode repo and running the corresponding docker-compose file in the contrib directory.

(Under development) Also available in the CB services platform.

Start the client ocean node:

docker-compose -f contrib/docker-compose-filename.yml up -d ocean

Using the client chain node generate a pubkey to receive fee rewards on:

addr=`ocean-cli getnewaddress`
pub=`ocean-cli validateaddress $addr | jq -r ".pubkey"`
echo $pub
  1. Bid for a request

The following script can be used to bid for an active request. The following parameters need to be filled:

  • Fee pubkey generated previously
  • Request transaction id from getrequests rpc
  • Current auction price from getrequests rpc
#!/bin/bash
shopt -s expand_aliases

alias ocl="ocean-cli -rpcport=7043 -rpcuser=ocean -rpcpassword=password"

echo "Creating bid in service chain"

# Address tokens will be locked in
addr=`ocl getnewaddress`
pub=`ocl validateaddress $addr | jq -r ".pubkey"`

# Get asset unspent
unspent=`ocl listunspent 1 9999999 [] true "CBT" | jq .[0]`
asset_hash=`echo $unspent | jq -r ".asset"`
value=`echo $unspent | jq -r ".amount"`
txid=`echo $unspent | jq ".txid"`
vout=`echo $unspent | jq -r ".vout"`

# TO UNLOCK A PREVIOUS BID
# Provide the `txid` and `vout` for that transaction
# The output can be spent after the locktime is expired
# e.g.
# value=5000
# vout=0
# txid="\"a327b15679f7fd0a8984cdb16f07c2c92063c5565af2f7ce99cff8d4750add8d\""

# Fee
fee=0.001
# Current auction price
bid=
# Change from unspent
change=$(echo "$value - $fee - $bid" | bc)

# Request id in service chain
requestid=""
# Request end height
end=
# Fee pubkey to pay fees in clientchain
feepub=""

inputs="[{\"txid\":$txid,\"vout\":$vout,\"asset\":\"$asset_hash\"}]"
outputs="{\"endBlockHeight\":$end,\"requestTxid\":\"$requestid\",\"pubkey\":\"$pub\",\
\"feePubkey\":\"$feepub\",\"value\":$bid,\"change\":$change,\"changeAddress\":\"$addr\",\"fee\":$fee}"

signedtx=`ocl signrawtransaction $(ocl createrawbidtx $inputs $outputs)`
txidbid=`ocl sendrawtransaction $(echo $signedtx | jq -r ".hex")`
echo "txid: $txidbid"

To use the script create a file called create_bid.sh with the contents and do the following commands:

cp create_bid.sh ../datadir/

docker-compose -f contrib/docker-compose-filename.yml exec ocean bash

./home/bitcoin/.bitcoin/create_bid.sh
  1. Running the guardnode service

Verify that the bid has been approved by using the service node:

ocean-cli getrequestbids $requesttxid

Once verified fill the bidpubkey and bidpubkey arguments on the docker-compose file downloaded for the client chain under guardnode and start the guardnode service by:

docker-compose -f contrib/docker-compose-filename.yml up -d guardnode

Monitor the logs using and look out for any alerts:

docker-compose -f contrib/docker-compose-filename.yml logs --follow guardnode