- Blockchain By Example
- Bellaj Badr Richard Horrocks Xun (Brian) Wu
- 153字
- 2021-06-10 18:53:49
Syncing databases with the blockchain
To sync the explorer's local database with the blockchain information, a dedicated script, sync.js (located in scripts/), is available. This script must be called from the explorer's root directory as follows:
node scripts/sync.js index [mode]
For the mode option, you can choose one of the following modes:
- update: Updates the index from the last sync to the current block
- check: Checks the index for (and adds) any missing transactions/addresses
- reindex: Clears the index and then resyncs from genesis to the current block
As indicated in the official documentation, it's recommended to have this script launched via a cronjob at 2+ minute intervals. For example, to update the index every minute and market data every two minutes, use the following:
*/1 * * * * cd /path/to/explorer && /usr/bin/nodejs scripts/sync.js index update > /dev/null 2>&1
*/5 * * * * cd /path/to/explorer && /usr/bin/nodejs scripts/peers.js > /dev/null 2>&1