Skip to content

Commit

Permalink
Fix: added txn data for multiple networks
Browse files Browse the repository at this point in the history
  • Loading branch information
masterchief164 committed Jan 24, 2023
1 parent 0af2164 commit ef0fdd8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/blockchain/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ class Chain extends AsyncEmitter {
// UASF is now enforced (bip148) (mainnet-only).
if (this.options.bip148 && this.network === Network.main) {
if (witness !== thresholdStates.LOCKED_IN
&& witness !== thresholdStates.ACTIVE) {
&& witness !== thresholdStates.ACTIVE) {
// The BIP148 MTP check is nonsensical in
// that it includes the _current_ entry's
// timestamp. This requires some hackery,
Expand Down Expand Up @@ -2034,11 +2034,11 @@ class Chain extends AsyncEmitter {
*/

getProgress() {
const time = util.now();
const rate = 271416 / (24 * 60 * 60);
const lastTime = 1672074795;
const time = util.now();
const rate = this.network.txnData.rate;
const lastTime = this.network.txnData.time;
const current = this.db.state.tx;
const end = 791077253 + (time - lastTime) * rate;
const end = this.network.txnData.count + (time - lastTime) * rate;
return current / end;
}

Expand Down Expand Up @@ -2126,7 +2126,7 @@ class Chain extends AsyncEmitter {

assert(hash);

for (;;) {
for (; ;) {
const orphan = this.orphanMap.get(hash);

if (!orphan)
Expand Down Expand Up @@ -2203,8 +2203,8 @@ class Chain extends AsyncEmitter {
return pow.bits;

while (prev.height !== 0
&& prev.height % pow.retargetInterval !== 0
&& prev.bits === pow.bits) {
&& prev.height % pow.retargetInterval !== 0
&& prev.bits === pow.bits) {
const cache = this.getPrevCache(prev);

if (cache)
Expand Down Expand Up @@ -2437,7 +2437,7 @@ class Chain extends AsyncEmitter {
const state = await this.getState(prev, deployment);

if (state === thresholdStates.LOCKED_IN
|| state === thresholdStates.STARTED) {
|| state === thresholdStates.STARTED) {
version |= 1 << deployment.bit;
}
}
Expand Down Expand Up @@ -2621,7 +2621,7 @@ class ChainOptions {
fromOptions(options) {
if (!options.spv) {
assert(options.blocks && typeof options.blocks === 'object',
'Chain requires a blockstore.');
'Chain requires a blockstore.');
}

this.blocks = options.blocks;
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 ef0fdd8

Please sign in to comment.