chain/pool: make checkpoints option permanent.
This commit is contained in:
parent
1b8115d03f
commit
bb6110c609
@ -71,7 +71,6 @@ function Chain(options) {
|
|||||||
this.network = this.options.network;
|
this.network = this.options.network;
|
||||||
this.logger = this.options.logger.context('chain');
|
this.logger = this.options.logger.context('chain');
|
||||||
this.workers = this.options.workers;
|
this.workers = this.options.workers;
|
||||||
this.checkpoints = this.options.checkpoints;
|
|
||||||
|
|
||||||
this.locker = new Lock(true);
|
this.locker = new Lock(true);
|
||||||
this.invalid = new LRU(100);
|
this.invalid = new LRU(100);
|
||||||
@ -490,6 +489,11 @@ Chain.prototype.getDeployments = async function getDeployments(time, prev) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Chain.prototype.setDeploymentState = function setDeploymentState(state) {
|
Chain.prototype.setDeploymentState = function setDeploymentState(state) {
|
||||||
|
if (this.options.checkpoints && this.height < this.network.lastCheckpoint) {
|
||||||
|
this.state = state;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.state.hasP2SH() && state.hasP2SH())
|
if (!this.state.hasP2SH() && state.hasP2SH())
|
||||||
this.logger.warning('P2SH has been activated.');
|
this.logger.warning('P2SH has been activated.');
|
||||||
|
|
||||||
@ -1472,9 +1476,6 @@ Chain.prototype.verifyCheckpoint = function verifyCheckpoint(prev, hash) {
|
|||||||
if (!this.options.checkpoints)
|
if (!this.options.checkpoints)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!this.checkpoints && !this.options.enforceCheckpoints)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
const height = prev.height + 1;
|
const height = prev.height + 1;
|
||||||
const checkpoint = this.network.checkpointMap[height];
|
const checkpoint = this.network.checkpointMap[height];
|
||||||
|
|
||||||
@ -1801,12 +1802,9 @@ Chain.prototype.maybeSync = function maybeSync() {
|
|||||||
if (this.synced)
|
if (this.synced)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (this.checkpoints) {
|
if (this.options.checkpoints) {
|
||||||
if (!this.hasCheckpoints())
|
if (this.height < this.network.lastCheckpoint)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
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)
|
||||||
@ -1830,17 +1828,6 @@ Chain.prototype.hasChainwork = function hasChainwork() {
|
|||||||
return this.tip.chainwork.gte(this.network.pow.chainwork);
|
return this.tip.chainwork.gte(this.network.pow.chainwork);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.gte(this.network.lastChainwork);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the fill percentage.
|
* Get the fill percentage.
|
||||||
* @returns {Number} percent - Ranges from 0.0 to 1.0.
|
* @returns {Number} percent - Ranges from 0.0 to 1.0.
|
||||||
@ -2418,7 +2405,6 @@ 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);
|
||||||
@ -2533,11 +2519,6 @@ 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -311,7 +311,7 @@ ChainEntry.prototype.getMedianTime = async function getMedianTime(time) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ChainEntry.prototype.isHistorical = function isHistorical() {
|
ChainEntry.prototype.isHistorical = function isHistorical() {
|
||||||
if (this.chain.checkpoints) {
|
if (this.chain.options.checkpoints) {
|
||||||
if (this.height + 1 <= this.chain.network.lastCheckpoint)
|
if (this.height + 1 <= this.chain.network.lastCheckpoint)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -104,7 +104,6 @@ function Pool(options) {
|
|||||||
this.headerChain = new List();
|
this.headerChain = new List();
|
||||||
this.headerNext = null;
|
this.headerNext = null;
|
||||||
this.headerTip = null;
|
this.headerTip = null;
|
||||||
this.headerFails = 0;
|
|
||||||
|
|
||||||
this.peers = new PeerList();
|
this.peers = new PeerList();
|
||||||
this.authdb = new BIP150.AuthDB(this.options);
|
this.authdb = new BIP150.AuthDB(this.options);
|
||||||
@ -122,15 +121,6 @@ function Pool(options) {
|
|||||||
|
|
||||||
util.inherits(Pool, AsyncObject);
|
util.inherits(Pool, AsyncObject);
|
||||||
|
|
||||||
/**
|
|
||||||
* Max number of header chain failures
|
|
||||||
* before disabling checkpoints.
|
|
||||||
* @const {Number}
|
|
||||||
* @default
|
|
||||||
*/
|
|
||||||
|
|
||||||
Pool.MAX_HEADER_FAILS = 1000;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Discovery interval for UPNP and DNS seeds.
|
* Discovery interval for UPNP and DNS seeds.
|
||||||
* @const {Number}
|
* @const {Number}
|
||||||
@ -246,15 +236,14 @@ Pool.prototype.resetChain = function resetChain() {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
this.checkpoints = false;
|
this.checkpoints = false;
|
||||||
this.chain.checkpoints = false;
|
|
||||||
this.headerTip = null;
|
this.headerTip = null;
|
||||||
this.headerChain.reset();
|
this.headerChain.reset();
|
||||||
this.headerNext = null;
|
this.headerNext = null;
|
||||||
|
|
||||||
if (!this.chain.hasCheckpoints()) {
|
const tip = this.chain.tip;
|
||||||
const tip = this.chain.tip;
|
|
||||||
|
if (tip.height < this.network.lastCheckpoint) {
|
||||||
this.checkpoints = true;
|
this.checkpoints = true;
|
||||||
this.chain.checkpoints = true;
|
|
||||||
this.headerTip = this.getNextTip(tip.height);
|
this.headerTip = this.getNextTip(tip.height);
|
||||||
this.headerChain.push(new HeaderEntry(tip.hash, tip.height));
|
this.headerChain.push(new HeaderEntry(tip.hash, tip.height));
|
||||||
this.logger.info(
|
this.logger.info(
|
||||||
@ -365,7 +354,6 @@ Pool.prototype._disconnect = async function _disconnect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.checkpoints = false;
|
this.checkpoints = false;
|
||||||
this.chain.checkpoints = false;
|
|
||||||
this.headerTip = null;
|
this.headerTip = null;
|
||||||
this.headerChain.reset();
|
this.headerChain.reset();
|
||||||
this.headerNext = null;
|
this.headerNext = null;
|
||||||
@ -2117,17 +2105,7 @@ Pool.prototype._handleHeaders = async function _handleHeaders(peer, packet) {
|
|||||||
this.logger.warning(
|
this.logger.warning(
|
||||||
'Peer sent a bad header chain (%s).',
|
'Peer sent a bad header chain (%s).',
|
||||||
peer.hostname());
|
peer.hostname());
|
||||||
|
peer.destroy();
|
||||||
if (++this.headerFails < Pool.MAX_HEADER_FAILS) {
|
|
||||||
peer.destroy();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.warning(
|
|
||||||
'Switching to getblocks (%s).',
|
|
||||||
peer.hostname());
|
|
||||||
|
|
||||||
await this.switchSync(peer);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2138,17 +2116,7 @@ Pool.prototype._handleHeaders = async function _handleHeaders(peer, packet) {
|
|||||||
this.logger.warning(
|
this.logger.warning(
|
||||||
'Peer sent an invalid checkpoint (%s).',
|
'Peer sent an invalid checkpoint (%s).',
|
||||||
peer.hostname());
|
peer.hostname());
|
||||||
|
peer.destroy();
|
||||||
if (++this.headerFails < Pool.MAX_HEADER_FAILS) {
|
|
||||||
peer.destroy();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.warning(
|
|
||||||
'Switching to getblocks (%s).',
|
|
||||||
peer.hostname());
|
|
||||||
|
|
||||||
await this.switchSync(peer);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
checkpoint = true;
|
checkpoint = true;
|
||||||
@ -2383,7 +2351,6 @@ Pool.prototype.switchSync = async function switchSync(peer, hash) {
|
|||||||
assert(this.checkpoints);
|
assert(this.checkpoints);
|
||||||
|
|
||||||
this.checkpoints = false;
|
this.checkpoints = false;
|
||||||
this.chain.checkpoints = false;
|
|
||||||
this.headerTip = null;
|
this.headerTip = null;
|
||||||
this.headerChain.reset();
|
this.headerChain.reset();
|
||||||
this.headerNext = null;
|
this.headerNext = null;
|
||||||
|
|||||||
@ -61,7 +61,6 @@ 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,7 +54,6 @@ 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
|
||||||
|
|||||||
@ -32,7 +32,6 @@ function Network(options) {
|
|||||||
this.port = options.port;
|
this.port = options.port;
|
||||||
this.checkpointMap = options.checkpointMap;
|
this.checkpointMap = options.checkpointMap;
|
||||||
this.lastCheckpoint = options.lastCheckpoint;
|
this.lastCheckpoint = options.lastCheckpoint;
|
||||||
this.lastChainwork = options.lastChainwork;
|
|
||||||
this.checkpoints = [];
|
this.checkpoints = [];
|
||||||
this.halvingInterval = options.halvingInterval;
|
this.halvingInterval = options.halvingInterval;
|
||||||
this.genesis = options.genesis;
|
this.genesis = options.genesis;
|
||||||
|
|||||||
@ -112,17 +112,6 @@ main.checkpointMap = {
|
|||||||
|
|
||||||
main.lastCheckpoint = 470000;
|
main.lastCheckpoint = 470000;
|
||||||
|
|
||||||
/**
|
|
||||||
* Last checkpoint chainwork.
|
|
||||||
* @const {BN}
|
|
||||||
* @default
|
|
||||||
*/
|
|
||||||
|
|
||||||
main.lastChainwork = new BN(
|
|
||||||
'0000000000000000000000000000000000000000005dcc420d5bcce89a5d0d04',
|
|
||||||
'hex'
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @const {Number}
|
* @const {Number}
|
||||||
* @default
|
* @default
|
||||||
@ -524,10 +513,6 @@ testnet.checkpointMap = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
testnet.lastCheckpoint = 1050000;
|
testnet.lastCheckpoint = 1050000;
|
||||||
testnet.lastChainwork = new BN(
|
|
||||||
'00000000000000000000000000000000000000000000001a461538dc48da1a06',
|
|
||||||
'hex'
|
|
||||||
);
|
|
||||||
|
|
||||||
testnet.halvingInterval = 210000;
|
testnet.halvingInterval = 210000;
|
||||||
|
|
||||||
@ -689,10 +674,6 @@ regtest.port = 48444;
|
|||||||
|
|
||||||
regtest.checkpointMap = {};
|
regtest.checkpointMap = {};
|
||||||
regtest.lastCheckpoint = 0;
|
regtest.lastCheckpoint = 0;
|
||||||
regtest.lastChainwork = new BN(
|
|
||||||
'0000000000000000000000000000000000000000000000000000000000000002',
|
|
||||||
'hex'
|
|
||||||
);
|
|
||||||
|
|
||||||
regtest.halvingInterval = 150;
|
regtest.halvingInterval = 150;
|
||||||
|
|
||||||
@ -855,10 +836,6 @@ simnet.port = 18555;
|
|||||||
simnet.checkpointMap = {};
|
simnet.checkpointMap = {};
|
||||||
|
|
||||||
simnet.lastCheckpoint = 0;
|
simnet.lastCheckpoint = 0;
|
||||||
simnet.lastChainwork = new BN(
|
|
||||||
'0000000000000000000000000000000000000000000000000000000000000002',
|
|
||||||
'hex'
|
|
||||||
);
|
|
||||||
|
|
||||||
simnet.halvingInterval = 210000;
|
simnet.halvingInterval = 210000;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user