@@ -27,7 +27,7 @@ var WS_SECRET = process.env.WS_SECRET || "eth-net-stats-has-a-secret";
27
27
28
28
var PENDING_WORKS = true ;
29
29
var MAX_BLOCKS_HISTORY = 40 ;
30
- var UPDATE_INTERVAL = 1000 ;
30
+ var UPDATE_INTERVAL = process . env . UPDATE_INTERVAL || 1000 ;
31
31
var PING_INTERVAL = 3000 ;
32
32
var MINERS_LIMIT = 5 ;
33
33
var MAX_HISTORY_UPDATE = 50 ;
@@ -37,7 +37,7 @@ var CONNECTION_ATTEMPTS_TIMEOUT = 1000;
37
37
// RPC call protection
38
38
var RPC_LOCKED = false ;
39
39
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
41
41
var lastRpcLockTime = 0 ;
42
42
43
43
// Soft start protection
@@ -96,10 +96,11 @@ function Node ()
96
96
active : false ,
97
97
mining : false ,
98
98
peers : 0 ,
99
- currentView : 0 ,
100
- nextViewChange : 0 ,
101
- highQcView : 0 ,
99
+ currentView : 0 ,
100
+ nextViewChange : 0 ,
101
+ highQcView : 0 ,
102
102
pending : 0 ,
103
+ queued : 0 ,
103
104
gasPrice : 0 ,
104
105
block : {
105
106
number : 0 ,
@@ -117,6 +118,7 @@ function Node ()
117
118
this . _lastStats = JSON . stringify ( this . stats ) ;
118
119
this . _lastFetch = 0 ;
119
120
this . _lastPending = 0 ;
121
+ this . _lastQueued = 0 ;
120
122
121
123
this . _tries = 0 ;
122
124
this . _down = 0 ;
@@ -457,9 +459,9 @@ Node.prototype.setInactive = function()
457
459
{
458
460
this . stats . active = false ;
459
461
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 ;
463
465
this . stats . mining = false ;
464
466
this . _down ++ ;
465
467
@@ -686,10 +688,16 @@ Node.prototype.getPending = function()
686
688
687
689
if ( this . _web3 )
688
690
{
689
- console . stats ( '==>' , 'Getting Pending' )
691
+ console . stats ( '==>' , 'Getting Pending and Queued ' )
690
692
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 ) {
693
701
if ( err ) {
694
702
console . error ( 'xx>' , 'getPending error: ' , err ) ;
695
703
return false ;
@@ -699,14 +707,25 @@ Node.prototype.getPending = function()
699
707
results . end = _ . now ( ) ;
700
708
results . diff = results . end - now ;
701
709
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 ) ;
703
714
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' ) ) ;
705
716
706
- if ( self . _lastPending !== pending )
707
- self . sendPendingUpdate ( ) ;
717
+ self . stats . pending = pending ;
718
+ self . stats . queued = queued ;
708
719
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
+ }
710
729
} ) ;
711
730
}
712
731
}
@@ -776,7 +795,8 @@ Node.prototype.preparePending = function ()
776
795
return {
777
796
id : this . id ,
778
797
stats : {
779
- pending : this . stats . pending
798
+ pending : this . stats . pending ,
799
+ queued : this . stats . queued
780
800
}
781
801
} ;
782
802
}
0 commit comments