From b4e4934b85447ca566177ccd1362f86546a56ac5 Mon Sep 17 00:00:00 2001 From: Shaswat Gupta <63920595+masterchief164@users.noreply.github.com> Date: Sat, 3 Dec 2022 19:48:52 +0530 Subject: [PATCH] Fix: updated the sync progress function --- lib/blockchain/chain.js | 10 ++++++---- lib/protocol/network.js | 1 + lib/protocol/networks.js | 24 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js index 7bc2fab2e..49338d1f5 100644 --- a/lib/blockchain/chain.js +++ b/lib/blockchain/chain.js @@ -2034,10 +2034,12 @@ class Chain extends AsyncEmitter { */ getProgress() { - const start = this.network.genesis.time; - const current = this.tip.time - start; - const end = util.now() - start - 40 * 60; - return Math.min(1, current / end); + const time = util.now(); + const rate = this.network.txnData.rate; + const lastTime = this.network.txnData.time; + const current = this.db.state.tx; + const end = this.network.txnData.count + (time - lastTime) * rate; + return Math.min(current / end, 1.0); } /** diff --git a/lib/protocol/network.js b/lib/protocol/network.js index 27d8f6061..6dad276c1 100644 --- a/lib/protocol/network.js +++ b/lib/protocol/network.js @@ -36,6 +36,7 @@ class Network { this.port = options.port; this.checkpointMap = options.checkpointMap; this.lastCheckpoint = options.lastCheckpoint; + this.txnData = options.txnData; this.checkpoints = []; this.halvingInterval = options.halvingInterval; this.genesis = options.genesis; diff --git a/lib/protocol/networks.js b/lib/protocol/networks.js index 235627ccf..16e6bedf7 100644 --- a/lib/protocol/networks.js +++ b/lib/protocol/networks.js @@ -127,6 +127,12 @@ main.checkpointMap = { main.lastCheckpoint = 525000; +main.txnData = { + rate: 2.925802860942233, + time: 1661697692, + count: 760120522 +}; + /** * @const {Number} * @default @@ -559,6 +565,12 @@ testnet.checkpointMap = { testnet.lastCheckpoint = 1050000; +testnet.txnData = { + rate: 0.1079119341520164, + time: 1661705221, + count: 63531852 +}; + testnet.halvingInterval = 210000; testnet.genesis = { @@ -722,6 +734,12 @@ regtest.port = 48444; regtest.checkpointMap = {}; regtest.lastCheckpoint = 0; +regtest.txnData = { + rate: 0, + time: 0, + count: 0 +}; + regtest.halvingInterval = 150; regtest.genesis = { @@ -885,6 +903,12 @@ simnet.checkpointMap = {}; simnet.lastCheckpoint = 0; +simnet.txnData = { + time: 0, + count: 0, + rate: 0 +}; + simnet.halvingInterval = 210000; simnet.genesis = {