From f5d8891317e5a4a14b62bb4704afce856eea827a Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 18 Feb 2014 14:01:18 -0300 Subject: [PATCH 1/2] failover to RPC sync if File sync fails --- app/controllers/socket.js | 4 ++++ insight.js | 4 +++- lib/HistoricSync.js | 6 ++++++ lib/Sync.js | 1 + util/sync.js | 4 +++- 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/controllers/socket.js b/app/controllers/socket.js index 825713b3..cdf41cfe 100644 --- a/app/controllers/socket.js +++ b/app/controllers/socket.js @@ -19,6 +19,8 @@ module.exports.broadcastTx = function(tx) { if (ios) { var t = {}; if (typeof tx === 'string') { + +console.log('[socket.js.22]',tx); //TODO t = { txid: tx }; @@ -31,6 +33,8 @@ module.exports.broadcastTx = function(tx) { }); t.valueOut = parseInt(valueOut) / util.COIN; + +console.log('[socket.js.36]',t); //TODO } ios.sockets. in ('inv').emit('tx', t); } diff --git a/insight.js b/insight.js index 0cf64a02..d4c2891d 100644 --- a/insight.js +++ b/insight.js @@ -53,7 +53,9 @@ if (!config.disableP2pSync) { /** * historic_sync process */ -var historicSync = new HistoricSync({ shouldBroadcastSync: true }); +var historicSync = new HistoricSync({ + shouldBroadcastSync: true +}); peerSync.historicSync = historicSync; if (!config.disableHistoricSync) { diff --git a/lib/HistoricSync.js b/lib/HistoricSync.js index 27383def..f29e77bc 100644 --- a/lib/HistoricSync.js +++ b/lib/HistoricSync.js @@ -264,7 +264,12 @@ function spec() { self.connectedCountDB > self.blockChainHeight * 0.9) return next(); + try { self.blockExtractor = new BlockExtractor(config.bitcoind.dataDir, config.network); + } catch (e) { + p(e.message + '. Disabling file sync.'); + return next(); + } self.getFn = self.getBlockFromFile; self.allowReorgs = true; @@ -407,6 +412,7 @@ function spec() { else { self.endTs = Date.now(); self.status = 'finished'; + console.log('Done Syncing', self.info()); return w_cb(err); } }); diff --git a/lib/Sync.js b/lib/Sync.js index a712304d..06954853 100644 --- a/lib/Sync.js +++ b/lib/Sync.js @@ -265,6 +265,7 @@ function spec() { Sync.prototype.handleNewTx = function(data) { if (this.opts.shouldBroadcast) { +console.log('[Sync.js.268:shouldBroadcast:]', data.tx); //TODO sockets.broadcastTx(data.tx); } }; diff --git a/util/sync.js b/util/sync.js index 05087ba3..ee29e65a 100755 --- a/util/sync.js +++ b/util/sync.js @@ -18,7 +18,9 @@ program .option('-v --verbose', 'Verbose 0/1', 0) .parse(process.argv); -var historicSync = new HistoricSync(); +var historicSync = new HistoricSync({ + shouldBroadcastSync: true, +}); async.series([ From 1e4a6179defb79fc918367b31283a341e69ecc74 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 18 Feb 2014 14:51:45 -0300 Subject: [PATCH 2/2] fix tx broadcast --- app/controllers/socket.js | 17 +++++++++-------- lib/Sync.js | 1 - 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/socket.js b/app/controllers/socket.js index cdf41cfe..9a11f5b5 100644 --- a/app/controllers/socket.js +++ b/app/controllers/socket.js @@ -17,24 +17,25 @@ module.exports.init = function(app, io_ext) { module.exports.broadcastTx = function(tx) { if (ios) { - var t = {}; + var t; if (typeof tx === 'string') { - -console.log('[socket.js.22]',tx); //TODO t = { txid: tx }; - } else { - t = tx; + } + + else { + t = { + txid: tx.txid, + size: tx.size, + }; // Outputs var valueOut = 0; - t.vout.forEach(function(o) { + tx.vout.forEach(function(o) { valueOut += o.value * util.COIN; }); t.valueOut = parseInt(valueOut) / util.COIN; - -console.log('[socket.js.36]',t); //TODO } ios.sockets. in ('inv').emit('tx', t); } diff --git a/lib/Sync.js b/lib/Sync.js index 06954853..a712304d 100644 --- a/lib/Sync.js +++ b/lib/Sync.js @@ -265,7 +265,6 @@ function spec() { Sync.prototype.handleNewTx = function(data) { if (this.opts.shouldBroadcast) { -console.log('[Sync.js.268:shouldBroadcast:]', data.tx); //TODO sockets.broadcastTx(data.tx); } };