Telos Technical How To #2

Ross Dold
EOSphere Blog

--

In the previous Telos Technical How To article you learnt how to build a Telos node and sync it to the Public Telos 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 Telos Snapshots

A valid snapshot can be used to sync a Telos 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 functionality 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 Telos snapshot services being provided by Telos Block Producers including EOSphere, however not all provide Testnet snapshots.. so you may need to look around a bit.

A great place to search is using Telos UK built public domain Open Keywords Platform

Here are a few Telos snapshot services that we can recommend:

EOSphere | snapshots.eosphere.io

CryptoLions | backup.cryptolions.io

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

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

EOS Nation | https://snapshots.eosnation.io/

Telos Unlimited | https://snapshots.telosunlimited.io/

Telos Central | https://teloscentral.com/snapshots/view

Usage

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

Download and unarchive the desired snapshot file:

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

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

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

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

> nodeos --data-dir ~/telosdata --config-dir ~/telosdata --snapshot ~/telosdata/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 Telos ecosystem is an excellent way to add value as a Telos 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 Telos Technical How To .. will look at querying your Telos Testnet Node, Hardening Security and Registering as a Telos Block Producer.

Be sure to ask any questions in the EOSphere Telegram

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

If you find our work helpful, please vote us on the Telos Mainnet: eosphereiobp

Connect with EOSphere via these channels:

TELEGRAM | MEDIUM |YOUTUBE | FACEBOOK | TWITTER | INSTAGRAM

--

--

EOSphere Blog
EOSphere Blog

Published in EOSphere Blog

Leading Australian Antelope Block Producer candidate serving the entire EOSphere

Ross Dold
Ross Dold

Written by Ross Dold

Co-Founder of EOSphere Australia