mempool: refactor orphan handling.
This commit is contained in:
parent
b9d6e7e40d
commit
5375f8bf19
@ -993,42 +993,19 @@ Mempool.prototype.verifyInputs = co(function* verifyInputs(tx, view, flags) {
|
||||
*/
|
||||
|
||||
Mempool.prototype.addEntry = co(function* addEntry(entry, view) {
|
||||
var i, resolved, tx;
|
||||
var tx = entry.tx;
|
||||
|
||||
this.trackEntry(entry, view);
|
||||
|
||||
this.emit('tx', entry.tx, view);
|
||||
this.emit('tx', tx, view);
|
||||
this.emit('add entry', entry);
|
||||
|
||||
if (this.fees)
|
||||
this.fees.processTX(entry, this.chain.isFull());
|
||||
|
||||
this.logger.debug('Added tx %s to mempool.', entry.tx.txid());
|
||||
this.logger.debug('Added tx %s to mempool.', tx.txid());
|
||||
|
||||
resolved = this.resolveOrphans(entry.tx);
|
||||
|
||||
for (i = 0; i < resolved.length; i++) {
|
||||
tx = resolved[i];
|
||||
|
||||
try {
|
||||
yield this._addTX(tx);
|
||||
} catch (err) {
|
||||
if (err.type === 'VerifyError') {
|
||||
this.logger.debug(
|
||||
'Could not resolve orphan %s: %s.',
|
||||
tx.txid(), err.message);
|
||||
|
||||
if (!tx.hasWitness() && !err.malleated)
|
||||
this.rejects.add(tx.hash());
|
||||
|
||||
continue;
|
||||
}
|
||||
this.emit('error', err);
|
||||
continue;
|
||||
}
|
||||
|
||||
this.logger.debug('Resolved orphan %s in mempool.', tx.txid());
|
||||
}
|
||||
yield this.handleOrphans(tx);
|
||||
});
|
||||
|
||||
/**
|
||||
@ -1042,8 +1019,6 @@ Mempool.prototype.removeEntry = function removeEntry(entry, limit) {
|
||||
var tx = entry.tx;
|
||||
var hash = tx.hash('hex');
|
||||
|
||||
this.removeOrphan(hash);
|
||||
|
||||
// We do not remove spenders if this is
|
||||
// being removed for a block. The spenders
|
||||
// are still spending valid coins (which
|
||||
@ -1380,13 +1355,48 @@ Mempool.prototype.storeOrphan = function storeOrphan(tx, missing) {
|
||||
return missing;
|
||||
};
|
||||
|
||||
/**
|
||||
* Resolve orphans and attempt to add to mempool.
|
||||
* @param {TX} tx
|
||||
* @returns {Promise} - Returns {@link TX}[].
|
||||
*/
|
||||
|
||||
Mempool.prototype.handleOrphans = co(function* handleOrphans(tx) {
|
||||
var resolved = this.resolveOrphans(tx);
|
||||
var i, orphan;
|
||||
|
||||
for (i = 0; i < resolved.length; i++) {
|
||||
orphan = resolved[i];
|
||||
|
||||
try {
|
||||
yield this._addTX(orphan);
|
||||
} catch (err) {
|
||||
if (err.type === 'VerifyError') {
|
||||
this.logger.debug(
|
||||
'Could not resolve orphan %s: %s.',
|
||||
orphan.txid(), err.message);
|
||||
|
||||
if (!orphan.hasWitness() && !err.malleated)
|
||||
this.rejects.add(orphan.hash());
|
||||
|
||||
continue;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
this.logger.debug('Resolved orphan %s in mempool.', orphan.txid());
|
||||
}
|
||||
|
||||
return resolved;
|
||||
});
|
||||
|
||||
/**
|
||||
* Potentially resolve any transactions
|
||||
* that redeem the passed-in transaction.
|
||||
* Deletes all orphan entries and
|
||||
* returns orphan hashes.
|
||||
* @param {TX} tx
|
||||
* @returns {Array} Resolved
|
||||
* @returns {TX[]} Resolved
|
||||
*/
|
||||
|
||||
Mempool.prototype.resolveOrphans = function resolveOrphans(tx) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user