bank on new bn() accepting buffers for extra perf.

This commit is contained in:
Christopher Jeffrey 2016-02-15 14:10:50 -08:00
parent effaa57abf
commit 39ecd292b3
2 changed files with 16 additions and 9 deletions

View File

@ -39,10 +39,16 @@ function BlockDB(options) {
this.data = new BlockData();
this.index = levelup(this.file, {
this.index = new levelup(this.file, {
keyEncoding: 'ascii',
valueEncoding: 'binary',
createIfMissing: true,
errorIfExists: false,
compression: true,
cacheSize: 16 * 1024 * 1024,
// writeBufferSize: 4 * 1024 * 1024,
// blockSize: 4 * 1024,
maxOpenFiles: 8192,
db: bcoin.isBrowser
? require('memdown')
: require('level' + 'down')
@ -74,7 +80,6 @@ BlockDB.prototype.parseOffset = function parseOffset(data) {
BlockDB.prototype.saveBlock = function saveBlock(block, callback) {
var self = this;
var batch = this.index.batch();
this.data.saveAsync(block._raw, function(err, data) {
var batch, blockOffset;
@ -537,8 +542,10 @@ BlockDB.prototype._getTXByAddress = function _getTXByAddress(address, callback)
});
stream.on('data', function(data) {
var parts = data.key.split('/').slice(3);
var hash = parts[0];
// var parts = data.key.split('/').slice(3);
// var hash = parts[0];
// Could store block hash in key
// var blockHash = parts[1];
var record = self.parseOffset(data.value);
pending++;

View File

@ -533,7 +533,7 @@ utils.isSatoshi = function isSatoshi(val) {
if (utils.isHex(val))
return new bn(val, 'hex');
if (Buffer.isBuffer(val))
return new bn(utils.toArray(val));
return new bn(val);
if (Array.isArray(val))
return new bn(val);
return false;
@ -1003,14 +1003,14 @@ utils.readU32BE = function readU32BE(arr, off) {
utils.readU64 = function readU64(arr, off) {
var num;
off = off >>> 0;
num = utils.toArray(arr.slice(off, off + 8));
num = arr.slice(off, off + 8);
return new bn(num, 'le');
};
utils.readU64BE = function readU64BE(arr, off) {
var num;
off = off >>> 0;
num = utils.toArray(arr.slice(off, off + 8));
num = arr.slice(off, off + 8);
return new bn(num, 'be');
};
@ -1058,7 +1058,7 @@ utils.read64 = function read64(arr, off) {
off = off >>> 0;
num = utils.toArray(arr.slice(off, off + 8));
num = arr.slice(off, off + 8);
// If we are signed, do (~num + 1) to get
// the positive counterpart and set bn's
@ -1077,7 +1077,7 @@ utils.read64BE = function read64BE(arr, off) {
off = off >>> 0;
num = utils.toArray(arr.slice(off, off + 8));
num = arr.slice(off, off + 8);
// If we are signed, do (~num + 1) to get
// the positive counterpart and set bn's