DEV Community

Cover image for How to Speed Up Blockchain Node Setup Using Node Snapshots for Quick Synchronization
siegkamgo
siegkamgo

Posted on

How to Speed Up Blockchain Node Setup Using Node Snapshots for Quick Synchronization

Decentralized networks rely on blockchain nodes to function, they play an important role in functions such as validating transactions, storing blockchain data, and maintaining network security. Whether we’re developers, validators, or simply enthusiasts, running a full blockchain node is an essential task that enables us to contribute to and interact with the network directly. However, as blockchain grows in popularity, the size and complexity of the data they store increase, making it challenging to run and maintain these nodes.

The Growing Storage Demands of Proof-of-Stake Blockchains

As Proof-of-Stake (PoS) blockchains continue to expand, the amount of storage required to run full nodes has grown substantially. Popular blockchains like Polygon PoS, Binance Smart Chain (BSC), and Coinbase's Base Chain now require massive amounts of storage:

  • Polygon PoS: At least 2.5TB of storage
  • BSC Chain: At least 3TB
  • Base Chain: At least 750GB

These large data sizes make the process of syncing a full node both time-consuming and resource-intensive. For instance, syncing a full node on the Polygon network can take anywhere from 2 to 3 days. The official Polygon documentation recommends using node snapshots to speed up this process, reducing the sync time from 3 days to approximately 16 hours.

Introducing Node Snapshots by Public Node: A Solution to Speed Up Node Synchronization

Node snapshots are essentially point-in-time copies of a blockchain's state that can be used to quickly bring a new node up to speed. Instead of downloading and processing the entire blockchain from scratch, which can take days, a snapshot allows us to start from a recent state and sync only the latest blocks. This approach saves time and improves the accuracy of node synchronization by reducing the potential for errors that can occur during full blockchain downloads.

Traditional methods of syncing, which involve piecing together the blockchain from the genesis block, can be prone to errors, especially if network interruptions or hardware issues arise. By using snapshots, the likelihood of these errors is minimized, as the node starts from a verified, stable state. Additionally, snapshots help in reducing the strain on your hardware by minimizing the processing load during synchronization. This reduces the time and computational resources required to get a node up and running. While many blockchains provide snapshots, these can sometimes be outdated or incomplete. When I attempted to set up a Polygon PoS full node, I found that the snapshot provided by the official documentation was no longer current.

After some research, I discovered a free service called Public Node. This service is maintained by Allnodes and offers free up-to-date snapshots for Polygon Heimdall and Bor Mainnets, Testnets, and 100+ other blockchains, providing a faster and more reliable way to synchronize full nodes.

Using Node Snapshop to Run a Full Node: My Experience with Polygon PoS

Running a Polygon PoS full node involves setting up both the Heimdall and Bor clients. Here’s a quick primer on how the Polygon blockchain works:

Primer on How Polygon Works

The Polygon blockchain operates as a layer-2 solution built to run alongside Ethereum. It enhances scalability and reduces transaction costs by processing transactions off-chain and using Ethereum to store checkpoint transactions.

Image description

The Polygon PoS network, which uses a Delegated Proof-of-Stake (DPoS) mechanism, consists of three layers:

  • Ethereum Layer: Manages stakes and stores checkpoints through smart contracts on Ethereum.
  • Heimdall Layer: Validates blocks produced by the Bor layer and commits checkpoints to Ethereum.
  • Bor Layer: Accepts user transactions, assembles them into blocks, and operates as an Ethereum Virtual Machine (EVM)-compatible sidechain.

Given Polygon’s popularity, the data size for running a full node has grown significantly, making synchronization a challenge. To address this, I used Public Node to expedite the process.

Challenges with Running Polygon Nodes

Polygon’s high processing speed and low transaction costs make it a preferred choice for decentralized applications (dApps). However, as the network grows, so does the disk usage for Bor and Heimdall, which now exceeds several terabytes. Synchronizing this data to provision a new full node typically takes 2–3 days, which can be a major bottleneck.

To solve this problem, the official Polygon documentation suggests using node snapshots. However, the snapshot provided was outdated, leading me to discover the Public Node Node Snapshots service.

Tutorial: Running a Polygon Full Node with Public Node

This tutorial presumes that you have some basic knowledge about the AWS EC2 instances. If not, you can check it out here.

With that in mind, here’s a step-by-step guide on how I used the Node snapshot to run a Polygon full node:

1. Downloading Heimdall Snapshot

Navigate to the Heimdall data directory:
cd /var/lib/heimdall
rm -r ./data

Download the latest Heimdall snapshot: Navigate to the Polygon section of the Public Nodes website and click on “Copy Link” and paste it into your working environment

Image description

Wget https://snapshots.publicnode.com/polygon-heimdall-19970284.tar.lz4

Open a screen session to run the download:

screen
sudo aria2c -j 12 -x 12 --console-log-level=warn --auto-file-renaming=false --summary-interval=3600 -c -i ./heimdall-mainnet-files.txt

The download size is around 323GB and takes about 3 hours, depending on network speed. After completion, change ownership:

sudo chown -R heimdall:nogroup /var/lib/heimdall

Restart the Heimdall service and check the sync status:
sudo service heimdalld start
curl localhost:26657/status

2. Downloading Bor Snapshot

Navigate to the Bor data directory:
cd /var/lib/bor/data/bor
rm -r ./chaindata

Download the latest Bor snapshot from Public Nodes: Again, simply navigate down to the Polyson section and copy the snapshot link

Wget https://snapshots.publicnode.com/polygon-bor-base-0-59369564.tar.lz4
sudo aria2c -j 6 -x 6 --console-log-level=warn --auto-file-renaming=false --summary-interval=3600 -c -i ./bor-mainnet-files.txt

The download size is around 3TB and can take 6–12 hours. After completion, change ownership:

sudo chown -R bor:nogroup /var/lib/bor
sudo service bor start

3. Adjusting the Configuration File

Modify the configuration to maintain node health and synchronization:
cd /var/lib/bor
sudo vim config.toml

Increase peer count, update bootnodes and trusted nodes, and ensure API settings are enabled.

Restart the Bor service to apply all the changes and ensure that your node appears on the Polygon telemetry dashboard.

These steps, combined with the use of Node Snapshots by Public Node, allowed me to get the Polygon full node up and running in significantly less time than traditional methods.

Conclusion

Running a full blockchain node can be an overwhelming and time-consuming process, especially as the data sizes of popular blockchains continue to grow.
However, by using Node Snapshots, I was able to reduce the time it took to synchronize a Polygon PoS full node, cutting down the process from days to just hours. This tool is invaluable for anyone looking to run full nodes efficiently, whether on Polygon or one of the many other blockchains supported by Public Nodes. By streamlining the synchronization process, Node Snapshots helps developers and node operators save time and resources, making the task of running a full node more accessible and manageable.

Top comments (0)