bip152: optimize.

This commit is contained in:
Christopher Jeffrey 2016-08-22 22:36:51 -07:00
parent 049be2086d
commit 9ced2df5fa
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -249,7 +249,7 @@ CompactBlock.prototype.initKey = function initKey() {
}; };
CompactBlock.prototype.init = function init() { CompactBlock.prototype.init = function init() {
var i, last, ptx, offset; var i, last, ptx, offset, id;
if (this.totalTX === 0) if (this.totalTX === 0)
throw new Error('Empty vectors.'); throw new Error('Empty vectors.');
@ -278,15 +278,19 @@ CompactBlock.prototype.init = function init() {
for (i = 0; i < this.ids.length; i++) { for (i = 0; i < this.ids.length; i++) {
while (this.available[i + offset]) while (this.available[i + offset])
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 // We're supposed to fail here if there's
// more than 12 hash collisions, but we // more than 12 hash collisions, but we
// don't have lowlevel access to our hash // don't have lowlevel access to our hash
// table. Hopefully we don't get hashdos'd. // 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() { CompactBlock.prototype.toBlock = function toBlock() {