Skip to content

Commit

Permalink
revert pending tx slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
gatsbyz committed Nov 8, 2023
1 parent ae3cfde commit f5c82b8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions cmd/monitor/block.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package monitor
13 changes: 10 additions & 3 deletions cmd/monitor/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ var (
usage string

// flags
rpcUrl string
batchSizeValue string
intervalStr string
rpcUrl string
batchSizeValue string
blockCacheLimit int
intervalStr string
)

// MonitorCmd represents the monitor command
Expand All @@ -37,6 +38,7 @@ var MonitorCmd = &cobra.Command{
func init() {
MonitorCmd.PersistentFlags().StringVarP(&rpcUrl, "rpc-url", "r", "http://localhost:8545", "The RPC endpoint url")
MonitorCmd.PersistentFlags().StringVarP(&batchSizeValue, "batch-size", "b", "auto", "Number of requests per batch")
MonitorCmd.PersistentFlags().IntVarP(&blockCacheLimit, "cache-limit", "c", 50, "Number of cached blocks for the LRU block data structure")
MonitorCmd.PersistentFlags().StringVarP(&intervalStr, "interval", "i", "5s", "Amount of time between batch block rpc calls")
}

Expand Down Expand Up @@ -66,5 +68,10 @@ func checkFlags() (err error) {
}
}

// Check batch-size flag.
if blockCacheLimit < 50 {
return fmt.Errorf("block-cache can't be less than 50")
}

return nil
}
8 changes: 1 addition & 7 deletions cmd/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func monitor(ctx context.Context) error {
ec := ethclient.NewClient(rpc)

ms := new(monitorStatus)
ms.BlockCache, _ = lru.New(100)
ms.BlockCache, _ = lru.New(blockCacheLimit)
ms.MaxBlockRetrieved = big.NewInt(0)

ms.ChainID = big.NewInt(0)
Expand Down Expand Up @@ -193,8 +193,6 @@ func prependLatestBlocks(ctx context.Context, ms *monitorStatus, rpc *ethrpc.Cli
}
}

const maxHistoricalPoints = 100 // set a limit to the number of historical points

func fetchBlocks(ctx context.Context, ec *ethclient.Client, ms *monitorStatus, rpc *ethrpc.Client, isUiRendered bool) (err error) {
var cs *chainState
cs, err = getChainState(ctx, ec)
Expand All @@ -203,10 +201,6 @@ func fetchBlocks(ctx context.Context, ec *ethclient.Client, ms *monitorStatus, r
time.Sleep(interval)
return err
}
if len(observedPendingTxs) >= maxHistoricalPoints {
// remove the oldest data point
observedPendingTxs = observedPendingTxs[1:]
}
observedPendingTxs = append(observedPendingTxs, historicalDataPoint{SampleTime: time.Now(), SampleValue: float64(cs.PendingCount)})

log.Debug().Uint64("PeerCount", cs.PeerCount).Uint64("ChainID", cs.ChainID.Uint64()).Uint64("HeadBlock", cs.HeadBlock).Uint64("GasPrice", cs.GasPrice.Uint64()).Msg("Fetching blocks")
Expand Down

0 comments on commit f5c82b8

Please sign in to comment.