diff --git a/lib/HistoricSync.js b/lib/HistoricSync.js index 74e8501..3ab8f60 100644 --- a/lib/HistoricSync.js +++ b/lib/HistoricSync.js @@ -320,9 +320,15 @@ function spec() { isMainChain = blockInfo.hash === nextHash; - //TODO blockInfo.isOrphan = !isMainChain; + /* + * In file sync, orphan blocks are just ignored. + * This is to simplify our schema and the + * sync process + */ + if (blockInfo.isOrphan) return c(); + self.sync.storeBlock(blockInfo, function(err) { existed = err && err.toString().match(/E11000/); @@ -340,19 +346,23 @@ function spec() { return cb(err); } else { - self.err = null; - self.status = 'syncing'; - } - // Continue - if (blockInfo) { + // Continue + if (blockInfo) { - // mainchain - if (isMainChain) height++; + // mainchain + if (isMainChain) height++; - self.syncedBlocks++; + self.syncedBlocks++; + self.err = null; + self.status = 'syncing'; - return self.getBlockFromFile(height, scanOpts, cb); + return self.getBlockFromFile(height, scanOpts, cb); + } + else { + self.err = null; + self.status = 'finished'; + } } return cb(err); });