From 3d6fc2923b392a4d37d977a36ed8fc2c7c721758 Mon Sep 17 00:00:00 2001 From: joeuhren Date: Tue, 1 Oct 2019 21:25:47 -0600 Subject: [PATCH] start from actual last known block height when updating index --- scripts/sync.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/sync.js b/scripts/sync.js index 6b558f0..9b1d821 100644 --- a/scripts/sync.js +++ b/scripts/sync.js @@ -176,12 +176,21 @@ is_locked(function (exists) { }); }); } else if (mode == 'update') { - db.update_tx_db(settings.coin, stats.last, stats.count, settings.update_timeout, function(){ - db.update_richlist('received', function(){ - db.update_richlist('balance', function(){ - db.get_stats(settings.coin, function(nstats){ - console.log('update complete (block: %s)', nstats.last); - exit(); + // Lookup the last block index + Tx.findOne({}, {blockindex:1}).sort({blockindex:-1}).limit(1).exec(function(err, data){ + var nLast = stats.last; + if (!err && data) { + // start from the last block index + nLast = data.blockindex; + } + + db.update_tx_db(settings.coin, nLast, stats.count, settings.update_timeout, function(){ + db.update_richlist('received', function(){ + db.update_richlist('balance', function(){ + db.get_stats(settings.coin, function(nstats){ + console.log('update complete (block: %s)', nstats.last); + exit(); + }); }); }); });