From 02c3512f94b2086b5ef5a21a8f852f346924c8f5 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 1 Feb 2014 22:39:08 -0300 Subject: [PATCH] orphan blocks ignored on file sync --- lib/HistoricSync.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/HistoricSync.js b/lib/HistoricSync.js index 74e85014..3ab8f60d 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); });