Deploy your own local Alastria/Quorum test network automatically

Alfonso de la Rocha
DRILL
Published in
4 min readApr 25, 2018

You: Look! It’s moving. It’s sha — it’s… it’s alive. It’s alive… It’s alive, it’s working, it’s alive! It’s alive, it’s alive, it’s alive! The Blockchain is ALIVE!

Victor: Henry — in the name of God!

You: Oh, in the name of God! Now I know what it feels like to BE God!

— — — Frankestein, Whale (1931)

One of the main problems people are facing when they want to start playing with blockchain technologies and Alastria, is the need of a test-net environment. Whether you want to try your brand new consensus algorithm, or you want to test your awesome smart contracts for you dApp, you need an infrastructure for your tests. A few posts ago, I announced that from the Alastria’s Platform Technical Team, we were working to develop an environment to allow everyone to test locally Alastria’s infrastructure.

Actually, this project was born as a response to our personal needs to have a test environment, independent from Alastria’s test-net, where we could test new developments, errors and bugs without bothering the rest of the partners in the official test-net. And finally, after these past few weeks of intense work, I found the time to release a first version of our Alastria test-environment. All the code for the tool is available here.

And at this point you may be thinking, “Ok, I get it, but stop all this chit-chat and teach me how can I run my own local Alastria/Quorum network”. Let’s start then. The first thing to do is to clone the test-environment repository:

git clone https://github.com/alastria/test-environment/
cd test-environment/infrastructure/testnet

I recommend you to deploy your tests in an environment where you don’t have a real Alastria node deployed, as this tool could mess with your node’s configuration and dependencies. Having this in mind, with the code downloaded, you must install the dependencies for the environment:

sudo apt-get install wget netcat
./bin/bootstrap.sh

We included the installation of wget and netcat manually before applying the bootstrap script just in case you are using an empty environment (such as an empty docker container). The bootstrap script uses sudo for certain operations, so if you are using a docker container, I suggest you also install sudo before running it (I know, this shouldn’t be needed, but we want to use and test Alastria’s code as-is, and right now alastria-node is not meant to be run as root).

With every dependency installed, we are ready to run our test-environment:

./bin/start_network.sh clean <num-validators> <num-gws>

The clean mode starts a network from scratch, and <num-validators> and <num-gws> allows you to define the topology of your network. Right now, the maximum number of validator and gateway/regular nodes supported in the tool are three and four respectively, allowing you to deploy a network of up to seven nodes. Thus, to start a network with two validators and three regular nodes we can run:

./bin/start_network.sh clean 2 3 

Let’s test if everything worked… We can inspect the log of each node at logs/ . And we can attach to any of the nodes and start playing with the blockchain as:

geth attach ./network/<node-identity>/geth.ipc
# Example using IPC
geth attach ./network/main/geth.ipc
geth attach ./network/validator1/geth.ipc
geth attach ./network/general1/geth.ipc
# Or we can use the RPC API
geth attach http://127.0.0.1:22001

We can use these RPC/IPC interfaces to connect a node to our favorite Ethereum/Quorum development tools, such as Truffle (more about this in other posts).

If we want to stop the network we just need to run:

./bin/stop_network.sh

And what about restarting our previously stopped network? We’ve thought about everything, just run the command using the restart mode:

./bin/start_network.sh restart 2 3

So with this we have a pretty nice Alastria local testnet running to start trying (and breaking) things. If, apart from this, you want to have a graphical view of the state of your network you can install the eth-netstats tool as follows:

sudo apt-get install npm nodejs
sudo ln -s /usr/bin/node /usr/bin/nodejs
./bin/start_ethstats.sh

After a few minutes of installation and configuration, you should have the status of your network at http://localhost:3000.

So there you go, a brand new local Alastria testnet ready for action. For the bravest Alastrians, in the project we have included some advanced scripts to enhance the functionalities of the test-environment such as:

#Starts a new node with another identity on an existing and already started network
./bin/start_node.sh
#Cleans the testnet and the blockchain state in order to start a new network.
./bin/clean_env.sh
# After cleaning, this script prepares a new test environment without starting the network
./bin/config_network.sh

# Allows the generation of new identities in order to extend the number of nodes that may be run in the testnet
./bin/new_identity.sh
# NOTE: Be careful with this last script. It creates new identities, but in order to use it in the testnet you must modify the node permissioning and, if you create a validator, propose it before starting the network. This will require modifications in the start_network.sh script.

As a final note, I really hope this tool is as useful for you as it currently is for us. If you face problems or find bugs, if you have feedback or suggestions, or if you just want a more thorough explanation about how the tool works, don’t hesitate contacting me or placing an issue in our github.

In the following weeks, our aim is to develop a tool to deploy an Alastria testnet over a Docker/Kubernetes infrastructure, to easily deploy the system in a production-ready environment, allowing us to debug and test our “powered by Alastria” applications in a real environment. Keep tuned for updates.

--

--