chain/pool: make checkpoints option permanent.

This commit is contained in:
Christopher Jeffrey 2017-08-02 15:23:10 -07:00
parent 1b8115d03f
commit bb6110c609
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
7 changed files with 13 additions and 91 deletions

View File

@ -71,7 +71,6 @@ function Chain(options) {
this.network = this.options.network;
this.logger = this.options.logger.context('chain');
this.workers = this.options.workers;
this.checkpoints = this.options.checkpoints;
this.locker = new Lock(true);
this.invalid = new LRU(100);
@ -490,6 +489,11 @@ Chain.prototype.getDeployments = async function getDeployments(time, prev) {
*/
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())
this.logger.warning('P2SH has been activated.');
@ -1472,9 +1476,6 @@ Chain.prototype.verifyCheckpoint = function verifyCheckpoint(prev, hash) {
if (!this.options.checkpoints)
return true;
if (!this.checkpoints && !this.options.enforceCheckpoints)
return true;
const height = prev.height + 1;
const checkpoint = this.network.checkpointMap[height];
@ -1801,12 +1802,9 @@ Chain.prototype.maybeSync = function maybeSync() {
if (this.synced)
return;
if (this.checkpoints) {
if (!this.hasCheckpoints())
if (this.options.checkpoints) {
if (this.height < this.network.lastCheckpoint)
return;
this.logger.info('Last checkpoint reached. Disabling checkpoints.');
this.checkpoints = false;
}
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);
};
/**
* 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.
* @returns {Number} percent - Ranges from 0.0 to 1.0.
@ -2418,7 +2405,6 @@ function ChainOptions(options) {
this.entryCache = 5000;
this.maxOrphans = 20;
this.checkpoints = true;
this.enforceCheckpoints = false;
if (options)
this.fromOptions(options);
@ -2533,11 +2519,6 @@ 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;
};

View File

@ -311,7 +311,7 @@ ChainEntry.prototype.getMedianTime = async function getMedianTime(time) {
*/
ChainEntry.prototype.isHistorical = function isHistorical() {
if (this.chain.checkpoints) {
if (this.chain.options.checkpoints) {
if (this.height + 1 <= this.chain.network.lastCheckpoint)
return true;
}

View File

@ -104,7 +104,6 @@ function Pool(options) {
this.headerChain = new List();
this.headerNext = null;
this.headerTip = null;
this.headerFails = 0;
this.peers = new PeerList();
this.authdb = new BIP150.AuthDB(this.options);
@ -122,15 +121,6 @@ function Pool(options) {
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.
* @const {Number}
@ -246,15 +236,14 @@ Pool.prototype.resetChain = function resetChain() {
return;
this.checkpoints = false;
this.chain.checkpoints = false;
this.headerTip = null;
this.headerChain.reset();
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.chain.checkpoints = true;
this.headerTip = this.getNextTip(tip.height);
this.headerChain.push(new HeaderEntry(tip.hash, tip.height));
this.logger.info(
@ -365,7 +354,6 @@ Pool.prototype._disconnect = async function _disconnect() {
}
this.checkpoints = false;
this.chain.checkpoints = false;
this.headerTip = null;
this.headerChain.reset();
this.headerNext = null;
@ -2117,17 +2105,7 @@ Pool.prototype._handleHeaders = async function _handleHeaders(peer, packet) {
this.logger.warning(
'Peer sent a bad header chain (%s).',
peer.hostname());
if (++this.headerFails < Pool.MAX_HEADER_FAILS) {
peer.destroy();
return;
}
this.logger.warning(
'Switching to getblocks (%s).',
peer.hostname());
await this.switchSync(peer);
peer.destroy();
return;
}
@ -2138,17 +2116,7 @@ Pool.prototype._handleHeaders = async function _handleHeaders(peer, packet) {
this.logger.warning(
'Peer sent an invalid checkpoint (%s).',
peer.hostname());
if (++this.headerFails < Pool.MAX_HEADER_FAILS) {
peer.destroy();
return;
}
this.logger.warning(
'Switching to getblocks (%s).',
peer.hostname());
await this.switchSync(peer);
peer.destroy();
return;
}
checkpoint = true;
@ -2383,7 +2351,6 @@ Pool.prototype.switchSync = async function switchSync(peer, hash) {
assert(this.checkpoints);
this.checkpoints = false;
this.chain.checkpoints = false;
this.headerTip = null;
this.headerChain.reset();
this.headerNext = null;

View File

@ -61,7 +61,6 @@ 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'),

View File

@ -54,7 +54,6 @@ 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

View File

@ -32,7 +32,6 @@ 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;

View File

@ -112,17 +112,6 @@ main.checkpointMap = {
main.lastCheckpoint = 470000;
/**
* Last checkpoint chainwork.
* @const {BN}
* @default
*/
main.lastChainwork = new BN(
'0000000000000000000000000000000000000000005dcc420d5bcce89a5d0d04',
'hex'
);
/**
* @const {Number}
* @default
@ -524,10 +513,6 @@ testnet.checkpointMap = {
};
testnet.lastCheckpoint = 1050000;
testnet.lastChainwork = new BN(
'00000000000000000000000000000000000000000000001a461538dc48da1a06',
'hex'
);
testnet.halvingInterval = 210000;
@ -689,10 +674,6 @@ regtest.port = 48444;
regtest.checkpointMap = {};
regtest.lastCheckpoint = 0;
regtest.lastChainwork = new BN(
'0000000000000000000000000000000000000000000000000000000000000002',
'hex'
);
regtest.halvingInterval = 150;
@ -855,10 +836,6 @@ simnet.port = 18555;
simnet.checkpointMap = {};
simnet.lastCheckpoint = 0;
simnet.lastChainwork = new BN(
'0000000000000000000000000000000000000000000000000000000000000002',
'hex'
);
simnet.halvingInterval = 210000;