diff --git a/lib/bcoin/bip152.js b/lib/bcoin/bip152.js index 5d462840..5bb2ab33 100644 --- a/lib/bcoin/bip152.js +++ b/lib/bcoin/bip152.js @@ -249,7 +249,7 @@ CompactBlock.prototype.initKey = function initKey() { }; CompactBlock.prototype.init = function init() { - var i, last, ptx, offset; + var i, last, ptx, offset, id; if (this.totalTX === 0) throw new Error('Empty vectors.'); @@ -278,15 +278,19 @@ CompactBlock.prototype.init = function init() { for (i = 0; i < this.ids.length; i++) { while (this.available[i + offset]) offset++; - this.idMap[this.ids[i]] = i + offset; + + id = this.ids[i]; + + // Fails on siphash collision + assert(!this.idMap[id], 'Siphash collision.'); + + this.idMap[id] = i + offset; + // We're supposed to fail here if there's // more than 12 hash collisions, but we // don't have lowlevel access to our hash // table. Hopefully we don't get hashdos'd. } - - // Fails on siphash collision - assert(this.ids.length === Object.keys(this.idMap).length); }; CompactBlock.prototype.toBlock = function toBlock() {