Checking bitcoind version

This commit is contained in:
Matias Pando 2015-03-10 17:11:04 -03:00
parent d0fab56469
commit 94b6c3f9af

View File

@ -24,6 +24,7 @@ var PERCENTAGE_TO_START_FROM_RPC = 0.96;
var BAD_GEN_ERROR = 'Bad genesis block. Network mismatch between Insight and bitcoind? Insight is configured for:'; var BAD_GEN_ERROR = 'Bad genesis block. Network mismatch between Insight and bitcoind? Insight is configured for:';
var BAD_GEN_ERROR_DB = 'Bad genesis block. Network mismatch between Insight and levelDB? Insight is configured for:'; var BAD_GEN_ERROR_DB = 'Bad genesis block. Network mismatch between Insight and levelDB? Insight is configured for:';
function HistoricSync(opts) { function HistoricSync(opts) {
opts = opts || {}; opts = opts || {};
this.shouldBroadcast = opts.shouldBroadcastSync; this.shouldBroadcast = opts.shouldBroadcastSync;
@ -36,13 +37,33 @@ function HistoricSync(opts) {
this.genesis = genesisHashReversed.toString('hex'); this.genesis = genesisHashReversed.toString('hex');
var bitcore = require('bitcore'); var bitcore = require('bitcore');
var RpcClient = bitcore.RpcClient; var RpcClient = bitcore.RpcClient;
this.rpc = new RpcClient(config.bitcoind); this.rpc = new RpcClient(config.bitcoind);
if (this.checkBitcoinCoreVersion) {
console.log('-------------------------------------------------------');
console.log('- Bitcoin Core version is greater or equal than 10.99 -');
console.log('-------------------------------------------------------');
}
this.sync = new Sync(opts); this.sync = new Sync(opts);
this.height = 0; this.height = 0;
} }
HistoricSync.prototype.checkBitcoinCoreVersion = function() {
var self = this;
self.rpc.getInfo(function(err, info) {
if (err) {
console.log('ERROR ', err);
process.exit(-1);
};
return info.result.version >= 109900;
});
};
HistoricSync.prototype.showProgress = function() { HistoricSync.prototype.showProgress = function() {
var self = this; var self = this;
@ -118,8 +139,7 @@ HistoricSync.prototype.getBlockFromRPC = function(cb) {
self.network.genesisBlock.prev_hash.toString('hex'); self.network.genesisBlock.prev_hash.toString('hex');
self.currentRpcHash = blockInfo.nextblockhash; self.currentRpcHash = blockInfo.nextblockhash;
} } else {
else {
blockInfo = null; blockInfo = null;
} }
return cb(null, blockInfo); return cb(null, blockInfo);
@ -204,8 +224,7 @@ HistoricSync.prototype.updateStartBlock = function(opts, next) {
return next(err); return next(err);
} }
}); });
} } else {
else {
self.sync.bDb.getTip(function(err, tip, height) { self.sync.bDb.getTip(function(err, tip, height) {
if (!tip) return next(); if (!tip) return next();
@ -235,8 +254,7 @@ HistoricSync.prototype.updateStartBlock = function(opts, next) {
if (self.blockChainHeight === blockInfo.height || if (self.blockChainHeight === blockInfo.height ||
blockInfo.confirmations > 0) { blockInfo.confirmations > 0) {
ret = false; ret = false;
} } else {
else {
oldtip = tip; oldtip = tip;
if (!tip) if (!tip)
throw new Error('Previous blockchain tip was not found on bitcoind. Please reset Insight DB. Tip was:' + tip) throw new Error('Previous blockchain tip was not found on bitcoind. Please reset Insight DB. Tip was:' + tip)
@ -324,8 +342,7 @@ HistoricSync.prototype.showSyncStartMessage = function() {
if (self.blockExtractor) { if (self.blockExtractor) {
info('bitcoind dataDir configured...importing blocks from .dat files'); info('bitcoind dataDir configured...importing blocks from .dat files');
info('First file index: ' + self.blockExtractor.currentFileIndex); info('First file index: ' + self.blockExtractor.currentFileIndex);
} } else {
else {
info('syncing from RPC (slow)'); info('syncing from RPC (slow)');
} }
@ -366,6 +383,7 @@ HistoricSync.prototype.prepareToSync = function(opts, next) {
self.status = 'starting'; self.status = 'starting';
async.series([ async.series([
function(s_c) { function(s_c) {
self.checkDBVersion(s_c); self.checkDBVersion(s_c);
}, },
@ -423,8 +441,7 @@ HistoricSync.prototype.start = function(opts, next) {
return w_cb(err); return w_cb(err);
}); });
}); });
} } else {
else {
self.endTs = Date.now(); self.endTs = Date.now();
self.status = 'finished'; self.status = 'finished';
var info = self.info(); var info = self.info();