Forword

When we install a new NEO node, the first thing to do is to synchronize this node to the latest block height. Because only in this way, can your node have the data that matches the data on the blockchain and correctly accept and send the transaction from this node. Due to the huge volume of blockchain data, anyone with the experience of node synch must have a deep understanding: the waiting time for the first-time synch is usually very long. If you don’t use any fast sync solution, it takes a few days to complete, and the process of waiting is very grueling.

NEO has introduced a fast synchronization solution that uses offline sync packets for synchronization. An offline sync package is a compressed file that wraps the data on the blockchain. When the node detects that there is an offline synchronization packet locally, it will directly obtain data from the offline synch packet, which reduces the consumption of data acquired by the node from the network and speeds up the synchronization. Using this synchronization scheme can reduce the overall synchronization time to a few hours. Although it is a significant improvement, it is still too slow for developers who want to quickly experience NEO nodes or want to quickly add more nodes.

In the following, we will introduce a faster way to synchronize and will publish a specific tutorial.

Text

When the NEO node synchronizes data, it essentially acquires data in the block, analyzes and validates the block data, and stores the data into leveldb according to “block”, “transaction”, “asset”, “contract”, etc. If you can ensure that the leveldb stored content of the node is the same as the stored content of the seed node on the blockchain, you can ensure that the data of this node is safe and reliable. Furthermore, if every database operation is correct and there is no omission, the data that the node synchronizes is correct and reliable.

If you can remove the data verification and classification step, directly operate leveldb, add and delete data on leveldb, it will certainly speed up the synchronization. First, the NEL records the node’s operations on leveldb. For example, what data is put at height 1 and what data is deleted. The new node can re-operate leveldb according to these ordered operations, thus ensuring the consistency of the two leveldb data. This sacrifices a certain amount of security, but in the case of that the data source is ensured reliable, it still meaningful to have a quick synchronization in the sacrifice of security to some extent.

This synchronization method is faster than the officially launched fast synchronization packet. The bottleneck of synchronization speed is the read and write speed of your hard disk. The time to synchronize to the latest height is usually ten minutes. NEL has made the new synchronization feature a plugin and packaged the database operations into a compressed file for developers to use. As long as you use NEL custom-modified nodes (neo-cli-nel), you can add this plug-in and achieve fast synchronization. Temporarily official original nodes cannot use this plugin.

Use process (take TestNet as an example)

0x01 Download neo-cli-nel

Since some functions in the fast synchronization are not supported in the original node (neo-cli), only the node after the NEL revision (neo-cli-nel) can be used at present. The revised node only adds some customized functions, which is as reliable and secure as the original version, and the related request interface remains unchanged. Here is the address of Github: https://github.com/NewEconoLab/neo-cli-nel.git. After compiling, you can see the following directory interface:

Both config.json and protocol.json are the default TestNet environments. Open the startUp.bat, then you can run the node.

0x02 Download the quick sync plugin

The GITHUB address for the NEL plugin is: https://github.com/neweconolab/plugins.git

Plug-in name：RestoreDB

Create two new folders under the node directory in 0x01, one named Plugins and the other named NEL_Plugins, as shown below:

Move the compiled Restore plugin to the NEL_Plugins directory as shown below:

It’s important to note that if a NEL custom node is used, the corresponding plugin also needs to be provided by NEL. The Restore plugin and the RecordToMongo plugin need to be placed in the NEL_Plugins directory. The rest are placed in the Plugins directory.

0x03 Download the fast synced packet

Download address: http://nel-acc.oss-cn-hangzhou.aliyuncs.com/release.0-2400000.zip

Place the downloaded data packet in the directory where neo-cli.dll is located, as shown below:

Click startUp.bat to start the node, you can see the following:

Waiting for a while until the next picture appears, the data has been restored, and the node has started to get the rest of the data from the blockchain.