diff --git a/etc/sample.conf b/etc/sample.conf index 2ab32f5f..edb882a7 100644 --- a/etc/sample.conf +++ b/etc/sample.conf @@ -1,4 +1,4 @@ -# Default bcoin config file (~/.bcoin/bcoin.conf) +# Sample bcoin config file (~/.bcoin/bcoin.conf) # Options network: main @@ -15,6 +15,7 @@ log-file: true # Node # prefix: ~/.bcoin db: leveldb +max-files: 64 # fast: false # Chain diff --git a/lib/chain/chaindb.js b/lib/chain/chaindb.js index d435e72d..22c8e325 100644 --- a/lib/chain/chaindb.js +++ b/lib/chain/chaindb.js @@ -233,6 +233,7 @@ function ChainDB(chain, options) { this.db = bcoin.ldb({ location: this.options.location, db: this.options.db, + maxOpenFiles: this.options.maxFiles, compression: true, cacheSize: 16 << 20, writeBufferSize: 8 << 20, diff --git a/lib/db/ldb.js b/lib/db/ldb.js index ecf12b40..6e84aa0a 100644 --- a/lib/db/ldb.js +++ b/lib/db/ldb.js @@ -29,19 +29,19 @@ var assert = utils.assert; */ function ldb(options) { - options = ldb.parseOptions(options); + var target = ldb.getTarget(options); - if (options.backend !== 'rbt') - utils.mkdir(options.location, true); + if (target.backend !== 'rbt') + utils.mkdir(target.location, true); - return new LowlevelUp(options.location, { + return new LowlevelUp(target.location, { // LevelDB and others createIfMissing: options.createIfMissing !== false, errorIfExists: options.errorIfExists === true, compression: options.compression !== false, cacheSize: options.cacheSize || (8 << 20), writeBufferSize: options.writeBufferSize || (4 << 20), - maxOpenFiles: options.maxOpenFiles || 8192, + maxOpenFiles: options.maxOpenFiles || 64, filterBits: 0, paranoidChecks: false, memory: false, @@ -54,7 +54,7 @@ function ldb(options) { // For browser buffer keys bufferKeys: options.bufferKeys, - db: options.db + db: target.db }); } @@ -103,12 +103,12 @@ ldb.getBackend = function getBackend(db) { }; /** - * Parse options. + * Get target backend and location. * @param {Object} options * @returns {Object} */ -ldb.parseOptions = function parseOptions(options) { +ldb.getTarget = function getTarget(options) { var backend = ldb.getBackend(options.db); var location = options.location; var db; @@ -125,12 +125,11 @@ ldb.parseOptions = function parseOptions(options) { location = 'rbt'; } - return utils.merge({}, options, { + return { + db: db, backend: backend.name, - ext: backend.ext, - location: location + '.' + backend.ext, - db: db - }); + location: location + '.' + backend.ext + }; }; /* diff --git a/lib/node/config.js b/lib/node/config.js index 45bdf7c9..18fb5626 100644 --- a/lib/node/config.js +++ b/lib/node/config.js @@ -133,6 +133,7 @@ config.parseData = function parseData(data) { // Node options.prefix = path(data.prefix); options.db = str(data.db); + options.maxFiles = num(data.maxfiles); options.fast = bool(data.fast); // Chain diff --git a/lib/node/fullnode.js b/lib/node/fullnode.js index bad512a5..74f0ca03 100644 --- a/lib/node/fullnode.js +++ b/lib/node/fullnode.js @@ -66,7 +66,8 @@ function Fullnode(options) { useCheckpoints: this.options.useCheckpoints, coinCache: this.options.coinCache, indexTX: this.options.indexTX, - indexAddress: this.options.indexAddress + indexAddress: this.options.indexAddress, + maxFiles: this.options.maxFiles }); // Fee estimation. @@ -135,6 +136,7 @@ function Fullnode(options) { location: this.location('walletdb'), witness: this.options.witness, useCheckpoints: this.options.useCheckpoints, + maxFiles: this.options.maxFiles, verify: false }); diff --git a/lib/node/spvnode.js b/lib/node/spvnode.js index dda494c8..94dae556 100644 --- a/lib/node/spvnode.js +++ b/lib/node/spvnode.js @@ -48,6 +48,7 @@ function SPVNode(options) { location: this.location('spvchain'), witness: this.options.witness, useCheckpoints: this.options.useCheckpoints, + maxFiles: this.options.maxFiles, spv: true }); @@ -75,6 +76,7 @@ function SPVNode(options) { db: this.db, location: this.location('walletdb'), witness: this.options.witness, + maxFiles: this.options.maxFiles, verify: true }); diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index 7faa4d0a..a6377b67 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -190,6 +190,7 @@ function WalletDB(options) { this.db = bcoin.ldb({ location: this.options.location, db: this.options.db, + maxOpenFiles: this.options.maxFiles, cacheSize: 8 << 20, writeBufferSize: 4 << 20, bufferKeys: true