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);
};
/**
* 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
* syncing phase. Mimic's bitcoind's `IsInitialBlockDownload()`
@ -1758,7 +1746,7 @@ Chain.prototype.isInitial = function isInitial(force) {
if (this.height < this.network.checkpoints.lastHeight)
return true;
if (this.height < this.bestHeight - 24 * 6)
if (this.tip.chainwork.cmp(this.network.pow.chainwork) < 0)
return true;
if (this.tip.ts < util.now() - this.network.block.maxTipAge)
@ -1767,6 +1755,18 @@ Chain.prototype.isInitial = function isInitial(force) {
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.
* @returns {Number} percent - Ranges from 0.0 to 1.0.

View File

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