diff --git a/lib/bcoin/blockdb.js b/lib/bcoin/blockdb.js index 8d7ea7f2..436b6f01 100644 --- a/lib/bcoin/blockdb.js +++ b/lib/bcoin/blockdb.js @@ -60,9 +60,14 @@ BlockDB.prototype.createOffset = function createOffset(size, offset, height) { }; BlockDB.prototype.parseOffset = function parseOffset(data) { + // Avoid using bignumbers here to increase performance. + // This is safe because this number will never exceed + // 53 bits (up to 8.3 petabytes). + var hi = utils.readU32(data, 8); + var lo = utils.readU32(data, 4); return { size: utils.readU32(data, 0), - offset: utils.readU64(data, 4).toNumber(), + offset: (hi * 0x100000000) + lo, height: utils.readU32(data, 12) }; }; @@ -367,6 +372,31 @@ BlockDB.prototype._getCoinsByAddress = function _getCoinsByAddress(address, call callback = utils.asyncify(callback); +/* + stream = this.index.createKeyStream({ + start: 'u/a/' + address, + end: 'u/a/' + address + '~' + }); + + stream.on('data', function(key) { + var parts = key.split('/').slice(3); + var hash = parts[0]; + var index = +parts[1]; + pending++; + self.index.get('u/t/' + hash + '/' + index, function(err, data) { + if (err && err.type !== 'NotFoundError') + return callback(err); + if (data) + coins.push(data); + pending--; + if (done) { + if (!pending) + return callback(null, coins); + } + }); + }); +*/ + stream = this.index.createReadStream({ start: 'u/a/' + address, end: 'u/a/' + address + '~' @@ -677,6 +707,7 @@ BlockData.prototype._init = function _init() { }; BlockData.prototype._malloc = function(size) { + return new Buffer(size); if (!this._bufferPool[size]) this._bufferPool[size] = new Buffer(size); @@ -689,6 +720,7 @@ BlockData.prototype._malloc = function(size) { }; BlockData.prototype._free = function(buf) { + return; if (this._bufferPool.used[buf.length] === buf) { assert(this._bufferPool[buf.length] === buf); delete this._bufferPool.used[buf.length]; diff --git a/lib/bcoin/node.js b/lib/bcoin/node.js index c0c414c3..1cd8d1d2 100644 --- a/lib/bcoin/node.js +++ b/lib/bcoin/node.js @@ -66,12 +66,14 @@ Node.prototype._init = function _init() { throw err; self.mempool.addBlock(block); + if (0) var hash = block.txs[0].hash('hex'); if (0) self.storage.getTX(hash, function(err, tx) { if (err) throw err; utils.print(tx); }); + if (0) self.storage.getCoin(hash, 0, function(err, tx) { if (err) throw err; utils.print(tx);