5
5
"errors"
6
6
"fmt"
7
7
"math/big"
8
+ "strings"
8
9
"sync"
9
10
"time"
10
11
52
53
53
54
// semaphore is a channel used to control the concurrency of block data fetch operations.
54
55
semaphore = make (chan struct {}, maxConcurrency )
55
-
56
- // size of the sub batches to divide and conquer the total batch size with
57
- subBatchSize = 50
58
56
)
59
57
60
58
type (
@@ -95,7 +93,6 @@ const (
95
93
)
96
94
97
95
func monitor (ctx context.Context ) error {
98
- // Dial rpc.
99
96
rpc , err := ethrpc .DialContext (ctx , rpcUrl )
100
97
if err != nil {
101
98
log .Error ().Err (err ).Msg ("Unable to dial rpc" )
@@ -134,8 +131,8 @@ func monitor(ctx context.Context) error {
134
131
}
135
132
}()
136
133
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
139
136
default :
140
137
for {
141
138
err = fetchCurrentBlockData (ctx , ec , ms , isUiRendered )
@@ -329,7 +326,14 @@ func (ms *monitorStatus) processBatchesConcurrently(ctx context.Context, rpc *et
329
326
b := backoff .NewExponentialBackOff ()
330
327
b .MaxElapsedTime = 3 * time .Minute
331
328
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
333
337
}
334
338
if err := backoff .Retry (retryable , b ); err != nil {
335
339
log .Error ().Err (err ).Msg ("unable to retry" )
@@ -381,7 +385,6 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
381
385
var renderedBlocks rpctypes.SortableBlocks
382
386
383
387
redraw := func (ms * monitorStatus , force ... bool ) {
384
-
385
388
if currentMode == monitorModeHelp {
386
389
// TODO add some help context?
387
390
} else if currentMode == monitorModeBlock {
@@ -437,12 +440,10 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
437
440
bottomBlockNumber .SetInt64 (0 )
438
441
}
439
442
440
- // if ms.LowerBlock == nil || ms.LowerBlock.Cmp(bottomBlockNumber) > 0 {
441
443
err := ms .getBlockRange (ctx , ms .TopDisplayedBlock , rpc )
442
444
if err != nil {
443
445
log .Error ().Err (err ).Msg ("There was an issue fetching the block range" )
444
446
}
445
- // }
446
447
}
447
448
toBlockNumber := ms .TopDisplayedBlock
448
449
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
462
463
ms .BlocksLock .RUnlock ()
463
464
renderedBlocks = renderedBlocksTemp
464
465
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" )
466
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 ())
467
468
skeleton .TxPerBlockChart .Data = metrics .GetTxsPerBlock (renderedBlocks )
468
469
skeleton .GasPriceChart .Data = metrics .GetMeanGasPricePerBlock (renderedBlocks )
0 commit comments