check orphan txs before requesting.

This commit is contained in:
Christopher Jeffrey 2016-05-06 14:10:01 -07:00
parent 3326078694
commit 1bf606a22d
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 24 additions and 5 deletions

View File

@ -504,6 +504,25 @@ Mempool.prototype.hasTX = function hasTX(hash, callback) {
return this.tx.hasTX(hash, callback);
};
/**
* Test the mempool to see if it contains a transaction or an orphan.
* @param {Hash} hash
* @param {Function} callback - Returns [Error, Boolean].
*/
Mempool.prototype.hasAny = function hasAny(hash, callback) {
var self = this;
return this.hasTX(hash, function(err, exists) {
if (err)
return callback(err);
if (exists)
return callback(null, true);
self.hasOrphan(hash, callback);
});
};
/**
* Add a transaction to the mempool. Note that this
* will lock the mempool until the transaction is
@ -998,7 +1017,7 @@ Mempool.prototype.getOrphan = function getOrphan(orphanHash, callback) {
this.db.get('O/' + orphanHash, function(err, orphan) {
if (err && err.type !== 'NotFoundError')
return next(err);
return callback(err);
if (!orphan)
return callback();
@ -1019,11 +1038,11 @@ Mempool.prototype.getOrphan = function getOrphan(orphanHash, callback) {
*/
Mempool.prototype.hasOrphan = function hasOrphan(orphanHash, callback) {
return this.getOrphan(orphanHash, function(err, tx) {
if (err)
this.db.get('O/' + orphanHash, function(err, orphan) {
if (err && err.type !== 'NotFoundError')
return callback(err);
return callback(null, tx != null);
return callback(null, orphan != null);
});
};

View File

@ -1616,7 +1616,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.hasTX(hash, done);
return this.mempool.hasAny(hash, done);
}
return this.chain.has(hash, done);
}