Intro
Bitcoin Cash (or BCH for short) is a [separate!] version of Bitcoin which provides much reduced transaction costs and improved transaction rates.
Crypto currencies use a network of machines which work together to produce a ledger of transactions which make up a universally agreed (and cryptographically provable) history.
If you, like me, have a Microsoft Partner Network account which doesn't get used to its full extent each month, then running a BCH node on Azure is an easy way to contribute to the project. (Or indeed if you don't have a MPN account and you're just a generous person!)
What will I have when this process is complete?
If you follow these steps, you will have a Virtual Machine in the Microsoft Cloud (a.k.a. Azure) which is actively participating in the running of the Bitcoin Cash peer to peer network.
What's in it for me?
There are options for your node to charge a small transaction fee, but that's beyond the scope of this article and not its intended purpose
Peer to peer generally relies on community contribution of resources (CPU, bandwidth, disk).
As my father used to say: "You get a Gold Star!"
What is required?
Running a simple BCH node doesn't require a powerful machine, a B1ms SKU VM is sufficient and is also inexpensive.
What does take up a bit more resource is the disk space required (currently approximately 168Gb) to store the ledger data and the subsequent outbound bandwidth which your node will use to share that data.
I currently run a node in the North Europe Azure Region and it averages about £1.50 (GBP) per day for all resources - or roughly £45 a month.
The variation in cost comes due to fluctuations in the amount of outbound network usage.
An Azure Subscription is required: if you don't have one, you can create a subscription with free credit (currently GBP £150) here
Installation Steps
These steps are specific to Windows, but should be easily adapted to other platforms
By default, Windows comes with PowerShell installed, but if you don't have it for some reason (or you are using a different operating system), get it here
- Install the Azure CLI
- Start a command shell (dos, powershell etc.)
- Run at the command prompt to log in:
az login
- After successful login, note the id of the subscription you wish to use by running this at the command prompt:
az account list --output table
- Copy and paste this script into your text editor of choice (notepad etc.):
$subscriptionid="..."
$region="northeurope"
$resourcegroup="BCH"
$username="azureuser"
$pwd="Replacemewithsomethinggoodandl0ngandstuff!"
$resourceprefix="bch"
$sku="Standard_B1ms"
$publicport="8333"
$vnetname=$resourceprefix + "-vnet"
$nsgname=$resourceprefix + "-nsg"
$subnetname=$resourceprefix + "-subnet1"
$diskname=$resourceprefix + "-disk"
$disksizegb=256 # you may need to increase this in future
$vmname=$resourceprefix
$cloudinit=@'
#!/bin/sh
sudo apt-get update
sudo apt-get install docker.io -y
diskpoint=$(lsblk -o NAME,SIZE | grep -i "DISKSIZEG" | awk '{print $1}')
sudo parted /dev/${diskpoint} --script mklabel gpt mkpart xfspart xfs 0% 100%
sudo mkfs.xfs /dev/${diskpoint}1
sudo partprobe /dev/${diskpoint}1
sudo mkdir /bch
sudo mount /dev/${diskpoint}1 /bch
diskuuid=$(sudo blkid | grep "/dev/${diskpoint}1" | sed -r 's/[[:alnum:]]+=/\n&/g' | awk -F= '$1=="UUID"{print $2}' | tr -d '"')
echo "UUID=${diskuuid} /bch xfs defaults,nofail 1 2" | sudo tee -a /etc/fstab
sudo docker run -d --log-driver none --restart unless-stopped -p 8333:8333 --security-opt no-new-privileges:true --name=bitcoind -v /bch:/data zquestz/bitcoin-cash-node
'@
$cloudinit = $cloudinit -replace "DISKSIZE", $disksizegb
$myip=(Invoke-WebRequest -uri "https://ifconfig.me/ip").Content
$cloudinitfilename = 'bch.sh'
$cloudinit | Out-File -Encoding utf8 -FilePath $cloudinitfilename
az account set --subscription $subscriptionid
az group create -n $resourcegroup -l $region
az configure --defaults location=$region group=$resourcegroup
az network vnet create `
--name $vnetname `
--address-prefix 10.0.0.0/16 `
--subnet-name $subnetname `
--subnet-prefix 10.0.0.0/22
az network nsg create --name $nsgname
az network nsg rule create --name OwnerAccess --nsg-name $nsgname --priority 100 --access Allow --direction Inbound --source-address-prefixes $myip --destination-port-ranges "22"
az network nsg rule create --name P2PInbound --nsg-name $nsgname --priority 101 --access Allow --direction Inbound --source-address-prefixes '*' --destination-port-ranges $publicport
az network vnet subnet update `
--vnet-name $vnetname `
--name $subnetname `
--network-security-group $nsgname
az disk create --name $diskname --size-gb $disksizegb --sku StandardSSD_LRS
az vm create --name $vmname `
--admin-username "$username" `
--admin-password "$pwd" `
--authentication-type all `
--image Canonical:UbuntuServer:18.04-LTS:latest `
--attach-data-disks $diskname `
--size $sku `
--data-disk-caching ReadOnly `
--nsg $nsgname `
--storage-sku Standard_LRS --os-disk-size-gb 30 `
--custom-data @$cloudinitfilename
- You must change the first line: alter $subscriptionid="..." to use the subscription id you noted down in step 4
- Alter $region="northeurope" if you wish to run your node in a different Azure region
- Type "az account list-locations --output table" at the command prompt to get a list of regions
- Use the value in the "Name" column for your chosen region to replace the default of northeurope
- Alter $pwd=... with a suitable value (must have an upper case letter, lower case, a number and a special character)
- If you wish to specify the name of the resource group to use, alter $resourcegroup="BCH" with a different value
- Save the altered script
- Run the altered script from a Powershell Command Prompt (it takes a few minutes, so start if off now then continue reading below)
My Goodness, what does all of that do!!?
- Creates a resource group (A grouping of resources in Azure: you can log in to the Azure Portal and select "Resource Groups" from the top-left menu to see the resource group named BCH which this is deploying to)
- Creates a Virtual Network
- Creates a Network Security Group
- Creates rules in the Network Security Group to open the required network ports for this service
- Creates a (Standard Tier) Azure Managed SSD disk
- Creates a Virtual Machine and attaches the disk to it
- Mounts the managed disk at /bch
- Installs Docker
- Runs this excellent Docker container with a volume mapping to /bch
So what happens next?
For now, you need to wait: it takes time for your node to download and validate the full bitcoin cash transaction ledger (referred to as synchronisation)
It can take a few days to synchronise depending on various things. If you want to speed things up a little bit, see point number 3 in the Notes section below
Examine Your VM
- To check the progress of your node's synchronisation process:
- Connect to your VM (see section below)
- After the initial deployment, the VM will still be installing docker etc. - so if the next step doesn't work yet, wait a few minutes
- Copy the text below and right-click your command prompt window to paste
sudo docker exec -it bitcoind bitcoin-cli -rpcuser=bitcoin -rpcpassword=password getblockchaininfo | grep -i "blocks\|headers"
- The result of the command above will have a value for "blocks" and a value for "headers": when the value for blocks is the same as the value for headers, your node is finished downloading the Bitcoin Cash ledger
- After the initial block download, the verification process which checks integrity can take some time to catch up. Run this to view the progress of the integrity check (though it never reaches one):
sudo docker exec -it bitcoind bitcoin-cli -rpcuser=bitcoin -rpcpassword=password getblockchaininfo | grep -i "verificationprogress"
- You can check that your node is active (completely synced and listening for network traffic) by entering the public ip address of your VM (which you found previously) in to this Node Checker
- Note that if/when you stop/restart your VM, it takes some time for it to re-validate and re-sync with the network before it will show as available in the tool above
- If you increased the size of your VM in order to speed up the synchronisation process, you can decrease the size now (B1ms is adequate)
Connecting to your VM
- Visit the Azure Portal using a web browser and locate your VM
- By default it is called "bch", so searching for bch in the portal search bar should locate it quickly
- Be aware there will be multiple results from this search: the disk, network etc. - so be sure you select the one labelled "Virtual Machine"
- You should now be at the "Overview" for the VM
- On the overview blade you will find the public ip address: write this down / copy this to your clipboard
- Open a command prompt
- Type ssh azureuser@[the ip address from above] (for example: azureuser@40.69.31.123)
- If the command times out, your IP address may have changed
- The security rules for the VM use your network address at the time of creation to grant access to the SSH port on the VM, but your internet access provider most likely uses dynamic IP address assignment so the network address of your local machine may change over time
- In this case, a quick visit to a site such as WhatIsMyIP will give you your new address
- Visit the Networking blade of your VM. There you will find a rule called "OwnerAccess": click on it and replace the current value for "Source IP Address" with your new address and click "Save"
- Retry the ssh command above (you may need to wait a minute or two for the rule change to take effect)
- If prompted, indicate that you accept the host certificate by typing "yes" or "y" as prompted
- You should now have a prompt something like "azureuser@bch:~$"
I've had enough, how do I stop?!
If you decide that this is not working out or you wish to stop running your node, there are two options:
Stop your VM
- This will stop the virtual machine, but you will continue to be charged for your disks as the data is still being stored in case you wish to start your VM again
- To temporarily stop your node
- Visit the Azure Portal using a web browser and locate your VM as before
- Click the "Stop" button
- That's it! Your machine will shut down and you won't be billed for the machine itself any more (see the note above regarding data storage)
Permanently delete everything
- Visit the Azure Portal using a web browser and locate your VM as before
- The VM overview has a link to the resource group which it is part of ("BCH" by default)
- The Resource Group page has a list of all the resources relating to your BCH node
- At the top of the page is a "Delete Resource Group" button
- This will delete absolutely everything - including data disks - and is permanent
- Future billing will be zero
Notes
- The VM created has just a minimal standard hard drive provisioned for its operating system (to keep costs low)
- The docker container has logging switched off (--log-driver none) to prevent unnecessary disk writes to the hard drive mentioned above
- If you want to get your node synced to the BCH network a bit faster, you can do the following:
- In the Azure Portal, navigate to the VM Overview (see the first point in "Connecting to your VM" above)
- Stop the VM using the Stop button
- Select the "Size" blade/menu option on the left
- By default, the VM will be sized as a B1ms: this has limited CPU - sufficient for normal running, but during network sync additional CPU is useful
- Select a larger size according to your budget (REMEMBER to come back and resize later unless you want an unnecessarily high cost!)
- Start the VM again
- Using a DS2 v2 took about 5 hours to download and then another couple of hours(?) to complete verification, but this is anecdotal as it will depend not only on the power of your VM, but also the number of other available network peers, their load/bandwidth etc.
Contribution
If you found this article useful, please consider making a Bitcoin Cash donation to:
qp4pkw6uwqkukj59mvrjfyj6r6tud7mllgcms5e2ut