pool: refactor reject handling.
This commit is contained in:
parent
94d4e80373
commit
5fb64e7bac
@ -1022,15 +1022,22 @@ Pool.prototype.handleTX = co(function* handleTX(peer, tx) {
|
||||
var missing;
|
||||
|
||||
if (!requested) {
|
||||
peer.invFilter.add(tx.hash());
|
||||
|
||||
if (!this.mempool)
|
||||
this.txFilter.add(tx.hash());
|
||||
|
||||
this.logger.warning('Peer sent unrequested tx: %s (%s).',
|
||||
tx.txid(), peer.hostname);
|
||||
|
||||
if (this.hasReject(tx.hash())) {
|
||||
peer.invFilter.add(tx.hash());
|
||||
}
|
||||
|
||||
if (!this.mempool) {
|
||||
if (!requested)
|
||||
this.txFilter.add(tx.hash());
|
||||
this.emit('tx', tx, peer);
|
||||
this.scheduleRequests(peer);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!requested) {
|
||||
if (this.mempool.hasReject(tx.hash())) {
|
||||
throw new VerifyError(tx,
|
||||
'alreadyknown',
|
||||
'txn-already-in-mempool',
|
||||
@ -1038,12 +1045,6 @@ Pool.prototype.handleTX = co(function* handleTX(peer, tx) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.mempool) {
|
||||
this.emit('tx', tx, peer);
|
||||
this.scheduleRequests(peer);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
missing = yield this.mempool.addTX(tx);
|
||||
} catch (err) {
|
||||
@ -1356,19 +1357,6 @@ Pool.prototype.handleAlert = function handleAlert(peer, alert) {
|
||||
this.emit('alert', alert, peer);
|
||||
};
|
||||
|
||||
/**
|
||||
* Test the mempool to see if it
|
||||
* contains a recent reject.
|
||||
* @param {Hash} hash
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
Pool.prototype.hasReject = function hasReject(hash) {
|
||||
if (!this.mempool)
|
||||
return false;
|
||||
return this.mempool.hasReject(hash);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create an inbound peer from an existing socket.
|
||||
* @private
|
||||
@ -1650,8 +1638,6 @@ Pool.prototype.getBlock = function getBlock(peer, hash) {
|
||||
|
||||
/**
|
||||
* Test whether the chain has or has seen an item.
|
||||
* @param {Peer} peer
|
||||
* @param {InvType} type
|
||||
* @param {Hash} hash
|
||||
* @returns {Promise} - Returns Boolean.
|
||||
*/
|
||||
@ -1710,8 +1696,6 @@ Pool.prototype.getTX = function getTX(peer, hashes) {
|
||||
|
||||
/**
|
||||
* Test whether the mempool has or has seen an item.
|
||||
* @param {Peer} peer
|
||||
* @param {InvType} type
|
||||
* @param {Hash} hash
|
||||
* @returns {Promise} - Returns Boolean.
|
||||
*/
|
||||
@ -1726,12 +1710,12 @@ Pool.prototype.hasTX = function hasTX(hash) {
|
||||
// Check the mempool.
|
||||
if (this.mempool.has(hash))
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we recently rejected this item. Ignore.
|
||||
if (this.hasReject(hash)) {
|
||||
this.logger.spam('Saw known reject of %s.', util.revHex(hash));
|
||||
return true;
|
||||
// If we recently rejected this item. Ignore.
|
||||
if (this.mempool.hasReject(hash)) {
|
||||
this.logger.spam('Saw known reject of %s.', util.revHex(hash));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check the pending requests.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user