pool: fix verify error handling.

This commit is contained in:
Christopher Jeffrey 2017-01-19 06:24:53 -08:00
parent 0a756aba34
commit 8cd951c994
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -880,21 +880,21 @@ Pool.prototype._handleBlock = co(function* handleBlock(peer, block) {
try {
yield this.chain.add(block);
} catch (err) {
if (err.type !== 'VerifyError')
throw err;
if (err.reason === 'bad-prevblk') {
if (this.headersFirst) {
peer.increaseBan(10);
throw err;
if (err.type === 'VerifyError') {
if (err.reason === 'bad-prevblk') {
if (this.headersFirst) {
peer.increaseBan(10);
this.emit('error', err);
return;
}
this.logger.debug('Peer sent an orphan block. Resolving.');
yield peer.resolveOrphan(null, hash);
return;
}
this.logger.debug('Peer sent an orphan block. Resolving.');
yield peer.resolveOrphan(null, hash);
throw err;
peer.reject(block, err.code, err.reason, err.score);
this.emit('error', err);
return;
}
peer.reject(block, err.code, err.reason, err.score);
throw err;
}
@ -1015,8 +1015,11 @@ Pool.prototype._handleTX = co(function* handleTX(peer, tx) {
try {
missing = yield this.mempool.addTX(tx);
} catch (err) {
if (err.type === 'VerifyError')
if (err.type === 'VerifyError') {
peer.reject(tx, err.code, err.reason, err.score);
this.emit('error', err);
return;
}
throw err;
}
@ -1605,7 +1608,6 @@ Pool.prototype.watchOutpoint = function watchOutpoint(outpoint) {
* Queue a `getdata` request to be sent.
* @param {Peer} peer
* @param {Hash[]} hashes
* @returns {Promise}
*/
Pool.prototype.getBlock = function getBlock(peer, hashes) {
@ -1646,11 +1648,9 @@ Pool.prototype.getBlock = function getBlock(peer, hashes) {
};
/**
* Queue a `getdata` request to be sent. Checks existence
* in the mempool before requesting.
* Queue a `getdata` request to be sent.
* @param {Peer} peer
* @param {Hash[]} hashes
* @returns {Boolean}
*/
Pool.prototype.getTX = function getTX(peer, hashes) {