From 835a83283f1029b9339fa8aa5e971a84fcd7cde7 Mon Sep 17 00:00:00 2001 From: Joe Uhren Date: Sat, 19 Mar 2022 19:27:17 -0600 Subject: [PATCH] Fix and move heavycoin update -update_heavy has been moved into a proper callback function which is now only called for index and reindex syncs right near the end of the process instead of at the beginning --- scripts/sync.js | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/scripts/sync.js b/scripts/sync.js index 3fcbc9e..fce750f 100644 --- a/scripts/sync.js +++ b/scripts/sync.js @@ -293,8 +293,7 @@ if (database == 'peers') { db.update_db(settings.coin.name, function(stats) { // check if stats returned properly if (stats !== false) { - if (settings.blockchain_specific.heavycoin.enabled == true) - db.update_heavy(settings.coin.name, stats.count, 20, function() {}); + // determine which index mode to run if (mode == 'reindex') { console.log('deleting transactions.. please wait..'); Tx.deleteMany({}, function(err) { @@ -338,11 +337,14 @@ if (database == 'peers') { // 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(); + // check for and update heavycoin data if applicable + update_heavy(settings.coin.name, stats.count, 20, settings.blockchain_specific.heavycoin.enabled, function(heavy) { + // always check for and remove the sync msg if exists + remove_sync_message(); - console.log('reindex complete (block: %s)', nstats.last); - exit(); + console.log('reindex complete (block: %s)', nstats.last); + exit(); + }); }); }); }); @@ -375,14 +377,17 @@ if (database == 'peers') { 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('update complete (block: %s)', nstats.last); - exit(); + // check for and update heavycoin data if applicable + update_heavy(settings.coin.name, stats.count, 20, settings.blockchain_specific.heavycoin.enabled, function(heavy) { + // 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('update complete (block: %s)', nstats.last); + exit(); + }); }); }); }); @@ -565,6 +570,15 @@ if (database == 'peers') { }); } +function update_heavy(coin, height, count, heavycoin_enabled, cb) { + if (heavycoin_enabled == true) { + db.update_heavy(coin, height, count, function() { + return cb(true); + }); + } else + return cb(false); +} + function check_show_sync_message(blocks_to_sync) { var retVal = false; var filePath = './tmp/show_sync_message.tmp';