From f0908fd17691d8b53c727fb91c65bb49ea0484ce Mon Sep 17 00:00:00 2001 From: Joe Uhren Date: Sun, 21 Nov 2021 19:15:42 -0700 Subject: [PATCH] Add optional block_start parameter to check mode --- README.md | 3 ++- scripts/sync.js | 18 +++++++++++++++--- scripts/sync.sh | 12 ++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 29564be..fb85e5e 100644 --- a/README.md +++ b/README.md @@ -410,6 +410,7 @@ Usage: scripts/sync.sh /path/to/node [mode] Mode: (required) update Updates index from last sync to current block check Checks index for (and adds) any missing transactions/addresses + Optional parameter: block number to start checking from reindex Clears index then resyncs from genesis to current block reindex-rich Clears and recreates the richlist data reindex-txcount Rescan and flatten the tx count value for faster access @@ -438,7 +439,7 @@ A number of npm scripts are included with the explorer for easy syncing of the v A small handful of useful scripts are also included to assist in solving various issues you may experience with the explorer: -- `npm run check-blocks`: Recheck all previously synced blocks by comparing against the wallet daemon to look for and add any missing transactions/addresses. :warning: **WARNING:** This can take a very long time depending on the length of the blockchain and is generally not recommended unless absolutely necessary. Furthermore, while you are checking for missing data, you will be unable to sync new blocks into the explorer until the check command has finished. If you do find missing transactions with this check (other than new data since last sync), this likely means that `sync.update_timeout` in `settings.json` is set too low. +- `npm run check-blocks`: Recheck all previously synced blocks by comparing against the wallet daemon to look for and add any missing transactions/addresses. Optional parameter: block number to start checking from. Example: `npm run check-blocks 1000` will begin the check starting at block 1000. :warning: **WARNING:** This can take a very long time depending on the length of the blockchain and is generally not recommended unless absolutely necessary. Furthermore, while you are checking for missing data, you will be unable to sync new blocks into the explorer until the check command has finished. If you do find missing transactions with this check (other than new data since last sync), this likely means that `sync.update_timeout` in `settings.json` is set too low. - `npm run reindex`: Delete all blocks, transactions and addresses, and resync from genesis to current block. :warning: **WARNING:** This will wipe out all blockchain-related data from the explorer. It is recommended to [backup the explorer database](#backup-database-script) before continuing with this command. - `npm run reindex-rich`: Clears and recreates the richlist data for the top 100 coin holders page. Rarely needed, but can be useful for debugging or if you are certain the richlist data is incorrect for some reason. - `npm run reindex-txcount`: Recalculate the count of transactions stored in `stats.txes` by recounting the txes stored in the mongo database. Rarely needed, but can be useful for debugging or if you notice the main list of transactions is showing the wrong number of entries. If this value is off for some reason, you will not be able to page back to the 1st blocks on the main list of transactions for example. diff --git a/scripts/sync.js b/scripts/sync.js index 534bc9c..17aa151 100644 --- a/scripts/sync.js +++ b/scripts/sync.js @@ -9,6 +9,7 @@ var mongoose = require('mongoose'), settings = require('../lib/settings'); var mode = 'update'; var database = 'index'; +var block_start = 1; // displays usage and exits function usage() { @@ -17,6 +18,7 @@ function usage() { console.log('Mode: (required)'); console.log('update Updates index from last sync to current block'); console.log('check Checks index for (and adds) any missing transactions/addresses'); + console.log(' Optional parameter: block number to start checking from'); console.log('reindex Clears index then resyncs from genesis to current block'); console.log('reindex-rich Clears and recreates the richlist data'); console.log('reindex-txcount Rescan and flatten the tx count value for faster access'); @@ -39,12 +41,22 @@ if (process.argv[2] == 'index') { if (process.argv.length < 3) usage(); else { - switch(process.argv[3]) { + switch (process.argv[3]) { case 'update': mode = 'update'; break; case 'check': mode = 'check'; + + // check if the block start value was passed in and is an integer + if (!isNaN(process.argv[4]) && Number.isInteger(parseFloat(process.argv[4]))) { + // Check if the block start value is less than 1 + if (parseInt(process.argv[4]) < 1) + block_start = 1; + else + block_start = parseInt(process.argv[4]); + } + break; case 'reindex': mode = 'reindex'; @@ -308,7 +320,7 @@ if (database == 'peers') { // Check if the sync msg should be shown check_show_sync_message(stats.count); - db.update_tx_db(settings.coin.name, 1, stats.count, stats.txes, settings.sync.update_timeout, false, function() { + db.update_tx_db(settings.coin.name, block_start, stats.count, stats.txes, settings.sync.update_timeout, false, function() { db.update_richlist('received', function() { db.update_richlist('balance', function() { db.get_stats(settings.coin.name, function(nstats) { @@ -333,7 +345,7 @@ if (database == 'peers') { } else if (mode == 'check') { console.log('starting check.. please wait..'); - db.update_tx_db(settings.coin.name, 1, stats.count, stats.txes, settings.sync.check_timeout, true, function() { + db.update_tx_db(settings.coin.name, block_start, stats.count, stats.txes, settings.sync.check_timeout, true, function() { db.get_stats(settings.coin.name, function(nstats) { console.log('check complete (block: %s)', nstats.last); exit(); diff --git a/scripts/sync.sh b/scripts/sync.sh index d8c6407..37081f9 100755 --- a/scripts/sync.sh +++ b/scripts/sync.sh @@ -13,6 +13,12 @@ if [ -n "${1}" ]; then "check") # Index check MODE="index check" + + # Check if the next parameter exists + if [ -n "${2}" ]; then + # Add onto the check cmd + MODE="${MODE} ${2}" + fi ;; "reindex") # Index reindex @@ -63,6 +69,12 @@ if [ -n "${1}" ]; then "check") # Index check MODE="index check" + + # Check if the next parameter exists + if [ -n "${3}" ]; then + # Add onto the check cmd + MODE="${MODE} ${3}" + fi ;; "reindex") # Index reindex