bank on new bn() accepting buffers for extra perf.
This commit is contained in:
parent
effaa57abf
commit
39ecd292b3
@ -39,10 +39,16 @@ function BlockDB(options) {
|
|||||||
|
|
||||||
this.data = new BlockData();
|
this.data = new BlockData();
|
||||||
|
|
||||||
this.index = levelup(this.file, {
|
this.index = new levelup(this.file, {
|
||||||
keyEncoding: 'ascii',
|
keyEncoding: 'ascii',
|
||||||
valueEncoding: 'binary',
|
valueEncoding: 'binary',
|
||||||
|
createIfMissing: true,
|
||||||
|
errorIfExists: false,
|
||||||
|
compression: true,
|
||||||
cacheSize: 16 * 1024 * 1024,
|
cacheSize: 16 * 1024 * 1024,
|
||||||
|
// writeBufferSize: 4 * 1024 * 1024,
|
||||||
|
// blockSize: 4 * 1024,
|
||||||
|
maxOpenFiles: 8192,
|
||||||
db: bcoin.isBrowser
|
db: bcoin.isBrowser
|
||||||
? require('memdown')
|
? require('memdown')
|
||||||
: require('level' + 'down')
|
: require('level' + 'down')
|
||||||
@ -74,7 +80,6 @@ BlockDB.prototype.parseOffset = function parseOffset(data) {
|
|||||||
|
|
||||||
BlockDB.prototype.saveBlock = function saveBlock(block, callback) {
|
BlockDB.prototype.saveBlock = function saveBlock(block, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var batch = this.index.batch();
|
|
||||||
|
|
||||||
this.data.saveAsync(block._raw, function(err, data) {
|
this.data.saveAsync(block._raw, function(err, data) {
|
||||||
var batch, blockOffset;
|
var batch, blockOffset;
|
||||||
@ -537,8 +542,10 @@ BlockDB.prototype._getTXByAddress = function _getTXByAddress(address, callback)
|
|||||||
});
|
});
|
||||||
|
|
||||||
stream.on('data', function(data) {
|
stream.on('data', function(data) {
|
||||||
var parts = data.key.split('/').slice(3);
|
// var parts = data.key.split('/').slice(3);
|
||||||
var hash = parts[0];
|
// var hash = parts[0];
|
||||||
|
// Could store block hash in key
|
||||||
|
// var blockHash = parts[1];
|
||||||
var record = self.parseOffset(data.value);
|
var record = self.parseOffset(data.value);
|
||||||
|
|
||||||
pending++;
|
pending++;
|
||||||
|
|||||||
@ -533,7 +533,7 @@ utils.isSatoshi = function isSatoshi(val) {
|
|||||||
if (utils.isHex(val))
|
if (utils.isHex(val))
|
||||||
return new bn(val, 'hex');
|
return new bn(val, 'hex');
|
||||||
if (Buffer.isBuffer(val))
|
if (Buffer.isBuffer(val))
|
||||||
return new bn(utils.toArray(val));
|
return new bn(val);
|
||||||
if (Array.isArray(val))
|
if (Array.isArray(val))
|
||||||
return new bn(val);
|
return new bn(val);
|
||||||
return false;
|
return false;
|
||||||
@ -1003,14 +1003,14 @@ utils.readU32BE = function readU32BE(arr, off) {
|
|||||||
utils.readU64 = function readU64(arr, off) {
|
utils.readU64 = function readU64(arr, off) {
|
||||||
var num;
|
var num;
|
||||||
off = off >>> 0;
|
off = off >>> 0;
|
||||||
num = utils.toArray(arr.slice(off, off + 8));
|
num = arr.slice(off, off + 8);
|
||||||
return new bn(num, 'le');
|
return new bn(num, 'le');
|
||||||
};
|
};
|
||||||
|
|
||||||
utils.readU64BE = function readU64BE(arr, off) {
|
utils.readU64BE = function readU64BE(arr, off) {
|
||||||
var num;
|
var num;
|
||||||
off = off >>> 0;
|
off = off >>> 0;
|
||||||
num = utils.toArray(arr.slice(off, off + 8));
|
num = arr.slice(off, off + 8);
|
||||||
return new bn(num, 'be');
|
return new bn(num, 'be');
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1058,7 +1058,7 @@ utils.read64 = function read64(arr, off) {
|
|||||||
|
|
||||||
off = off >>> 0;
|
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
|
// If we are signed, do (~num + 1) to get
|
||||||
// the positive counterpart and set bn's
|
// the positive counterpart and set bn's
|
||||||
@ -1077,7 +1077,7 @@ utils.read64BE = function read64BE(arr, off) {
|
|||||||
|
|
||||||
off = off >>> 0;
|
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
|
// If we are signed, do (~num + 1) to get
|
||||||
// the positive counterpart and set bn's
|
// the positive counterpart and set bn's
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user