Proton Technical How To #2

Ross Dold
EOSphere Blog

--

In the previous Proton Technical How To article you learnt how to build a Proton node and sync it to the Public Proton Testnet. You will have noticed that syncing up to a blockchain that has been running for millions of blocks can take quite some time. Luckily Syncing up can be expedited by using an existing valid snapshot of the chain state database.

In this Second Edition will show how to make use of snapshots as well as how to create them yourself.

How to use Proton Snapshots

A valid snapshot can be used to sync a Proton nodeos process up to a desired block on launch by using a snapshot file to recreate a valid chain state database.

This alleviates the need to build the state database one block at a time from block #1, which takes time to catch up to the chain head block which can be in the millions or more.

Explanation

The chain state database shared_memory.binis needed by nodeosto run, it is a memory mapped file that contains the state associated with each block, including smart contract data, account details and deferred transactions.

There is however a caveat. Depending on the function you require of your node, for instance running it as a P2P seed node or fully functional API node you will also require the associated complete blocks.log from block #1 to be able to provide a “full” node service.

It should also be mentioned that the state-history database as well as the now depreciated V1 History functionality is not preserved in a snapshot and will require a full replay.

It is possible to run nodeoswithout any existing blocks.log with a current snapshot file but this node wouldn’t be considered “full” and would typically only be used to query current chain info and push actions.

Ideally snapshots should be used with an associated blocks.log containing a higher head block number. To summarise the above, lower block in snapshot.. higher block in blocks.log when you start nodeos.

Common Scenario

The most common use for a snapshot is recovering from an incorrectly stopped node.. power failure, out of memory, process killed etc.

nodeos needs to be gracefully exited otherwise the state database may be corrupted showing this nasty error:

“Database dirty flag set (likely due to unclean shutdown): replay required”

Locating a snapshot

First of all you need to obtain a valid snapshot file from a trusted source. There are quite a few Proton snapshot services being provided by Proton Block Producers including EOSphere, however not all provide Testnet snapshots.. so you may need to look around a bit.

Here are a few that we have used:

EOSphere | snapshots.eosphere.io

CryptoLions | backup.cryptolions.io

EOS Sw/eden | snapshots.eossweden.org

EOSUSA | http://snapshots.eosusa.news/snapshots/

EOS Amsterdam | https://snapshots.eosamsterdam.net

CryptoBloks | https://bp.cryptobloks.io/supported-chains/proton-blockchain.html

Saltant | https://snapshots.saltant.io/ (Currently a complete backup rather than a snapshot)

Usage

Using the example nodeos build in the previous Proton Technical How To, all relevant files are located in ~/protondata.

Download and unarchive the desired snapshot file:

> sudo apt install zstdcd > cd ~/protondata/snapshots> wget http://snapshots.eosphere.io/snapshots/proton/snapshot.bin.zst> unzstd snapshot.bin.zst

Delete the existing (if any) state database and blocks reversible:

> rm -r ~/protondata/state> rm -r ~/protondata/blocks/reversible

Launch nodeos from the downloaded snapshot (noting that the genesis.json is not specified):

> nodeos --data-dir ~/protondata --config-dir ~/protondata --snapshot ~/protondata/snapshots/snapshot.bin

nodeos will now start from a snapshot and attempt to sync to the active chain from the head block captured in the used snapshot file. The blocks.log will also be continued from the snapshot block number, that is why it is important to ensure a lower block in the snapshot.. higher block in blocks.log to avoid gaps.

Generating snapshots

The most security conscious way of using snapshots is to create and use your own. Also providing a snapshot file hosting service for the rest of the Proton ecosystem is an excellent way to add value as a Proton Block Producer.

To generate a snapshot nodeos requires a producer api plugin configured. Add the following to the end of your config.ini and restart nodeos.

plugin = eosio::producer_api_plugin

Warning: Exposing the producer_api_plugin publicly is a security risk and can be exploited, the node used for creating a snapshot should not be publicly queryable.

Generate a snapshot locally using the following syntax, the snapshot file will by default be saved to the snapshots folder:

curl -X POST http://127.0.0.1:8888/v1/producer/create_snapshot

In the Next Edition of Proton Technical How To .. will look at querying your Proton Testnet Node, Hardening Security and Registering as a Testnet Block Producer.

Be sure to ask any questions in the EOSphere Telegram

EOSphere is a Block Producer on the Proton Mainnet and Testnet Blockchains as well as many other EOSIO based Blockchains.

If you find our work helpful, please vote us on the Proton Mainnet: eosphere

Connect with EOSphere via these channels:

TELEGRAM | MEDIUM |YOUTUBE | FACEBOOK | TWITTER | INSTAGRAM

--

--