diff --git a/server/index.js b/server/index.js index 00ec06c..5e164fb 100644 --- a/server/index.js +++ b/server/index.js @@ -12,9 +12,12 @@ db.connect(config.mongodb.uri, config.mongodb.options); db.connection.once('open', () => { // DB Audit returns best height to node - db.blocks.findMissingBlocks((err, lastBestHeight) => { + db.blocks.findMissingBlocks((err, bestBlockHeight) => { // Pass height to node to start Sync - if (config.start_node) Bcoin.start(lastBestHeight); + logger.log('debug', + `Starting Bcoin from best height: ${bestBlockHeight}`); + + if (config.start_node) Bcoin.start(bestBlockHeight); Api.listen(config.api.port, () => { logger.log('debug', diff --git a/server/lib/db/blocks.js b/server/lib/db/blocks.js index 547319b..78eba2f 100644 --- a/server/lib/db/blocks.js +++ b/server/lib/db/blocks.js @@ -50,12 +50,11 @@ function findMissingBlocks(cb) { // Blocks are in ascending order let lastGoodHeight = 0; blocks.forEach((block) => { - if (lastGoodHeight !== block.height - 1) { - return lastGoodHeight; + if (lastGoodHeight === block.height - 1) { + lastGoodHeight = block.height; } - lastGoodHeight = block.height; }); - return lastGoodHeight; + return cb(null, lastGoodHeight); }); } diff --git a/server/lib/node/index.js b/server/lib/node/index.js index ee4171a..a3b4b00 100644 --- a/server/lib/node/index.js +++ b/server/lib/node/index.js @@ -14,7 +14,7 @@ function start(bestBlockHeight) { .then(() => { node.connect() .then(() => { - node.reset(bestBlockHeight); + node.chain.reset(bestBlockHeight); node.startSync(); }); });