reject packets.

This commit is contained in:
Christopher Jeffrey 2016-02-09 01:29:23 -08:00
parent fb8be11eac
commit 9fc6848dce

View File

@ -105,21 +105,37 @@ Mempool.prototype.add = function add(tx, peer, callback) {
return callback(err); return callback(err);
if (!tx.hasPrevout()) { if (!tx.hasPrevout()) {
peer.reject({
data: tx.hash(),
reason: 'no-prevout'
});
pool.setMisbehavior(peer, 100); pool.setMisbehavior(peer, 100);
return callback(new Error('Previous outputs not found.')); return callback(new Error('Previous outputs not found.'));
} }
if (!tx.isStandard()) { if (!tx.isStandard()) {
peer.reject({
data: tx.hash(),
reason: 'non-standard'
});
pool.setMisbehavior(peer, 100); pool.setMisbehavior(peer, 100);
return callback(new Error('TX is not standard.')); return callback(new Error('TX is not standard.'));
} }
if (!tx.isStandardInputs()) { if (!tx.isStandardInputs()) {
peer.reject({
data: tx.hash(),
reason: 'non-standard-inputs'
});
pool.setMisbehavior(peer, 100); pool.setMisbehavior(peer, 100);
return callback(new Error('TX inputs are not standard.')); return callback(new Error('TX inputs are not standard.'));
} }
if (tx.getOutputValue().cmp(tx.getInputValue()) > 0) { if (tx.getOutputValue().cmp(tx.getInputValue()) > 0) {
peer.reject({
data: tx.hash(),
reason: 'nonexistent-coins'
});
pool.setMisbehavior(peer, 100); pool.setMisbehavior(peer, 100);
return callback(new Error('TX is spending coins that it does not have.')); 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; height = self.pool.chain.height() + 1;
ts = utils.now(); ts = utils.now();
if (!tx.isFinal(height, ts)) { if (!tx.isFinal(height, ts)) {
peer.reject({
data: tx.hash(),
reason: 'not-final'
});
pool.setMisbehavior(peer, 100); pool.setMisbehavior(peer, 100);
return callback(new Error('TX is not final.')); 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++) { for (i = 0; i < tx.inputs.length; i++) {
input = tx.inputs[i]; input = tx.inputs[i];
if (input.output.spent) { if (input.output.spent) {
peer.reject({
data: tx.hash(),
reason: 'old-outputs'
});
pool.setMisbehavior(peer, 100); pool.setMisbehavior(peer, 100);
return callback(new Error('TX is spending old outputs.')); return callback(new Error('TX is spending old outputs.'));
} }
@ -146,6 +170,10 @@ Mempool.prototype.add = function add(tx, peer, callback) {
continue; continue;
} }
} }
peer.reject({
data: tx.hash(),
reason: 'double-spend'
});
pool.setMisbehavior(peer, 100); pool.setMisbehavior(peer, 100);
return callback(new Error('TX is double spending.')); 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++) { for (i = 0; i < tx.outputs.length; i++) {
output = tx.outputs[i]; output = tx.outputs[i];
if (output.value.cmpn(0) < 0) { if (output.value.cmpn(0) < 0) {
peer.reject({
data: tx.hash(),
reason: 'negative-value'
});
pool.setMisbehavior(peer, 100); pool.setMisbehavior(peer, 100);
return callback(new Error('TX is spending negative coins.')); return callback(new Error('TX is spending negative coins.'));
} }
} }
if (!tx.verify(true)) { if (!tx.verify(true)) {
peer.reject({
data: tx.hash(),
reason: 'script-failed'
});
pool.setMisbehavior(peer, 100); pool.setMisbehavior(peer, 100);
return callback(new Error('TX did not verify.')); return callback(new Error('TX did not verify.'));
} }