network: add minimum chainworks.

This commit is contained in:
Christopher Jeffrey 2017-01-08 23:05:54 -08:00
parent 59db7a5498
commit f58e748263
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 31 additions and 15 deletions

View File

@ -1731,18 +1731,6 @@ Chain.prototype.isFull = function isFull(force) {
return !this.isInitial(force); return !this.isInitial(force);
}; };
/**
* Potentially emit a `sync` event.
* @private
*/
Chain.prototype.maybeSync = function maybeSync() {
if (!this.synced && this.isFull()) {
this.synced = true;
this.emit('full');
}
};
/** /**
* Test the chain to see if it is still in the initial * Test the chain to see if it is still in the initial
* syncing phase. Mimic's bitcoind's `IsInitialBlockDownload()` * syncing phase. Mimic's bitcoind's `IsInitialBlockDownload()`
@ -1758,7 +1746,7 @@ Chain.prototype.isInitial = function isInitial(force) {
if (this.height < this.network.checkpoints.lastHeight) if (this.height < this.network.checkpoints.lastHeight)
return true; return true;
if (this.height < this.bestHeight - 24 * 6) if (this.tip.chainwork.cmp(this.network.pow.chainwork) < 0)
return true; return true;
if (this.tip.ts < util.now() - this.network.block.maxTipAge) if (this.tip.ts < util.now() - this.network.block.maxTipAge)
@ -1767,6 +1755,18 @@ Chain.prototype.isInitial = function isInitial(force) {
return false; return false;
}; };
/**
* Potentially emit a `sync` event.
* @private
*/
Chain.prototype.maybeSync = function maybeSync() {
if (!this.synced && this.isFull()) {
this.synced = true;
this.emit('full');
}
};
/** /**
* 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.

View File

@ -180,6 +180,16 @@ main.pow = {
bits: 486604799, bits: 486604799,
/**
* Minimum chainwork for best chain.
* @const {BN}
*/
chainwork: new BN(
'0000000000000000000000000000000000000000002cb971dd56d1c583c20f90',
'hex'
),
/** /**
* Default retarget interval. * Default retarget interval.
* @const {Number} * @const {Number}
@ -550,6 +560,10 @@ testnet.pow = {
'hex' 'hex'
), ),
bits: 486604799, bits: 486604799,
chainwork: new BN(
'0000000000000000000000000000000000000000000000198b4def2baa9338d6',
'hex'
),
targetTimespan: 14 * 24 * 60 * 60, // two weeks targetTimespan: 14 * 24 * 60 * 60, // two weeks
targetSpacing: 10 * 60, targetSpacing: 10 * 60,
retargetInterval: 2016, retargetInterval: 2016,
@ -709,6 +723,7 @@ regtest.pow = {
'hex' 'hex'
), ),
bits: 545259519, bits: 545259519,
chainwork: new BN(0),
targetTimespan: 14 * 24 * 60 * 60, // two weeks targetTimespan: 14 * 24 * 60 * 60, // two weeks
targetSpacing: 10 * 60, targetSpacing: 10 * 60,
retargetInterval: 2016, retargetInterval: 2016,
@ -864,6 +879,7 @@ segnet4.pow = {
'hex' 'hex'
), ),
bits: 503447551, bits: 503447551,
chainwork: new BN(0),
targetTimespan: 14 * 24 * 60 * 60, // two weeks targetTimespan: 14 * 24 * 60 * 60, // two weeks
targetSpacing: 10 * 60, targetSpacing: 10 * 60,
retargetInterval: 2016, retargetInterval: 2016,
@ -912,7 +928,7 @@ segnet4.deployments = {
name: 'segwit', name: 'segwit',
bit: 1, bit: 1,
startTime: 0, startTime: 0,
timeout: 999999999999, timeout: 0xffffffff,
force: false force: false
} }
}; };
@ -1038,7 +1054,7 @@ simnet.block = {
simnet.bip30 = {}; simnet.bip30 = {};
simnet.witness = false; simnet.witness = true;
simnet.activationThreshold = 1512; // 75% for testchains simnet.activationThreshold = 1512; // 75% for testchains