wip
This commit is contained in:
parent
735810919a
commit
cd4cbe3fb7
@ -679,82 +679,12 @@ DB.prototype.getConcurrentTipOperation = function(block, add) {
|
||||
tipData = Buffer.concat([BufferUtil.reverse(block.header.prevHash), heightBuffer]);
|
||||
}
|
||||
|
||||
<<<<<<< HEAD:lib/services/db.js
|
||||
self.bitcoindSyncing = true;
|
||||
|
||||
var height;
|
||||
|
||||
async.whilst(function() {
|
||||
height = self.tip.__height;
|
||||
return height < self.node.services.bitcoind.height && !self.node.stopping;
|
||||
}, function(done) {
|
||||
log.debug('fetching block ' + (height + 1));
|
||||
self.node.services.bitcoind.getBlock(height + 1, function(err, block) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
// TODO: expose prevHash as a string from bitcore
|
||||
var prevHash = BufferUtil.reverse(block.header.prevHash).toString('hex');
|
||||
|
||||
if (prevHash === self.tip.hash) {
|
||||
|
||||
// This block appends to the current chain tip and we can
|
||||
// immediately add it to the chain and create indexes.
|
||||
|
||||
// Populate height
|
||||
block.__height = self.tip.__height + 1;
|
||||
|
||||
// Create indexes
|
||||
self.connectBlock(block, function(err) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
self.tip = block;
|
||||
log.debug('Chain added block to main chain');
|
||||
self.emit('addblock', block);
|
||||
setImmediate(done);
|
||||
});
|
||||
} else {
|
||||
// This block doesn't progress the current tip, so we'll attempt
|
||||
// to rewind the chain to the common ancestor of the block and
|
||||
// then we can resume syncing.
|
||||
log.warn('Beginning reorg! Current tip: ' + self.tip.hash + '; New tip: ' + block.hash);
|
||||
self.syncRewind(block, function(err) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
log.warn('Reorg complete. New tip is ' + self.tip.hash);
|
||||
done();
|
||||
});
|
||||
}
|
||||
});
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
Error.captureStackTrace(err);
|
||||
return self.node.emit('error', err);
|
||||
}
|
||||
|
||||
if(self.node.stopping) {
|
||||
self.bitcoindSyncing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.node.services.bitcoind.isSynced()) {
|
||||
self.bitcoindSyncing = false;
|
||||
self.node.emit('synced');
|
||||
} else {
|
||||
self.bitcoindSyncing = false;
|
||||
}
|
||||
=======
|
||||
return {
|
||||
type: 'put',
|
||||
key: this.dbPrefix + 'concurrentTip',
|
||||
value: tipData
|
||||
};
|
||||
};
|
||||
>>>>>>> feature/concurrency:lib/services/db/index.js
|
||||
|
||||
|
||||
|
||||
|
||||
@ -60,8 +60,8 @@ Sync.prototype.sync = function() {
|
||||
}
|
||||
|
||||
this.syncing = true;
|
||||
this.blockStream = new BlockStream();
|
||||
var processBoth = new ProcessBoth(this.db);
|
||||
this.blockStream = new BlockStream(this.highWaterMark, this.node.services.bitcoind, this.db.tip.__height);
|
||||
var processBoth = new ProcessBoth(this.highWaterMark, this.db);
|
||||
|
||||
this._handleErrors(this.blockStream);
|
||||
this._handleErrors(processBoth);
|
||||
@ -72,8 +72,7 @@ Sync.prototype.sync = function() {
|
||||
});
|
||||
|
||||
this.blockStream
|
||||
.pipe(processBoth)
|
||||
.pipe(writeStream1);
|
||||
.pipe(processBoth);
|
||||
};
|
||||
|
||||
Sync.prototype.stop = function() {
|
||||
@ -222,7 +221,7 @@ BlockStream.prototype._process = function() {
|
||||
self.processing = false;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
function ProcessSerial(highWaterMark, db, tip) {
|
||||
Writable.call(this, {objectMode: true, highWaterMark: highWaterMark});
|
||||
@ -386,7 +385,7 @@ var ProcessBoth = function(highWaterMark, db) {
|
||||
inherits(ProcessBoth, Writable);
|
||||
|
||||
ProcessBoth.prototype._write = function(block, encoding, callback) {
|
||||
|
||||
var self = this;
|
||||
async.parallel([function(next) {
|
||||
self.db.getConcurrentBlockOperations(block, true, function(err, operations) {
|
||||
if(err) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user