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) {
|
||||
// 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.');
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user