chain: better checkpoint handling.
This commit is contained in:
parent
1f38f36077
commit
1a4268544f
@ -1469,7 +1469,10 @@ Chain.prototype.logStatus = function logStatus(start, block, entry) {
|
||||
*/
|
||||
|
||||
Chain.prototype.verifyCheckpoint = function verifyCheckpoint(prev, hash) {
|
||||
if (!this.checkpoints)
|
||||
if (!this.options.checkpoints)
|
||||
return true;
|
||||
|
||||
if (!this.checkpoints && !this.options.enforceCheckpoints)
|
||||
return true;
|
||||
|
||||
const height = prev.height + 1;
|
||||
@ -1799,11 +1802,10 @@ Chain.prototype.maybeSync = function maybeSync() {
|
||||
return;
|
||||
|
||||
if (this.checkpoints) {
|
||||
if (this.tip.height < this.network.lastCheckpoint)
|
||||
return;
|
||||
|
||||
this.logger.info('Last checkpoint reached. Disabling checkpoints.');
|
||||
this.checkpoints = false;
|
||||
if (this.tip.height >= this.network.lastCheckpoint || this.hasChainwork()) {
|
||||
this.logger.info('Last checkpoint reached. Disabling checkpoints.');
|
||||
this.checkpoints = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.tip.time < util.now() - this.network.block.maxTipAge)
|
||||
@ -2404,6 +2406,7 @@ function ChainOptions(options) {
|
||||
this.entryCache = 5000;
|
||||
this.maxOrphans = 20;
|
||||
this.checkpoints = true;
|
||||
this.enforceCheckpoints = false;
|
||||
|
||||
if (options)
|
||||
this.fromOptions(options);
|
||||
@ -2518,6 +2521,11 @@ ChainOptions.prototype.fromOptions = function fromOptions(options) {
|
||||
this.checkpoints = options.checkpoints;
|
||||
}
|
||||
|
||||
if (options.enforceCheckpoints != null) {
|
||||
assert(typeof options.enforceCheckpoints === 'boolean');
|
||||
this.enforceCheckpoints = options.enforceCheckpoints;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
@ -242,8 +242,6 @@ Pool.prototype._open = async function _open() {
|
||||
*/
|
||||
|
||||
Pool.prototype.resetChain = function resetChain() {
|
||||
const tip = this.chain.tip;
|
||||
|
||||
if (!this.options.checkpoints)
|
||||
return;
|
||||
|
||||
@ -253,7 +251,9 @@ Pool.prototype.resetChain = function resetChain() {
|
||||
this.headerChain.reset();
|
||||
this.headerNext = null;
|
||||
|
||||
if (tip.height < this.network.lastCheckpoint) {
|
||||
const tip = this.chain.tip;
|
||||
|
||||
if (tip.height < this.network.lastCheckpoint && !this.chain.hasChainwork()) {
|
||||
this.checkpoints = true;
|
||||
this.chain.checkpoints = true;
|
||||
this.headerTip = this.getNextTip(tip.height);
|
||||
|
||||
@ -61,6 +61,7 @@ function FullNode(options) {
|
||||
bip148: this.config.bool('bip148'),
|
||||
prune: this.config.bool('prune'),
|
||||
checkpoints: this.config.bool('checkpoints'),
|
||||
enforceCheckpoints: this.config.bool('enforce-checkpoints'),
|
||||
coinCache: this.config.mb('coin-cache'),
|
||||
entryCache: this.config.num('entry-cache'),
|
||||
indexTX: this.config.bool('index-tx'),
|
||||
|
||||
@ -54,6 +54,7 @@ function SPVNode(options) {
|
||||
entryCache: this.config.num('entry-cache'),
|
||||
forceFlags: this.config.bool('force-flags'),
|
||||
checkpoints: this.config.bool('checkpoints'),
|
||||
enforceCheckpoints: this.config.bool('enforce-checkpoints'),
|
||||
bip91: this.config.bool('bip91'),
|
||||
bip148: this.config.bool('bip148'),
|
||||
spv: true
|
||||
|
||||
Loading…
Reference in New Issue
Block a user