Skip to content

Commit

Permalink
feat: track queued txs along with pending (#206)
Browse files Browse the repository at this point in the history
* feat: track queued txs along with pending

* remove GetTxPoolSize util function
  • Loading branch information
manav2401 authored Feb 7, 2024
1 parent 556cd54 commit ec28777
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
3 changes: 2 additions & 1 deletion cmd/loadtest/loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,13 @@ func updateRateLimit(ctx context.Context, rl *rate.Limiter, rpc *ethrpc.Client,
for {
select {
case <-ticker.C:
txPoolSize, err := util.GetTxPoolSize(rpc)
pendingTx, queuedTx, err := util.GetTxPoolStatus(rpc)
if err != nil {
log.Error().Err(err).Msg("Error getting txpool size")
return
}

txPoolSize := pendingTx + queuedTx
if txPoolSize < steadyStateQueueSize {
// additively increment requests per second if txpool less than queue steady state
newRateLimit := rate.Limit(float64(rl.Limit()) + float64(rateLimitIncrement))
Expand Down
12 changes: 8 additions & 4 deletions cmd/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type (
PeerCount uint64
GasPrice *big.Int
PendingCount uint64
QueuedCount uint64
SelectedBlock rpctypes.PolyBlock
SelectedTransaction rpctypes.PolyTransaction
BlockCache *lru.Cache `json:"-"`
Expand All @@ -76,6 +77,7 @@ type (
PeerCount uint64
GasPrice *big.Int
PendingCount uint64
QueuedCount uint64
}
historicalDataPoint struct {
SampleTime time.Time
Expand Down Expand Up @@ -119,6 +121,7 @@ func monitor(ctx context.Context) error {

ms.ChainID = big.NewInt(0)
ms.PendingCount = 0
ms.QueuedCount = 0

observedPendingTxs = make(historicalRange, 0)

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

cs.PendingCount, err = util.GetTxPoolSize(ec.Client())
cs.PendingCount, cs.QueuedCount, err = util.GetTxPoolStatus(ec.Client())
if err != nil {
log.Debug().Err(err).Msg("Unable to get pending transaction count")
cs.PendingCount = 0
log.Debug().Err(err).Msg("Unable to get pending and queued transaction count")
}

return cs, nil
Expand Down Expand Up @@ -229,6 +231,7 @@ func fetchCurrentBlockData(ctx context.Context, ec *ethclient.Client, ms *monito
ms.PeerCount = cs.PeerCount
ms.GasPrice = cs.GasPrice
ms.PendingCount = cs.PendingCount
ms.QueuedCount = cs.QueuedCount

return
}
Expand Down Expand Up @@ -432,6 +435,7 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
Uint64("PeerCount", ms.PeerCount).
Str("GasPrice", ms.GasPrice.String()).
Uint64("PendingCount", ms.PendingCount).
Uint64("QueuedCount", ms.QueuedCount).
Msg("Redrawing")

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

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")
skeleton.Current.Text = ui.GetCurrentBlockInfo(ms.HeadBlock, ms.GasPrice, ms.PeerCount, ms.PendingCount, ms.ChainID, renderedBlocks, skeleton.Current.Inner.Dx(), skeleton.Current.Inner.Dy())
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())
skeleton.TxPerBlockChart.Data = metrics.GetTxsPerBlock(renderedBlocks)
skeleton.GasPriceChart.Data = metrics.GetMeanGasPricePerBlock(renderedBlocks)
skeleton.BlockSizeChart.Data = metrics.GetSizePerBlock(renderedBlocks)
Expand Down
5 changes: 3 additions & 2 deletions cmd/monitor/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type UiSkeleton struct {
Receipts *widgets.List
}

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

info := []string{height, timeInfo, gasPriceString, peers, pendingTx, chainIdString}
info := []string{height, timeInfo, gasPriceString, peers, pendingTx, queuedTx, chainIdString}
columns := len(info) / dy
if len(info)%dy != 0 {
columns += 1 // Add an extra column for the remaining items
Expand Down
10 changes: 5 additions & 5 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,22 +185,22 @@ func GetReceipts(ctx context.Context, rawBlocks []*json.RawMessage, c *ethrpc.Cl
return receipts, nil
}

func GetTxPoolSize(rpc *ethrpc.Client) (uint64, error) {
func GetTxPoolStatus(rpc *ethrpc.Client) (uint64, uint64, error) {
var status = new(txpoolStatus)
err := rpc.Call(status, "txpool_status")
if err != nil {
return 0, err
return 0, 0, err
}
pendingCount, err := tryCastToUint64(status.Pending)
if err != nil {
return 0, err
return 0, 0, err
}
queuedCount, err := tryCastToUint64(status.Queued)
if err != nil {
return 0, err
return pendingCount, 0, err
}

return pendingCount + queuedCount, nil
return pendingCount, queuedCount, nil
}

func tryCastToUint64(val any) (uint64, error) {
Expand Down

0 comments on commit ec28777

Please sign in to comment.