From 9fc6848dce799ccb40f68f1f0d1ba6ed38b09888 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 9 Feb 2016 01:29:23 -0800 Subject: [PATCH] reject packets. --- lib/bcoin/mempool.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/bcoin/mempool.js b/lib/bcoin/mempool.js index 6bb2f31e..8769fcc7 100644 --- a/lib/bcoin/mempool.js +++ b/lib/bcoin/mempool.js @@ -105,21 +105,37 @@ Mempool.prototype.add = function add(tx, peer, callback) { return callback(err); if (!tx.hasPrevout()) { + peer.reject({ + data: tx.hash(), + reason: 'no-prevout' + }); pool.setMisbehavior(peer, 100); return callback(new Error('Previous outputs not found.')); } if (!tx.isStandard()) { + peer.reject({ + data: tx.hash(), + reason: 'non-standard' + }); pool.setMisbehavior(peer, 100); return callback(new Error('TX is not standard.')); } if (!tx.isStandardInputs()) { + peer.reject({ + data: tx.hash(), + reason: 'non-standard-inputs' + }); pool.setMisbehavior(peer, 100); return callback(new Error('TX inputs are not standard.')); } if (tx.getOutputValue().cmp(tx.getInputValue()) > 0) { + peer.reject({ + data: tx.hash(), + reason: 'nonexistent-coins' + }); pool.setMisbehavior(peer, 100); return callback(new Error('TX is spending coins that it does not have.')); } @@ -127,6 +143,10 @@ Mempool.prototype.add = function add(tx, peer, callback) { height = self.pool.chain.height() + 1; ts = utils.now(); if (!tx.isFinal(height, ts)) { + peer.reject({ + data: tx.hash(), + reason: 'not-final' + }); pool.setMisbehavior(peer, 100); return callback(new Error('TX is not final.')); } @@ -134,6 +154,10 @@ Mempool.prototype.add = function add(tx, peer, callback) { for (i = 0; i < tx.inputs.length; i++) { input = tx.inputs[i]; if (input.output.spent) { + peer.reject({ + data: tx.hash(), + reason: 'old-outputs' + }); pool.setMisbehavior(peer, 100); return callback(new Error('TX is spending old outputs.')); } @@ -146,6 +170,10 @@ Mempool.prototype.add = function add(tx, peer, callback) { continue; } } + peer.reject({ + data: tx.hash(), + reason: 'double-spend' + }); pool.setMisbehavior(peer, 100); return callback(new Error('TX is double spending.')); } @@ -154,12 +182,20 @@ Mempool.prototype.add = function add(tx, peer, callback) { for (i = 0; i < tx.outputs.length; i++) { output = tx.outputs[i]; if (output.value.cmpn(0) < 0) { + peer.reject({ + data: tx.hash(), + reason: 'negative-value' + }); pool.setMisbehavior(peer, 100); return callback(new Error('TX is spending negative coins.')); } } if (!tx.verify(true)) { + peer.reject({ + data: tx.hash(), + reason: 'script-failed' + }); pool.setMisbehavior(peer, 100); return callback(new Error('TX did not verify.')); }