Skip to content

Commit

Permalink
Fix: updated the sync progress function
Browse files Browse the repository at this point in the history
  • Loading branch information
masterchief164 committed Jan 24, 2023
1 parent 69d689a commit b4e4934
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/blockchain/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/protocol/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions lib/protocol/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ main.checkpointMap = {

main.lastCheckpoint = 525000;

main.txnData = {
rate: 2.925802860942233,
time: 1661697692,
count: 760120522
};

/**
* @const {Number}
* @default
Expand Down Expand Up @@ -559,6 +565,12 @@ testnet.checkpointMap = {

testnet.lastCheckpoint = 1050000;

testnet.txnData = {
rate: 0.1079119341520164,
time: 1661705221,
count: 63531852
};

testnet.halvingInterval = 210000;

testnet.genesis = {
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -885,6 +903,12 @@ simnet.checkpointMap = {};

simnet.lastCheckpoint = 0;

simnet.txnData = {
time: 0,
count: 0,
rate: 0
};

simnet.halvingInterval = 210000;

simnet.genesis = {
Expand Down

0 comments on commit b4e4934

Please sign in to comment.