- Bill Clark
- Posts
- Cardano Node at Home: Running the Node
Cardano Node at Home: Running the Node
Part 2: Starting the containers and monitor initial sync
[If you missed it, here’s Part 1 of the guide]
Welcome back to the Cardano Node at Home guide! In this segment, Running the Node, we’ll cover cloning the git repository to your computer, starting the node, and monitoring its initial sync progress.
Set Up the Node Environment
To make the management of the server a little more organized, we're going to set up a folder structure in our home directory.
Log into your server if you're not already logged in. Make sure you're in your home directory; use cd ~
to get there.
Create a new directory called docker
:
mkdir docker
Change to this directory:
cd docker
Clone the Git Repository
Clone the cardano-compose-stacks
repository:
git clone https://github.com/blinklabs-io/cardano-compose-stacks.git
Change into the new project directory:
cd cardano-compose-stacks
Change the default password for the Postgres databse:
nano ./postgres-config/secrets/postgres_password
In this file, replace changeme
with a secure password. When completed, hit Ctrl-X to exit, Y to save, and Enter to confirm.
Starting the Cardano-Node Docker Stack
In this part, we'll fire up our node for the first time. Thanks to Mithril, the initial sync no longer takes upwards of 24 hours to complete: on my example machine, the initial sync took approximately 45 minutes. The example machine was a 4-core ARM-based AWS instance with 32GB RAM. This was overkill—it didn’t take any longer on a 2-core instance with 16GB of RAM; I tested.
We'll also learn how to monitor the node from the command line using docker logs
and docker exec
so you can watch the progress of your node's sync.
To start the docker-compose stack, first navigate to the cardano-compose-stacks directory:
cd ~/docker/cardano-compose-stacks
Once you're in the directory, run the following command to start the cardano-node container:
docker compose --profile tx-submit-api up -d
The --profile tx-submit-api
flag and option tell docker compose to start the core cardano-node container and the tx-submit-api container, which is where you’ll send your transactions.
The -d
flag in the command above is shorthand for "detach," which just means to run the container in the background rather than printing its output to our console.
Important Note: The container will begin to start after the above command. However, it may appear to be frozen for up to an hour. Alternately, you may receive a message that the health check failed. This is normal and expected behavior upon the very first launch of a fresh node. What’s happening in the background is the node is downloading a rather large file, a signed mithril snapshot of the blockchain. For more information on Mithril snapshots, see https://docs.cardano.org/developer-resources/scalability-solutions/mithril/.
Docker Container Logs
To cheat a bit and monitor the progress of your node, you can SSH into the computer or open another terminal session using Alt + F2 on your console keyboard and use the logging features of Docker.
To take a look at the logs to see if the node is running or if it threw any errors, use the following command:
docker logs cardano-node -f
The -f
flag above is shorthand for "follow" which just means to keep printing the logs to the screen as new entries come in.
With the Mithril client, you’ll only see one message printed to the logs at the outset; you’ll see something similar to the image below:
Cardano-Node log output illustrating the Mithril snapshot download
Once you see output similar to the image below, your node is synced and adding new blocks:
Cardano-Node log output illustrating new blocks being added to the blockchain
To exit from this log console, hit Ctrl + C
on your keyboard.
Querying Sync Progress
To check the node's sync status, we can use the docker exec
command to execute a cardano-cli command inside the container:
docker exec cardano-node cardano-cli query tip --mainnet --socket-path /ipc/node.socket
The command above tells docker to execute (docker exec
) inside the container cardano-node (cardano-node
), the command cardano-cli query tip --mainnet --socket-path /ipc/node.socket
.
The output should be JSON-formatted text that looks like the image below:
Example cardano-cli output displaying sync status
What you're seeing above is a collection of data:
block
is the current block number the node has proccessed to.epoch
is the epoch in which the current block occurred in.era
is the era of the chain at that point in time.hash
is the hash of the block.slot
is the slot number in which the block was produced (each slot is 1 second since the time the chain went live).syncProgress
is the node's progress in syncing with the blockchain. When this number reaches 100.00%, the sync is complete, and your node continues to process new blocks as they're distributed.
Stopping the Node
If you need to stop your node at any time, first change to the project directory:
cd ~/docker/cardano-compose-stacks
Then, run the following command to bring down the docker-compose stack (this will stop any containers running; such as cardano-node and tx-submit-api):
docker-compose down
Note that if you stop the node after some time and later restart it with docker-compose --profile tx-submit-api up -d
, the node will take a little time to catch up and verify the state of part of the chain it's already downloaded.
You'll see messages about opening the Ledger DB and replaying blocks with blue tags in the log output. After a while, the magenta messages start scrolling again after the node has caught up verifying its previous work.
See Part 3 for More
In the final segment, we'll learn how to send transactions to the blockchain using our tx-submit-api
endpoint and Eternl wallet.