Skip to content

Commit 7d99012

Browse files
authored
feat: DEVOPS-2042 add pending and queued transactions (#13)
1 parent 37b0f9b commit 7d99012

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed

docker-compose.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ services:
2525
build:
2626
context: ../ethstats-server
2727
dockerfile: Dockerfile
28-
image: zilstats-server:latest
28+
# image: zilstats-server:latest
2929
platform: linux/amd64
3030
ports:
3131
- "3000:3000"
@@ -40,19 +40,20 @@ services:
4040
- dashboard
4141
#- node0
4242
environment:
43-
RPC_HOST: zq2-prototestnet-validator-ase1-0-80f5.zq2.dev #"198.51.100.103"
43+
RPC_HOST: zq2-devnet-api-ase1-0-b549.zq2.dev #"198.51.100.103"
4444
RPC_PORT: "4202"
4545
LISTENING_PORT: "3333"
46-
INSTANCE_NAME: "zq2-prototestnet-validator-ase1-0-80f5"
46+
INSTANCE_NAME: "zq2-devnet-api-ase1-0-b549"
4747
CONTACT_DETAILS: "[email protected]"
48+
WS_PORT: "4202"
4849
WS_SERVER: "ws://198.51.100.10:3000"
4950
WS_SECRET: "mysecret"
5051
VERBOSITY: "2"
5152
container_name: client0
5253
build:
5354
context: .
5455
dockerfile: Dockerfile.zilliqa
55-
image: zilstats-client:latest
56+
# image: zilstats-client:latest
5657
networks:
5758
testnet:
5859
ipv4_address: 198.51.100.50

lib/node.js

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var WS_SECRET = process.env.WS_SECRET || "eth-net-stats-has-a-secret";
2727

2828
var PENDING_WORKS = true;
2929
var MAX_BLOCKS_HISTORY = 40;
30-
var UPDATE_INTERVAL = 1000;
30+
var UPDATE_INTERVAL = process.env.UPDATE_INTERVAL || 1000;
3131
var PING_INTERVAL = 3000;
3232
var MINERS_LIMIT = 5;
3333
var MAX_HISTORY_UPDATE = 50;
@@ -37,7 +37,7 @@ var CONNECTION_ATTEMPTS_TIMEOUT = 1000;
3737
// RPC call protection
3838
var RPC_LOCKED = false;
3939
var RPC_LOCK_TIMEOUT = 10000; // 10 seconds lock
40-
var RPC_SLOW_THRESHOLD = 2000; // 2 seconds threshold
40+
var RPC_SLOW_THRESHOLD = process.env.RPC_SLOW_THRESHOLD || 2000; // 2 seconds threshold
4141
var lastRpcLockTime = 0;
4242

4343
// Soft start protection
@@ -96,10 +96,11 @@ function Node ()
9696
active: false,
9797
mining: false,
9898
peers: 0,
99-
currentView: 0,
100-
nextViewChange: 0,
101-
highQcView: 0,
99+
currentView: 0,
100+
nextViewChange: 0,
101+
highQcView: 0,
102102
pending: 0,
103+
queued: 0,
103104
gasPrice: 0,
104105
block: {
105106
number: 0,
@@ -117,6 +118,7 @@ function Node ()
117118
this._lastStats = JSON.stringify(this.stats);
118119
this._lastFetch = 0;
119120
this._lastPending = 0;
121+
this._lastQueued = 0;
120122

121123
this._tries = 0;
122124
this._down = 0;
@@ -457,9 +459,9 @@ Node.prototype.setInactive = function()
457459
{
458460
this.stats.active = false;
459461
this.stats.peers = 0;
460-
this.currentView = 0;
461-
this.nextViewChange = 0;
462-
this.highQcView = 0;
462+
this.stats.currentView = 0;
463+
this.stats.nextViewChange = 0;
464+
this.stats.highQcView = 0;
463465
this.stats.mining = false;
464466
this._down++;
465467

@@ -686,10 +688,16 @@ Node.prototype.getPending = function()
686688

687689
if (this._web3)
688690
{
689-
console.stats('==>', 'Getting Pending')
691+
console.stats('==>', 'Getting Pending and Queued')
690692

691-
web3.eth.getBlockTransactionCount('pending', function (err, pending)
692-
{
693+
const payload = {
694+
jsonrpc: "2.0",
695+
method: "txpool_status",
696+
params: [],
697+
id: 1
698+
};
699+
700+
web3.currentProvider.sendAsync(payload, function (err, response) {
693701
if (err) {
694702
console.error('xx>', 'getPending error: ', err);
695703
return false;
@@ -699,14 +707,25 @@ Node.prototype.getPending = function()
699707
results.end = _.now();
700708
results.diff = results.end - now;
701709

702-
console.sstats('==>', 'Got', chalk.reset.red(pending) , chalk.reset.bold.green('pending tx'+ (pending === 1 ? '' : 's') + ' in'), chalk.reset.cyan(results.diff, 'ms'));
710+
try {
711+
// Values are already in decimal format
712+
const pending = parseInt(response.result.pending);
713+
const queued = parseInt(response.result.queued);
703714

704-
self.stats.pending = pending;
715+
console.sstats('==>', 'Got', chalk.reset.red(pending), chalk.reset.bold.green('pending tx' + (pending === 1 ? '' : 's')), 'and', chalk.reset.red(queued), chalk.reset.bold.green('queued tx' + (queued === 1 ? '' : 's')), 'in', chalk.reset.cyan(results.diff, 'ms'));
705716

706-
if(self._lastPending !== pending)
707-
self.sendPendingUpdate();
717+
self.stats.pending = pending;
718+
self.stats.queued = queued;
708719

709-
self._lastPending = pending;
720+
if(self._lastPending !== pending || self._lastQueued !== queued)
721+
self.sendPendingUpdate();
722+
723+
self._lastPending = pending;
724+
self._lastQueued = queued;
725+
} catch (e) {
726+
console.error('xx>', 'Error parsing txpool_status response:', e);
727+
console.error('xx>', 'Response was:', response);
728+
}
710729
});
711730
}
712731
}
@@ -776,7 +795,8 @@ Node.prototype.preparePending = function ()
776795
return {
777796
id: this.id,
778797
stats: {
779-
pending: this.stats.pending
798+
pending: this.stats.pending,
799+
queued: this.stats.queued
780800
}
781801
};
782802
}

0 commit comments

Comments
 (0)