Skip to content

Commit

Permalink
remove get block by number and use range
Browse files Browse the repository at this point in the history
  • Loading branch information
gatsbyz committed Nov 9, 2023
1 parent 97ec6ad commit 246436c
Showing 1 changed file with 2 additions and 43 deletions.
45 changes: 2 additions & 43 deletions cmd/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,47 +254,6 @@ func (ms *monitorStatus) getBlockRange(ctx context.Context, from, to *big.Int, r
return nil
}

func (ms *monitorStatus) getBlockByBlockNumber(ctx context.Context, blockNumbers []*big.Int, rpc *ethrpc.Client) error {
blms := make([]ethrpc.BatchElem, 0)
for _, number := range blockNumbers {
r := new(rpctypes.RawBlockResponse)
var err error
blms = append(blms, ethrpc.BatchElem{
Method: "eth_getBlockByNumber",
Args: []interface{}{"0x" + number.Text(16), true},
Result: r,
Error: err,
})
}
if len(blms) == 0 {
return nil
}
b := backoff.NewExponentialBackOff()
b.MaxElapsedTime = 3 * time.Minute
retryable := func() error {
err := rpc.BatchCallContext(ctx, blms)
return err
}
err := backoff.Retry(retryable, b)
if err != nil {
return err
}
for _, b := range blms {
if b.Error != nil {
return b.Error
}
pb := rpctypes.NewPolyBlock(b.Result.(*rpctypes.RawBlockResponse))

ms.BlockCache.Add(pb.Number().String(), pb)

log.Debug().
Str("isBlockInCache(ms.BlockCache, toBlockNumber)", pb.Number().String()).
Msg("FETCHED")
}

return nil
}

func setUISkeleton() (blockTable *widgets.List, grid *ui.Grid, blockGrid *ui.Grid, termUi uiSkeleton) {
blockTable = widgets.NewList()
blockTable.TextStyle = ui.NewStyle(ui.ColorWhite)
Expand Down Expand Up @@ -773,9 +732,9 @@ func checkAndFetchMissingBlocks(ctx context.Context, ms *monitorStatus, rpc *eth
}
}

// If there are missing blocks, fetch them using getBlockByBlockNumber.
// If there are missing blocks, fetch them using getBlockRange.
if len(missingBlocks) > 0 {
err := ms.getBlockByBlockNumber(ctx, missingBlocks, rpc)
err := ms.getBlockRange(ctx, missingBlocks[0], missingBlocks[len(missingBlocks)-1], rpc)
if err != nil {
// Handle the error, such as logging or returning it.
return nil, err
Expand Down

0 comments on commit 246436c

Please sign in to comment.