diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js index 34f13eec..f8f73466 100644 --- a/lib/blockchain/chain.js +++ b/lib/blockchain/chain.js @@ -2283,6 +2283,8 @@ Chain.prototype.verifyLocks = co(function* verifyLocks(prev, tx, view, flags) { var locks = yield this.getLocks(prev, tx, view, flags); var medianTime; + // Also catches case where + // height is `-1`. Fall through. if (locks.height >= prev.height + 1) return false; diff --git a/lib/utils/bloom.js b/lib/utils/bloom.js index da515725..07a46c3a 100644 --- a/lib/utils/bloom.js +++ b/lib/utils/bloom.js @@ -27,7 +27,7 @@ var LN2 = 0.6931471805599453094172321214581765680755001343602552; * Bloom Filter * @exports Bloom * @constructor - * @param {Number|Bufer} size - Filter size in bits, or filter itself. + * @param {Number|Buffer} bits - Filter size in bits, or filter itself. * @param {Number} n - Number of hash functions. * @param {Number} tweak - Seed value. * @param {Number|String} - Update type. @@ -38,9 +38,9 @@ var LN2 = 0.6931471805599453094172321214581765680755001343602552; * @property {Number} update - Update flag (see {@link Bloom.flags}). */ -function Bloom(size, n, tweak, update) { +function Bloom(bits, n, tweak, update) { if (!(this instanceof Bloom)) - return new Bloom(size, n, tweak, update); + return new Bloom(bits, n, tweak, update); this.filter = DUMMY; this.size = 0; @@ -48,8 +48,8 @@ function Bloom(size, n, tweak, update) { this.tweak = 0; this.update = Bloom.flags.NONE; - if (size != null) - this.fromOptions(size, n, tweak, update); + if (bits != null) + this.fromOptions(bits, n, tweak, update); } /** @@ -109,22 +109,23 @@ Bloom.MAX_HASH_FUNCS = 50; /** * Inject properties from options. * @private - * @param {Number|Bufer} size - Filter size in bits, or filter itself. + * @param {Number|Buffer} bits - Filter size in bits, or filter itself. * @param {Number} n - Number of hash functions. * @param {Number} tweak - Seed value. * @param {Number|String} - Update type. * @returns {Bloom} */ -Bloom.prototype.fromOptions = function fromOptions(size, n, tweak, update) { - var filter; +Bloom.prototype.fromOptions = function fromOptions(bits, n, tweak, update) { + var filter, size; - if (Buffer.isBuffer(size)) { - filter = size; + if (Buffer.isBuffer(bits)) { + filter = bits; size = filter.length * 8; } else { - assert(typeof size === 'number', '`size` must be a number.'); - assert(size > 0, '`size` must be greater than zero.'); + assert(typeof bits === 'number', '`bits` must be a number or Buffer.'); + assert(bits > 0, '`bits` must be greater than zero.'); + size = bits; size -= size % 8; filter = new Buffer(size / 8); filter.fill(0); @@ -157,21 +158,21 @@ Bloom.prototype.fromOptions = function fromOptions(size, n, tweak, update) { /** * Instantiate bloom filter from options. - * @param {Number|Bufer} size - Filter size in bits, or filter itself. + * @param {Number|Buffer} bits - Filter size in bits, or filter itself. * @param {Number} n - Number of hash functions. * @param {Number} tweak - Seed value. * @param {Number|String} - Update type. * @returns {Bloom} */ -Bloom.fromOptions = function fromOptions(size, n, tweak, update) { - return new Bloom().fromOptions(size, n, tweak, update); +Bloom.fromOptions = function fromOptions(bits, n, tweak, update) { + return new Bloom().fromOptions(bits, n, tweak, update); }; /** * Perform the mumur3 hash on data. * @param {Buffer} val - * @param {Number} seed + * @param {Number} n * @returns {Number} */ @@ -270,7 +271,7 @@ Bloom.fromRate = function fromRate(items, rate, update) { if (update !== -1) size = Math.min(size, Bloom.MAX_BLOOM_FILTER_SIZE * 8); - n = Math.max(1, size / items * LN2); + n = Math.max(1, (size / items * LN2) | 0); if (update !== -1) n = Math.min(n, Bloom.MAX_HASH_FUNCS);