From f58e748263a94afae4cd33b5fc12bee8897b8225 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 8 Jan 2017 23:05:54 -0800 Subject: [PATCH] network: add minimum chainworks. --- lib/blockchain/chain.js | 26 +++++++++++++------------- lib/protocol/networks.js | 20 ++++++++++++++++++-- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js index b9bdbe9b..7f4204f8 100644 --- a/lib/blockchain/chain.js +++ b/lib/blockchain/chain.js @@ -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. diff --git a/lib/protocol/networks.js b/lib/protocol/networks.js index d9313dd7..f06bb610 100644 --- a/lib/protocol/networks.js +++ b/lib/protocol/networks.js @@ -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