block: improve performance of duplicate tx check.

This commit is contained in:
Christopher Jeffrey 2014-05-23 23:13:16 -05:00
parent 44774e7c6b
commit e3e324441b

View File

@ -232,14 +232,11 @@ Block.prototype._checkBlock = function checkBlock() {
this.merkleTree = this._buildMerkle();
// Check for duplicate tx ids
var unique = [];
var unique = {};
for (var i = 0; i < this.txs.length; i++) {
if (!~unique.indexOf(this.txs[i].hash('hex'))) {
unique.push(this.txs[i].hash('hex'));
}
}
if (unique.length !== this.txs.length) {
return false;
var hash = this.txs[i].hash('hex');
if (unique[hash]) return false;
unique[hash] = true;
}
// Check to make sure block does not have more opcodes than MAX_BLOCK_SIGOPS