This laboratory aim is to recover the blockchain state from a snapshot. The student will learn to set up a snapshot and take it as reference to run a blockchain either to restart due to a failure or to start a new node.
Edit the config.ini
file created in Run a Local Producer Node laboratory by adding the producer_api_plugin
plugin. Later create the snapshot and replay nodeos
from it.
This laboratory assumes the project is running in your local machine
The student must send:
- The
nodeos.log
file created in the stepFinally, run nodeos
.
To help you complete this tutorial, you can take a look at the following resource:
To successfully complete this laboratory, please, make sure you have the following requirements:
- Install the EOSIO software. It is assumed that
nodeos
,cleos
, andkeosd
are accessible through the execution PATH. - Complete the producer node lab.
Copy the Run a Local Producer Node
laboratory you have already completed and add the producer_api_plugin
plugin in the config.ini
file. Once it is done, run again the nodeos as you did in the producer node laboratory.
The final config.ini
file is:
enable-stale-production = true
producer-name = eosio
plugin = eosio::producer_plugin
# New plugin to create snapshots
plugin = eosio::producer_api_plugin
To restore a stoped node or start a new one, first you need a snapshot. To do so, run:
- Open your terminal.
- Paste next command
curl -X POST http://127.0.0.1:8888/v1/producer/create_snapshot
into the terminal.
By default, snapshots are written to the data/snapshots directory relative to your nodeos data directory.
The resulting snapshot file would be similar to snapshot-0000006105c35d011d0ee0a17f7d30893ee58c3ba5f4be15fd864b5c83ceabfe.bin
. Make sure you remember this path, it is going to be needed in the following step.
For this laboratory, we are going to replay from an empty folder, follow next steps to successfully replay nodeos from a snapshot.
- Run the following command to create the working folder.
mkdir ~/recovery-lab
- Copy the snapshot you created in step two to the working directory.
cp <SNAPSHOT_NAME>.bin ~/recovery-lab
- Create the following variables in your terminal:
SNAPSHOT=latest.bin
CONFIG_DIR=./config
DATA_DIR=./blockchain
- Rename the snapshot file for simplicity:
cd ~/recovery-lab
mv <SNAPSHOT_NAME>.bin latest.bin
In case you set a different name than
latest.bin
for the snapshot file, make sure to update the value forSNAPSHOT
variable to the new name.
- Create the snapshot folder.
cd ~/recovery-lab
mkdir -p $DATA_DIR/snapshots
- Copy the snapshot file located in your working directory to the snapshots directory.
cd ~/recovery-lab
cp latest.bin $DATA_DIR/snapshots/
- Create the
config
folder.
mkdir ~/recovery-lab/$CONFIG_DIR
- Copy the latest version of the
config.ini
file you modified in the step one and paste it into theconfig
folder.
cd ~/recovery-lab
cp <MODIFIED_CONFIG_INI_FILE> $CONFIG_DIR
- Finally, run nodeos.
nodeos \
--config-dir ./config \
--data-dir $DATA_DIR/ \
--blocks-dir $DATA_DIR/blocks \
--snapshot $DATA_DIR/snapshots/$SNAPSHOT \
>> nodeos.log 2>&1 &
To check if the replay was successfully, run:
tail -f nodeos.log
You should get an output like:
info 2022-01-06T05:48:52.464 thread-0 http_plugin.cpp:877 operator() ] start listening for http requests
info 2022-01-06T05:48:52.466 thread-0 http_plugin.cpp:983 add_handler ] add api url: /v1/node/get_supported_apis
info 2022-01-06T05:48:52.470 thread-0 producer_plugin.cpp:2333 produce_block ] Produced block 6b74690bf476c0c6... #362 @ 2022-01-06T05:48:52.500 signed by eosio [trxs: 0, lib: 361, confirmed: 0]
info 2022-01-06T05:48:52.907 thread-0 producer_plugin.cpp:2333 produce_block ] Produced block 5e074e7221533e71... #363 @ 2022-01-06T05:48:53.000 signed by eosio [trxs: 0, lib: 362, confirmed: 0]
info 2022-01-06T05:48:53.302 thread-0 producer_plugin.cpp:2333 produce_block ] Produced block f7b67b9dfc98422a... #364 @ 2022-01-06T05:48:53.500 signed by eosio [trxs: 0, lib: 363, confirmed: 0]
info 2022-01-06T05:48:53.902 thread-0 producer_plugin.cpp:2333 produce_block ] Produced block 5d87d585b72718ed... #365 @ 2022-01-06T05:48:54.000 signed by eosio [trxs: 0, lib: 364, confirmed: 0]
info 2022-01-06T05:48:54.402 thread-0 producer_plugin.cpp:2333 produce_block ] Produced block d2ff4ced2b7c1593... #366 @ 2022-01-06T05:48:54.500 signed by eosio [trxs: 0, lib: 365, confirmed: 0]
The starting producing blockchain number should be different to 0, for this example, the starting block is
#362
. You can validate it in the lineinfo 2022-01-06T05:48:52.470 thread-0 producer_plugin.cpp:2333 produce_block ] Produced block 6b74690bf476c0c6... #362 @ 2022-01-06T05:48:52.500 signed by eosio [trxs: 0, lib: 361, confirmed: 0]
.