From 4700990bcd08858f7956e17700441fa1812f41ac Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 9 May 2016 00:56:44 -0700 Subject: [PATCH] mempool locker hasPending. --- lib/bcoin/mempool.js | 8 ++++++-- lib/bcoin/pool.js | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/bcoin/mempool.js b/lib/bcoin/mempool.js index 134e83cf..743d3cc1 100644 --- a/lib/bcoin/mempool.js +++ b/lib/bcoin/mempool.js @@ -71,7 +71,7 @@ function Mempool(options) { this.loaded = false; - this.locker = new bcoin.locker(this, this.addTX, 20 << 20); + this.locker = new bcoin.locker(this, this.addTX, 100 << 20); this.writeLock = new bcoin.locker(this); this.db = null; @@ -510,8 +510,12 @@ Mempool.prototype.hasTX = function hasTX(hash, callback) { * @param {Function} callback - Returns [Error, Boolean]. */ -Mempool.prototype.hasAny = function hasAny(hash, callback) { +Mempool.prototype.has = function has(hash, callback) { var self = this; + + if (this.locker.hasPending(hash)) + return utils.asyncify(callback)(null, true); + return this.hasTX(hash, function(err, exists) { if (err) return callback(err); diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index 1ca08ca9..36e90091 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -1642,7 +1642,7 @@ Pool.prototype.getData = function getData(peer, type, hash, options, callback) { if (type === this.tx.type) { if (!this.mempool) return utils.asyncify(done)(null, false); - return this.mempool.hasAny(hash, done); + return this.mempool.has(hash, done); } return this.chain.has(hash, done);