chain: determine sync state using last checkpoint's chainwork.
This commit is contained in:
parent
860e51e390
commit
ee7ad9dc86
@ -1802,10 +1802,11 @@ Chain.prototype.maybeSync = function maybeSync() {
|
||||
return;
|
||||
|
||||
if (this.checkpoints) {
|
||||
if (this.tip.height >= this.network.lastCheckpoint || this.hasChainwork()) {
|
||||
this.logger.info('Last checkpoint reached. Disabling checkpoints.');
|
||||
this.checkpoints = false;
|
||||
}
|
||||
if (!this.hasCheckpoints())
|
||||
return;
|
||||
|
||||
this.logger.info('Last checkpoint reached. Disabling checkpoints.');
|
||||
this.checkpoints = false;
|
||||
}
|
||||
|
||||
if (this.tip.time < util.now() - this.network.block.maxTipAge)
|
||||
@ -1829,6 +1830,17 @@ Chain.prototype.hasChainwork = function hasChainwork() {
|
||||
return this.tip.chainwork.cmp(this.network.pow.chainwork) >= 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test the chain to see if it has the
|
||||
* minimum required chainwork for the
|
||||
* last checkpointed block.
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
Chain.prototype.hasCheckpoints = function hasCheckpoints() {
|
||||
return this.tip.chainwork.cmp(this.network.lastChainwork) >= 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the fill percentage.
|
||||
* @returns {Number} percent - Ranges from 0.0 to 1.0.
|
||||
|
||||
@ -251,9 +251,8 @@ Pool.prototype.resetChain = function resetChain() {
|
||||
this.headerChain.reset();
|
||||
this.headerNext = null;
|
||||
|
||||
const tip = this.chain.tip;
|
||||
|
||||
if (tip.height < this.network.lastCheckpoint && !this.chain.hasChainwork()) {
|
||||
if (!this.chain.hasCheckpoints()) {
|
||||
const tip = this.chain.tip;
|
||||
this.checkpoints = true;
|
||||
this.chain.checkpoints = true;
|
||||
this.headerTip = this.getNextTip(tip.height);
|
||||
|
||||
@ -32,6 +32,7 @@ function Network(options) {
|
||||
this.port = options.port;
|
||||
this.checkpointMap = options.checkpointMap;
|
||||
this.lastCheckpoint = options.lastCheckpoint;
|
||||
this.lastChainwork = options.lastChainwork;
|
||||
this.checkpoints = [];
|
||||
this.halvingInterval = options.halvingInterval;
|
||||
this.genesis = options.genesis;
|
||||
|
||||
@ -112,6 +112,17 @@ main.checkpointMap = {
|
||||
|
||||
main.lastCheckpoint = 470000;
|
||||
|
||||
/**
|
||||
* Last checkpoint chainwork.
|
||||
* @const {BN}
|
||||
* @default
|
||||
*/
|
||||
|
||||
main.lastChainwork = new BN(
|
||||
'0000000000000000000000000000000000000000005dcc420d5bcce89a5d0d04',
|
||||
'hex'
|
||||
);
|
||||
|
||||
/**
|
||||
* @const {Number}
|
||||
* @default
|
||||
@ -513,6 +524,10 @@ testnet.checkpointMap = {
|
||||
};
|
||||
|
||||
testnet.lastCheckpoint = 1050000;
|
||||
testnet.lastChainwork = new BN(
|
||||
'00000000000000000000000000000000000000000000001a461538dc48da1a06',
|
||||
'hex'
|
||||
);
|
||||
|
||||
testnet.halvingInterval = 210000;
|
||||
|
||||
@ -674,6 +689,10 @@ regtest.port = 48444;
|
||||
|
||||
regtest.checkpointMap = {};
|
||||
regtest.lastCheckpoint = 0;
|
||||
regtest.lastChainwork = new BN(
|
||||
'0000000000000000000000000000000000000000000000000000000000000002',
|
||||
'hex'
|
||||
);
|
||||
|
||||
regtest.halvingInterval = 150;
|
||||
|
||||
@ -836,6 +855,10 @@ simnet.port = 18555;
|
||||
simnet.checkpointMap = {};
|
||||
|
||||
simnet.lastCheckpoint = 0;
|
||||
simnet.lastChainwork = new BN(
|
||||
'0000000000000000000000000000000000000000000000000000000000000002',
|
||||
'hex'
|
||||
);
|
||||
|
||||
simnet.halvingInterval = 210000;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user