quick hack to handle blocks that arrive at the sametime

This commit is contained in:
Matias Alejo Garcia 2014-06-02 20:09:48 -03:00
parent a46715d649
commit a8ecdc7453

View File

@ -83,8 +83,18 @@ Sync.prototype.storeTipBlock = function(b, allowReorgs, cb) {
allowReorgs = true;
}
if (!b) return cb();
var self = this;
if ( self.storingBlock ) {
console.log('## Storing a block already. Delaying storeTipBlock with:' +
b.hash);
return setTimeout( function() {
console.log('## Retrying storeTipBlock with: ' + b.hash);
self.storeTipBlock(b,allowReorgs,cb);
}, 1000);
}
self.storingBlock=1;
var oldTip, oldNext, oldHeight, needReorg = false, height = -1;
var newPrev = b.previousblockhash;
@ -164,6 +174,7 @@ Sync.prototype.storeTipBlock = function(b, allowReorgs, cb) {
if (err && err.toString().match(/WARN/)) {
err = null;
}
self.storingBlock=0;
return cb(err, height);
});
};
@ -177,7 +188,10 @@ Sync.prototype.processReorg = function(oldTip, oldNext, newPrev, oldHeight, cb)
function(c) {
self.bDb.getHeight(newPrev, function(err, height) {
if (!height) return c(new Error('Could not found block:' + newPrev));
if (!height) {
// Case 3 + allowReorgs = true
return c(new Error('Could not found block:' + newPrev));
}
if (height<0) return c();
newHeight = height + 1;