chaindb: add forceWitness option.
This commit is contained in:
parent
331daf0f6a
commit
233f0c5278
@ -229,9 +229,10 @@ ChainDB.prototype._open = co(function* open() {
|
|||||||
if (options) {
|
if (options) {
|
||||||
// Verify the options haven't changed.
|
// Verify the options haven't changed.
|
||||||
this.options.verify(options);
|
this.options.verify(options);
|
||||||
this.options = options;
|
if (this.options.forceWitness)
|
||||||
|
yield this.saveOptions();
|
||||||
} else {
|
} else {
|
||||||
yield this.db.put(layout.O, this.options.toRaw());
|
yield this.saveOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state) {
|
if (state) {
|
||||||
@ -1611,6 +1612,15 @@ ChainDB.prototype.pruneBlock = co(function* pruneBlock(block) {
|
|||||||
this.del(layout.u(hash));
|
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
|
* Chain Options
|
||||||
* @constructor
|
* @constructor
|
||||||
@ -1626,6 +1636,8 @@ function ChainOptions(options) {
|
|||||||
this.indexTX = false;
|
this.indexTX = false;
|
||||||
this.indexAddress = false;
|
this.indexAddress = false;
|
||||||
|
|
||||||
|
this.forceWitness = false;
|
||||||
|
|
||||||
if (options)
|
if (options)
|
||||||
this.fromOptions(options);
|
this.fromOptions(options);
|
||||||
}
|
}
|
||||||
@ -1656,6 +1668,11 @@ ChainOptions.prototype.fromOptions = function fromOptions(options) {
|
|||||||
this.indexAddress = options.indexAddress;
|
this.indexAddress = options.indexAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.forceWitness != null) {
|
||||||
|
assert(typeof options.forceWitness === 'boolean');
|
||||||
|
this.forceWitness = options.forceWitness;
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1670,11 +1687,13 @@ ChainOptions.prototype.verify = function verify(options) {
|
|||||||
if (!this.spv && options.spv)
|
if (!this.spv && options.spv)
|
||||||
throw new Error('Cannot retroactively disable SPV.');
|
throw new Error('Cannot retroactively disable SPV.');
|
||||||
|
|
||||||
if (this.witness && !options.witness)
|
if (!this.forceWitness) {
|
||||||
throw new Error('Cannot retroactively enable witness.');
|
if (this.witness && !options.witness)
|
||||||
|
throw new Error('Cannot retroactively enable witness.');
|
||||||
|
|
||||||
if (!this.witness && options.witness)
|
if (!this.witness && options.witness)
|
||||||
throw new Error('Cannot retroactively disable witness.');
|
throw new Error('Cannot retroactively disable witness.');
|
||||||
|
}
|
||||||
|
|
||||||
if (this.prune && !options.prune)
|
if (this.prune && !options.prune)
|
||||||
throw new Error('Cannot retroactively prune.');
|
throw new Error('Cannot retroactively prune.');
|
||||||
|
|||||||
@ -157,6 +157,7 @@ config.parseData = function parseData(data, prefix, dirname) {
|
|||||||
|
|
||||||
// Chain
|
// Chain
|
||||||
options.witness = bool(data.witness);
|
options.witness = bool(data.witness);
|
||||||
|
options.forceWitness = bool(data.forcewitness);
|
||||||
options.prune = bool(data.prune);
|
options.prune = bool(data.prune);
|
||||||
options.useCheckpoints = bool(data.usecheckpoints);
|
options.useCheckpoints = bool(data.usecheckpoints);
|
||||||
options.coinCache = bool(data.coincache);
|
options.coinCache = bool(data.coincache);
|
||||||
|
|||||||
@ -74,6 +74,7 @@ function Fullnode(options) {
|
|||||||
preload: false,
|
preload: false,
|
||||||
spv: false,
|
spv: false,
|
||||||
witness: this.options.witness,
|
witness: this.options.witness,
|
||||||
|
forceWitness: this.options.forceWitness,
|
||||||
prune: this.options.prune,
|
prune: this.options.prune,
|
||||||
useCheckpoints: this.options.useCheckpoints,
|
useCheckpoints: this.options.useCheckpoints,
|
||||||
coinCache: this.options.coinCache,
|
coinCache: this.options.coinCache,
|
||||||
|
|||||||
@ -56,6 +56,7 @@ function SPVNode(options) {
|
|||||||
db: this.options.db,
|
db: this.options.db,
|
||||||
location: this.location('spvchain'),
|
location: this.location('spvchain'),
|
||||||
witness: this.options.witness,
|
witness: this.options.witness,
|
||||||
|
forceWitness: this.options.forceWitness,
|
||||||
useCheckpoints: this.options.useCheckpoints,
|
useCheckpoints: this.options.useCheckpoints,
|
||||||
maxFiles: this.options.maxFiles,
|
maxFiles: this.options.maxFiles,
|
||||||
spv: true
|
spv: true
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user