diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index b5f4c742..d67b42f9 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -272,8 +272,8 @@ Pool.prototype._addPeer = function _addPeer() { }); peer.on('merkleblock', function(block) { - self.chain.add(block); self._response(block); + self.chain.add(block); self.emit('block', block); }); @@ -439,6 +439,9 @@ Pool.prototype._request = function _request(type, hash, options, cb) { if (has) return; + if (self.destroyed) + return; + var req = new LoadRequest(self, type, hex, cb); req.add(options.noQueue); } @@ -600,15 +603,15 @@ Pool.prototype.destroy = function destroy() { if (this.peers.load) this.peers.load.destroy(); + this.request.queue.slice().forEach(function(item) { + item.finish(null); + }); this.peers.pending.slice().forEach(function(peer) { peer.destroy(); }); this.peers.block.slice().forEach(function(peer) { peer.destroy(); }); - this.request.queue.slice().forEach(function(item) { - item.finish(null); - }); }; Pool.prototype.toJSON = function toJSON() { diff --git a/lib/bcoin/tx-pool.js b/lib/bcoin/tx-pool.js index f5a208a5..f54d7e93 100644 --- a/lib/bcoin/tx-pool.js +++ b/lib/bcoin/tx-pool.js @@ -51,10 +51,9 @@ TXPool.prototype.add = function add(tx, noWrite) { // Do not add TX two times if (this._all[hash]) { // Transaction was confirmed, update it in storage - if (tx.ts !== 0 && this._all[hash].ts === 0) { + if (this._storage && tx.ts !== 0 && this._all[hash].ts === 0) { this._all[hash].ts = tx.ts; - if (this._storage) - this._storeTX(hash, tx); + this._storeTX(hash, tx); } return false; }