This commit is contained in:
Patrick Nagurny 2017-01-27 14:49:03 -05:00
parent c5875332d4
commit fae38b1ee8

View File

@ -259,27 +259,34 @@ ProcessSerial.prototype._transform = function(block, enc, callback) {
return callback(err); return callback(err);
} }
async.whilst( if(check) {
function() { return self._process(block, callback);
}
var processed = false;
self.db.on('addblock', function() {
if(!processed) {
processed = true;
return self._process(block, callback);
}
});
self.db.on('concurrentblock', function() {
if(!processed) {
processed = true;
return self._process(block, callback);
}
});
function check() {
return self.db.concurrentTip.__height < block.__height || self.db.tip.__height < block.__height - 1; return self.db.concurrentTip.__height < block.__height || self.db.tip.__height < block.__height - 1;
},
function(next) {
var nextCalled = false;
// wait until concurrent handler is ahead of us
self.db.once('addblock', function() {
if(!nextCalled) {
next();
} }
nextCalled = true; };
});
self.db.once('concurrentaddblock', function() { ProcessSerial.prototype._process = function(block, callback) {
if(!nextCalled) { var self = this;
next();
}
nextCalled = true;
});
},
function() {
self.db.getSerialBlockOperations(block, true, function(err, operations) { self.db.getSerialBlockOperations(block, true, function(err, operations) {
if(err) { if(err) {
return callback(err); return callback(err);
@ -296,8 +303,6 @@ ProcessSerial.prototype._transform = function(block, enc, callback) {
callback(null, obj); callback(null, obj);
}); });
}
);
}; };
function ProcessConcurrent(highWaterMark, db) { function ProcessConcurrent(highWaterMark, db) {