Reset Bcoin chain if blocks are missing from mongo.
This commit is contained in:
parent
2ccaf2fce0
commit
333eec3dd8
@ -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',
|
||||
|
||||
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ function start(bestBlockHeight) {
|
||||
.then(() => {
|
||||
node.connect()
|
||||
.then(() => {
|
||||
node.reset(bestBlockHeight);
|
||||
node.chain.reset(bestBlockHeight);
|
||||
node.startSync();
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user