chaindb: add forceWitness option.

This commit is contained in:
Christopher Jeffrey 2016-10-23 05:35:37 -07:00
parent 331daf0f6a
commit 233f0c5278
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
4 changed files with 28 additions and 6 deletions

View File

@ -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.');

View File

@ -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);

View File

@ -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,

View File

@ -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