From ec287776d7db0383e6ffa1ff17c12944e48476a7 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Wed, 7 Feb 2024 19:00:31 +0530 Subject: [PATCH] feat: track queued txs along with pending (#206) * feat: track queued txs along with pending * remove GetTxPoolSize util function --- cmd/loadtest/loadtest.go | 3 ++- cmd/monitor/monitor.go | 12 ++++++++---- cmd/monitor/ui/ui.go | 5 +++-- util/util.go | 10 +++++----- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/cmd/loadtest/loadtest.go b/cmd/loadtest/loadtest.go index afb20b18..f0702962 100644 --- a/cmd/loadtest/loadtest.go +++ b/cmd/loadtest/loadtest.go @@ -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)) diff --git a/cmd/monitor/monitor.go b/cmd/monitor/monitor.go index fd3505b0..fd34a0a9 100644 --- a/cmd/monitor/monitor.go +++ b/cmd/monitor/monitor.go @@ -65,6 +65,7 @@ type ( PeerCount uint64 GasPrice *big.Int PendingCount uint64 + QueuedCount uint64 SelectedBlock rpctypes.PolyBlock SelectedTransaction rpctypes.PolyTransaction BlockCache *lru.Cache `json:"-"` @@ -76,6 +77,7 @@ type ( PeerCount uint64 GasPrice *big.Int PendingCount uint64 + QueuedCount uint64 } historicalDataPoint struct { SampleTime time.Time @@ -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) @@ -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 @@ -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 } @@ -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 { @@ -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) diff --git a/cmd/monitor/ui/ui.go b/cmd/monitor/ui/ui.go index cbab0c6a..83c1a45a 100644 --- a/cmd/monitor/ui/ui.go +++ b/cmd/monitor/ui/ui.go @@ -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." @@ -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 diff --git a/util/util.go b/util/util.go index a8c30445..caa71bd4 100644 --- a/util/util.go +++ b/util/util.go @@ -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) {