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