Skip to content

Commit 5e20a71

Browse files
authored
error when batch limit error + add sub batch arg (#192)
* hot fix: add sub batch arg * force exit when batch limit error * make gen doc * save * revert go routines * bump back to 10 * fix order
1 parent eafc0bb commit 5e20a71

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

cmd/monitor/cmd.go

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var (
1818
// flags
1919
rpcUrl string
2020
batchSizeValue string
21+
subBatchSize int
2122
blockCacheLimit int
2223
intervalStr string
2324

@@ -77,6 +78,7 @@ var MonitorCmd = &cobra.Command{
7778
func init() {
7879
MonitorCmd.PersistentFlags().StringVarP(&rpcUrl, "rpc-url", "r", "http://localhost:8545", "The RPC endpoint url")
7980
MonitorCmd.PersistentFlags().StringVarP(&batchSizeValue, "batch-size", "b", "auto", "Number of requests per batch")
81+
MonitorCmd.PersistentFlags().IntVarP(&subBatchSize, "sub-batch-size", "s", 50, "Number of requests per sub-batch")
8082
MonitorCmd.PersistentFlags().IntVarP(&blockCacheLimit, "cache-limit", "c", 200, "Number of cached blocks for the LRU block data structure (Min 100)")
8183
MonitorCmd.PersistentFlags().StringVarP(&intervalStr, "interval", "i", "5s", "Amount of time between batch block rpc calls")
8284
}

cmd/monitor/monitor.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"math/big"
8+
"strings"
89
"sync"
910
"time"
1011

@@ -52,9 +53,6 @@ var (
5253

5354
// semaphore is a channel used to control the concurrency of block data fetch operations.
5455
semaphore = make(chan struct{}, maxConcurrency)
55-
56-
// size of the sub batches to divide and conquer the total batch size with
57-
subBatchSize = 50
5856
)
5957

6058
type (
@@ -95,7 +93,6 @@ const (
9593
)
9694

9795
func monitor(ctx context.Context) error {
98-
// Dial rpc.
9996
rpc, err := ethrpc.DialContext(ctx, rpcUrl)
10097
if err != nil {
10198
log.Error().Err(err).Msg("Unable to dial rpc")
@@ -134,8 +131,8 @@ func monitor(ctx context.Context) error {
134131
}
135132
}()
136133
select {
137-
case <-ctx.Done(): // listens for a cancellation signal
138-
return // exit the goroutine when the context is done
134+
case <-ctx.Done():
135+
return
139136
default:
140137
for {
141138
err = fetchCurrentBlockData(ctx, ec, ms, isUiRendered)
@@ -329,7 +326,14 @@ func (ms *monitorStatus) processBatchesConcurrently(ctx context.Context, rpc *et
329326
b := backoff.NewExponentialBackOff()
330327
b.MaxElapsedTime = 3 * time.Minute
331328
retryable := func() error {
332-
return rpc.BatchCallContext(ctx, subBatch)
329+
err := rpc.BatchCallContext(ctx, subBatch)
330+
if err != nil {
331+
log.Error().Err(err).Msg("BatchCallContext error - retry loop")
332+
if strings.Contains(err.Error(), "limit") {
333+
return backoff.Permanent(err)
334+
}
335+
}
336+
return nil
333337
}
334338
if err := backoff.Retry(retryable, b); err != nil {
335339
log.Error().Err(err).Msg("unable to retry")
@@ -381,7 +385,6 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
381385
var renderedBlocks rpctypes.SortableBlocks
382386

383387
redraw := func(ms *monitorStatus, force ...bool) {
384-
385388
if currentMode == monitorModeHelp {
386389
// TODO add some help context?
387390
} else if currentMode == monitorModeBlock {
@@ -437,12 +440,10 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
437440
bottomBlockNumber.SetInt64(0)
438441
}
439442

440-
// if ms.LowerBlock == nil || ms.LowerBlock.Cmp(bottomBlockNumber) > 0 {
441443
err := ms.getBlockRange(ctx, ms.TopDisplayedBlock, rpc)
442444
if err != nil {
443445
log.Error().Err(err).Msg("There was an issue fetching the block range")
444446
}
445-
// }
446447
}
447448
toBlockNumber := ms.TopDisplayedBlock
448449
fromBlockNumber := new(big.Int).Sub(toBlockNumber, big.NewInt(int64(windowSize-1)))
@@ -462,7 +463,7 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
462463
ms.BlocksLock.RUnlock()
463464
renderedBlocks = renderedBlocksTemp
464465

465-
log.Warn().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")
466+
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")
466467
skeleton.Current.Text = ui.GetCurrentBlockInfo(ms.HeadBlock, ms.GasPrice, ms.PeerCount, ms.PendingCount, ms.ChainID, renderedBlocks, skeleton.Current.Inner.Dx(), skeleton.Current.Inner.Dy())
467468
skeleton.TxPerBlockChart.Data = metrics.GetTxsPerBlock(renderedBlocks)
468469
skeleton.GasPriceChart.Data = metrics.GetMeanGasPricePerBlock(renderedBlocks)

doc/polycli_monitor.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ If you're experiencing missing blocks, try adjusting the `--batch-size` and `--i
2828
## Flags
2929

3030
```bash
31-
-b, --batch-size string Number of requests per batch (default "auto")
32-
-c, --cache-limit int Number of cached blocks for the LRU block data structure (Min 100) (default 200)
33-
-h, --help help for monitor
34-
-i, --interval string Amount of time between batch block rpc calls (default "5s")
35-
-r, --rpc-url string The RPC endpoint url (default "http://localhost:8545")
31+
-b, --batch-size string Number of requests per batch (default "auto")
32+
-c, --cache-limit int Number of cached blocks for the LRU block data structure (Min 100) (default 200)
33+
-h, --help help for monitor
34+
-i, --interval string Amount of time between batch block rpc calls (default "5s")
35+
-r, --rpc-url string The RPC endpoint url (default "http://localhost:8545")
36+
-s, --sub-batch-size int Number of requests per sub-batch (default 50)
3637
```
3738

3839
The command also inherits flags from parent commands.

0 commit comments

Comments
 (0)