From cd05484ba5ff12309caa5eeb6aba905f0fa63fde Mon Sep 17 00:00:00 2001 From: Joe Uhren Date: Sat, 19 Mar 2022 18:44:36 -0600 Subject: [PATCH] Reindex tweaks and improvements -Added an "Are you sure" prompt before starting the reindex to make it clear that this is a destructive sync option -All necessary coin stat data is cleared before starting the resync (txes, blockchain_last_updated and richlist_last_updated were not previously being cleared) -More and better messages about what is being done during the process -Shifted some of the code around to be run in a better order (for example, blockchain_last_updated date is set right after finishing the blockchain sync instead of at the very end of the reindex) --- scripts/sync.js | 52 ++++++++++++++++++++++++++++++------------------- scripts/sync.sh | 13 +++++++++++++ 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/scripts/sync.js b/scripts/sync.js index ea52a98..3fcbc9e 100644 --- a/scripts/sync.js +++ b/scripts/sync.js @@ -296,42 +296,54 @@ if (database == 'peers') { if (settings.blockchain_specific.heavycoin.enabled == true) db.update_heavy(settings.coin.name, stats.count, 20, function() {}); if (mode == 'reindex') { + console.log('deleting transactions.. please wait..'); Tx.deleteMany({}, function(err) { - console.log('TXs cleared.'); + console.log('transactions deleted successfully'); + console.log('deleting addresses.. please wait..'); Address.deleteMany({}, function(err2) { - console.log('Addresses cleared.'); + console.log('addresses deleted successfully'); + console.log('deleting address transactions.. please wait..'); AddressTx.deleteMany({}, function(err3) { - console.log('Address TXs cleared.'); + console.log('address transactions deleted successfully'); + console.log('deleting top 100 data.. please wait..'); Richlist.updateOne({coin: settings.coin.name}, { received: [], balance: [] }, function(err3) { + console.log('top 100 data deleted successfully'); + + console.log('deleting block index.. please wait..'); Stats.updateOne({coin: settings.coin.name}, { last: 0, count: 0, - supply: 0 + supply: 0, + txes: 0, + blockchain_last_updated: 0, + richlist_last_updated: 0 }, function() { - console.log('index cleared (reindex)'); - }); + console.log('block index deleted successfully'); - // Check if the sync msg should be shown - check_show_sync_message(stats.count); + // Check if the sync msg should be shown + check_show_sync_message(stats.count); - 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) { - // always check for and remove the sync msg if exists - remove_sync_message(); - // update richlist_last_updated value - db.update_last_updated_stats(settings.coin.name, { richlist_last_updated: Math.floor(new Date() / 1000) }, function (cb) { - // update blockchain_last_updated value - db.update_last_updated_stats(settings.coin.name, { blockchain_last_updated: Math.floor(new Date() / 1000) }, function (cb) { - console.log('reindex complete (block: %s)', nstats.last); - exit(); + console.log('starting resync of blockchain data.. please wait..'); + db.update_tx_db(settings.coin.name, block_start, stats.count, stats.txes, settings.sync.update_timeout, false, function() { + // update blockchain_last_updated value + db.update_last_updated_stats(settings.coin.name, { blockchain_last_updated: Math.floor(new Date() / 1000) }, function (cb) { + db.update_richlist('received', function() { + db.update_richlist('balance', function() { + // update richlist_last_updated value + db.update_last_updated_stats(settings.coin.name, { richlist_last_updated: Math.floor(new Date() / 1000) }, function (cb) { + db.get_stats(settings.coin.name, function(nstats) { + // always check for and remove the sync msg if exists + remove_sync_message(); + + console.log('reindex complete (block: %s)', nstats.last); + exit(); + }); }); }); }); diff --git a/scripts/sync.sh b/scripts/sync.sh index 37081f9..988d59b 100755 --- a/scripts/sync.sh +++ b/scripts/sync.sh @@ -120,6 +120,19 @@ if [ -n "${MODE}" ]; then # Check if the desired mode requires a lock if [ "${MODE}" != "peers" ] && [ "${MODE}" != "masternodes" ]; then # A lock is required + # Check if this is a reindex + if [ "${MODE}" = "index reindex" ]; then + # Prompt for the reindex + echo "You are about to delete all blockchain data (transactions and addresses)" + echo "and resync from the genesis block." + echo "Are you sure you want to do this? [y/n]: "; + read -p "" REINDEX_ANSWER + # Determine if the reindex should proceed + case "$REINDEX_ANSWER" in + y|Y|yes|Yes|YES) ;; + *) echo "Process aborted. Nothing was deleted." && exit ;; + esac + fi # Check if the script is already running (tmp/index.pid file already exists) if [ -f "${EXPLORER_PATH}/tmp/index.pid" ]; then # The tmp/index.pid file exists. Check if the process is actually still running