From ab94bf07b3832eda0b70947763e6bf1fa5674d88 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 8 Jun 2016 12:21:31 -0700 Subject: [PATCH] pool: minor. --- lib/bcoin/pool.js | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index da5a86a6..e6fb9b4c 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -129,7 +129,7 @@ function Pool(options) { this.syncing = false; this.synced = false; this._scheduled = false; - this._pendingWatch = false; + this._pendingWatch = null; this.load = { timeout: options.loadTimeout || 120000, @@ -888,7 +888,8 @@ Pool.prototype._createPeer = function _createPeer(options) { network: options.network, spv: options.spv, witness: options.witness, - headers: this.options.headers + headers: this.options.headers, + ts: options.ts }); peer.on('error', function(err) { @@ -1045,7 +1046,7 @@ Pool.prototype._handleTX = function _handleTX(tx, peer, callback) { // Fulfill the load request. requested = this.fulfill(tx); - if (!requested && tx.ts === 0) { + if (!requested) { peer.invFilter.add(tx.hash()); if (!this.mempool) @@ -1062,17 +1063,12 @@ Pool.prototype._handleTX = function _handleTX(tx, peer, callback) { } } - function addMempool(tx, callback) { - if (!self.mempool) - return utils.nextTick(callback); - - if (tx.ts !== 0) - return utils.nextTick(callback); - - self.mempool.addTX(tx, callback); + if (!self.mempool) { + self.emit('tx', tx, peer); + return callback(); } - addMempool(tx, function(err) { + self.mempool.addTX(tx, function(err) { if (err) { if (err.type === 'VerifyError') { if (err.score !== -1) @@ -1256,13 +1252,11 @@ Pool.prototype.updateWatch = function updateWatch() { var self = this; var i; - if (this._pendingWatch) + if (this._pendingWatch != null) return; - this._pendingWatch = true; - - setTimeout(function() { - self._pendingWatch = false; + this._pendingWatch = setTimeout(function() { + self._pendingWatch = null; if (self.peers.load) self.peers.load.updateWatch(); @@ -1681,7 +1675,7 @@ Pool.prototype.fillCoins = function fillCoins(tx, callback) { Pool.prototype.getLoaderHost = function getLoaderHost() { var host; - if (!this.connected) + if (!this.connected && process.env.BCOIN_SEED) return this.seeds[0]; host = this.getRandom(this.seeds);