Skip to content

Commit ec28777

Browse files
authored
feat: track queued txs along with pending (#206)
* feat: track queued txs along with pending * remove GetTxPoolSize util function
1 parent 556cd54 commit ec28777

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

cmd/loadtest/loadtest.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,13 @@ func updateRateLimit(ctx context.Context, rl *rate.Limiter, rpc *ethrpc.Client,
408408
for {
409409
select {
410410
case <-ticker.C:
411-
txPoolSize, err := util.GetTxPoolSize(rpc)
411+
pendingTx, queuedTx, err := util.GetTxPoolStatus(rpc)
412412
if err != nil {
413413
log.Error().Err(err).Msg("Error getting txpool size")
414414
return
415415
}
416416

417+
txPoolSize := pendingTx + queuedTx
417418
if txPoolSize < steadyStateQueueSize {
418419
// additively increment requests per second if txpool less than queue steady state
419420
newRateLimit := rate.Limit(float64(rl.Limit()) + float64(rateLimitIncrement))

cmd/monitor/monitor.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type (
6565
PeerCount uint64
6666
GasPrice *big.Int
6767
PendingCount uint64
68+
QueuedCount uint64
6869
SelectedBlock rpctypes.PolyBlock
6970
SelectedTransaction rpctypes.PolyTransaction
7071
BlockCache *lru.Cache `json:"-"`
@@ -76,6 +77,7 @@ type (
7677
PeerCount uint64
7778
GasPrice *big.Int
7879
PendingCount uint64
80+
QueuedCount uint64
7981
}
8082
historicalDataPoint struct {
8183
SampleTime time.Time
@@ -119,6 +121,7 @@ func monitor(ctx context.Context) error {
119121

120122
ms.ChainID = big.NewInt(0)
121123
ms.PendingCount = 0
124+
ms.QueuedCount = 0
122125

123126
observedPendingTxs = make(historicalRange, 0)
124127

@@ -182,10 +185,9 @@ func getChainState(ctx context.Context, ec *ethclient.Client) (*chainState, erro
182185
return nil, fmt.Errorf("couldn't estimate gas: %s", err.Error())
183186
}
184187

185-
cs.PendingCount, err = util.GetTxPoolSize(ec.Client())
188+
cs.PendingCount, cs.QueuedCount, err = util.GetTxPoolStatus(ec.Client())
186189
if err != nil {
187-
log.Debug().Err(err).Msg("Unable to get pending transaction count")
188-
cs.PendingCount = 0
190+
log.Debug().Err(err).Msg("Unable to get pending and queued transaction count")
189191
}
190192

191193
return cs, nil
@@ -229,6 +231,7 @@ func fetchCurrentBlockData(ctx context.Context, ec *ethclient.Client, ms *monito
229231
ms.PeerCount = cs.PeerCount
230232
ms.GasPrice = cs.GasPrice
231233
ms.PendingCount = cs.PendingCount
234+
ms.QueuedCount = cs.QueuedCount
232235

233236
return
234237
}
@@ -432,6 +435,7 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
432435
Uint64("PeerCount", ms.PeerCount).
433436
Str("GasPrice", ms.GasPrice.String()).
434437
Uint64("PendingCount", ms.PendingCount).
438+
Uint64("QueuedCount", ms.QueuedCount).
435439
Msg("Redrawing")
436440

437441
if blockTable.SelectedRow == 0 {
@@ -464,7 +468,7 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
464468
renderedBlocks = renderedBlocksTemp
465469

466470
log.Debug().Int("skeleton.Current.Inner.Dy()", skeleton.Current.Inner.Dy()).Int("skeleton.Current.Inner.Dx()", skeleton.Current.Inner.Dx()).Msg("the dimension of the current box")
467-
skeleton.Current.Text = ui.GetCurrentBlockInfo(ms.HeadBlock, ms.GasPrice, ms.PeerCount, ms.PendingCount, ms.ChainID, renderedBlocks, skeleton.Current.Inner.Dx(), skeleton.Current.Inner.Dy())
471+
skeleton.Current.Text = ui.GetCurrentBlockInfo(ms.HeadBlock, ms.GasPrice, ms.PeerCount, ms.PendingCount, ms.QueuedCount, ms.ChainID, renderedBlocks, skeleton.Current.Inner.Dx(), skeleton.Current.Inner.Dy())
468472
skeleton.TxPerBlockChart.Data = metrics.GetTxsPerBlock(renderedBlocks)
469473
skeleton.GasPriceChart.Data = metrics.GetMeanGasPricePerBlock(renderedBlocks)
470474
skeleton.BlockSizeChart.Data = metrics.GetSizePerBlock(renderedBlocks)

cmd/monitor/ui/ui.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type UiSkeleton struct {
3131
Receipts *widgets.List
3232
}
3333

34-
func GetCurrentBlockInfo(headBlock *big.Int, gasPrice *big.Int, peerCount uint64, pendingCount uint64, chainID *big.Int, blocks []rpctypes.PolyBlock, dx int, dy int) string {
34+
func GetCurrentBlockInfo(headBlock *big.Int, gasPrice *big.Int, peerCount uint64, pendingCount uint64, queuedCount uint64, chainID *big.Int, blocks []rpctypes.PolyBlock, dx int, dy int) string {
3535
// Return an appropriate message if dy is 0 or less.
3636
if dy <= 0 {
3737
return "Invalid display configuration."
@@ -42,9 +42,10 @@ func GetCurrentBlockInfo(headBlock *big.Int, gasPrice *big.Int, peerCount uint64
4242
gasPriceString := fmt.Sprintf("Gas Price: %s gwei", new(big.Int).Div(gasPrice, metrics.UnitShannon).String())
4343
peers := fmt.Sprintf("Peers: %d", peerCount)
4444
pendingTx := fmt.Sprintf("Pending Tx: %d", pendingCount)
45+
queuedTx := fmt.Sprintf("Queued Tx: %d", queuedCount)
4546
chainIdString := fmt.Sprintf("Chain ID: %s", chainID.String())
4647

47-
info := []string{height, timeInfo, gasPriceString, peers, pendingTx, chainIdString}
48+
info := []string{height, timeInfo, gasPriceString, peers, pendingTx, queuedTx, chainIdString}
4849
columns := len(info) / dy
4950
if len(info)%dy != 0 {
5051
columns += 1 // Add an extra column for the remaining items

util/util.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -185,22 +185,22 @@ func GetReceipts(ctx context.Context, rawBlocks []*json.RawMessage, c *ethrpc.Cl
185185
return receipts, nil
186186
}
187187

188-
func GetTxPoolSize(rpc *ethrpc.Client) (uint64, error) {
188+
func GetTxPoolStatus(rpc *ethrpc.Client) (uint64, uint64, error) {
189189
var status = new(txpoolStatus)
190190
err := rpc.Call(status, "txpool_status")
191191
if err != nil {
192-
return 0, err
192+
return 0, 0, err
193193
}
194194
pendingCount, err := tryCastToUint64(status.Pending)
195195
if err != nil {
196-
return 0, err
196+
return 0, 0, err
197197
}
198198
queuedCount, err := tryCastToUint64(status.Queued)
199199
if err != nil {
200-
return 0, err
200+
return pendingCount, 0, err
201201
}
202202

203-
return pendingCount + queuedCount, nil
203+
return pendingCount, queuedCount, nil
204204
}
205205

206206
func tryCastToUint64(val any) (uint64, error) {

0 commit comments

Comments
 (0)