Merge pull request #301 from matiaspando/bug/bitcoindVersion
Checking Bitcoin Core version
This commit is contained in:
commit
1263ab0148
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
# *insight API*
|
# *insight API*
|
||||||
|
|
||||||
*insight API* is an open-source bitcoin blockchain REST
|
*insight API* is an open-source bitcoin blockchain REST
|
||||||
@ -12,6 +13,10 @@ require certain information from the blockchain that bitcoind does not provide.
|
|||||||
A blockchain explorer front-end has been developed on top of *Insight API*. It can
|
A blockchain explorer front-end has been developed on top of *Insight API*. It can
|
||||||
be downloaded at [Github Insight Repository](https://github.com/bitpay/insight).
|
be downloaded at [Github Insight Repository](https://github.com/bitpay/insight).
|
||||||
|
|
||||||
|
## Warning
|
||||||
|
Insight file sync does not work with **bitcoind** v0.10
|
||||||
|
In order to use Insigtht you must set the environment variable INSIGHT_FORCE_RPC_SYNC = 1
|
||||||
|
We are working on `bitcore-node` to replace Insight-api. Check `bitcore-node` on [github](https://github.com/bitpay/bitcore-node).
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
@ -32,6 +37,7 @@ bitcoind must be running and must have finished downloading the blockchain **bef
|
|||||||
|
|
||||||
* **NPM** - Node.js package manager, should be automatically installed when you get node.js.
|
* **NPM** - Node.js package manager, should be automatically installed when you get node.js.
|
||||||
|
|
||||||
|
|
||||||
## Quick Install
|
## Quick Install
|
||||||
Check the Prerequisites section above before installing.
|
Check the Prerequisites section above before installing.
|
||||||
|
|
||||||
|
|||||||
@ -50,6 +50,7 @@ switch (process.env.NODE_ENV) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var network = process.env.INSIGHT_NETWORK || 'testnet';
|
var network = process.env.INSIGHT_NETWORK || 'testnet';
|
||||||
|
var forceRPCsync = process.env.INSIGHT_FORCE_RPC_SYNC;
|
||||||
|
|
||||||
var dataDir = process.env.BITCOIND_DATADIR;
|
var dataDir = process.env.BITCOIND_DATADIR;
|
||||||
var isWin = /^win/.test(process.platform);
|
var isWin = /^win/.test(process.platform);
|
||||||
@ -133,4 +134,5 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
safeConfirmations: safeConfirmations, // PLEASE NOTE THAT *FULL RESYNC* IS NEEDED TO CHANGE safeConfirmations
|
safeConfirmations: safeConfirmations, // PLEASE NOTE THAT *FULL RESYNC* IS NEEDED TO CHANGE safeConfirmations
|
||||||
ignoreCache: ignoreCache,
|
ignoreCache: ignoreCache,
|
||||||
|
forceRPCsync: forceRPCsync,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -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,40 @@ 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);
|
||||||
|
|
||||||
|
this.getBitcoinCoreVersion(function(bitcoinVersion) {
|
||||||
|
if (bitcoinVersion > 100000 && !config.forceRPCsync) {
|
||||||
|
info('-------------------------------------------------------');
|
||||||
|
info('- Bitcoin Core version >0.10 only works with RPC sync -');
|
||||||
|
info('- Set the env variable INSIGHT_FORCE_RPC_SYNC = 1 -');
|
||||||
|
info('-------------------------------------------------------');
|
||||||
|
process.exit(1);
|
||||||
|
} else {
|
||||||
|
info('Bitcoin Core version ', bitcoinVersion);
|
||||||
|
info('Using RPC sync ');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
this.sync = new Sync(opts);
|
this.sync = new Sync(opts);
|
||||||
this.height = 0;
|
this.height = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HistoricSync.prototype.getBitcoinCoreVersion = function(cb) {
|
||||||
|
var self = this;
|
||||||
|
self.rpc.getInfo(function(err, info) {
|
||||||
|
if (err) {
|
||||||
|
error('ERROR ', err);
|
||||||
|
process.exit(-1);
|
||||||
|
};
|
||||||
|
return cb(info.result.version);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
HistoricSync.prototype.showProgress = function() {
|
HistoricSync.prototype.showProgress = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
@ -118,8 +146,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 +231,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 +261,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)
|
||||||
@ -260,6 +285,8 @@ HistoricSync.prototype.updateStartBlock = function(opts, next) {
|
|||||||
HistoricSync.prototype.prepareFileSync = function(opts, next) {
|
HistoricSync.prototype.prepareFileSync = function(opts, next) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
if (config.forceRPCsync) return next();
|
||||||
|
|
||||||
if (opts.forceRPC || !config.bitcoind.dataDir ||
|
if (opts.forceRPC || !config.bitcoind.dataDir ||
|
||||||
self.height > self.blockChainHeight * PERCENTAGE_TO_START_FROM_RPC) return next();
|
self.height > self.blockChainHeight * PERCENTAGE_TO_START_FROM_RPC) return next();
|
||||||
|
|
||||||
@ -324,8 +351,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 +392,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 +450,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();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user