reject packets.
This commit is contained in:
parent
fb8be11eac
commit
9fc6848dce
@ -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.'));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user