diff --git a/lib/chain/chaindb.js b/lib/chain/chaindb.js index c3d45e1f..f161c1cb 100644 --- a/lib/chain/chaindb.js +++ b/lib/chain/chaindb.js @@ -229,9 +229,10 @@ ChainDB.prototype._open = co(function* open() { if (options) { // Verify the options haven't changed. this.options.verify(options); - this.options = options; + if (this.options.forceWitness) + yield this.saveOptions(); } else { - yield this.db.put(layout.O, this.options.toRaw()); + yield this.saveOptions(); } if (state) { @@ -1611,6 +1612,15 @@ ChainDB.prototype.pruneBlock = co(function* pruneBlock(block) { this.del(layout.u(hash)); }); +/** + * Save database options. + * @returns {Promise} + */ + +ChainDB.prototype.saveOptions = function saveOptions() { + return this.db.put(layout.O, this.options.toRaw()); +}; + /** * Chain Options * @constructor @@ -1626,6 +1636,8 @@ function ChainOptions(options) { this.indexTX = false; this.indexAddress = false; + this.forceWitness = false; + if (options) this.fromOptions(options); } @@ -1656,6 +1668,11 @@ ChainOptions.prototype.fromOptions = function fromOptions(options) { this.indexAddress = options.indexAddress; } + if (options.forceWitness != null) { + assert(typeof options.forceWitness === 'boolean'); + this.forceWitness = options.forceWitness; + } + return this; }; @@ -1670,11 +1687,13 @@ ChainOptions.prototype.verify = function verify(options) { if (!this.spv && options.spv) throw new Error('Cannot retroactively disable SPV.'); - if (this.witness && !options.witness) - throw new Error('Cannot retroactively enable witness.'); + if (!this.forceWitness) { + if (this.witness && !options.witness) + throw new Error('Cannot retroactively enable witness.'); - if (!this.witness && options.witness) - throw new Error('Cannot retroactively disable witness.'); + if (!this.witness && options.witness) + throw new Error('Cannot retroactively disable witness.'); + } if (this.prune && !options.prune) throw new Error('Cannot retroactively prune.'); diff --git a/lib/node/config.js b/lib/node/config.js index 518e4d85..d2c03c25 100644 --- a/lib/node/config.js +++ b/lib/node/config.js @@ -157,6 +157,7 @@ config.parseData = function parseData(data, prefix, dirname) { // Chain options.witness = bool(data.witness); + options.forceWitness = bool(data.forcewitness); options.prune = bool(data.prune); options.useCheckpoints = bool(data.usecheckpoints); options.coinCache = bool(data.coincache); diff --git a/lib/node/fullnode.js b/lib/node/fullnode.js index 8dd9b953..797532c5 100644 --- a/lib/node/fullnode.js +++ b/lib/node/fullnode.js @@ -74,6 +74,7 @@ function Fullnode(options) { preload: false, spv: false, witness: this.options.witness, + forceWitness: this.options.forceWitness, prune: this.options.prune, useCheckpoints: this.options.useCheckpoints, coinCache: this.options.coinCache, diff --git a/lib/node/spvnode.js b/lib/node/spvnode.js index 8bd035b6..a53256c5 100644 --- a/lib/node/spvnode.js +++ b/lib/node/spvnode.js @@ -56,6 +56,7 @@ function SPVNode(options) { db: this.options.db, location: this.location('spvchain'), witness: this.options.witness, + forceWitness: this.options.forceWitness, useCheckpoints: this.options.useCheckpoints, maxFiles: this.options.maxFiles, spv: true