Skip to content

Commit 0df93e3

Browse files
committed
chore: remove unnecessary timeouts
1 parent d935293 commit 0df93e3

File tree

2 files changed

+5
-36
lines changed

2 files changed

+5
-36
lines changed

server/l1.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package server
33
import (
44
"context"
55
"fmt"
6-
"time"
76

87
ethcommon "github.com/ethereum/go-ethereum/common"
98
"github.com/flashbots/chain-monitor/config"
@@ -69,9 +68,6 @@ func (l1 *L1) observeWallets(ctx context.Context, o otelapi.Observer) error {
6968
errs := make([]error, 0)
7069

7170
for name, addr := range l1.wallets {
72-
ctx, cancel := context.WithTimeout(ctx, time.Second)
73-
defer cancel()
74-
7571
_balance, err := l1.rpc.BalanceAt(ctx, addr, nil)
7672
if err != nil {
7773
l.Error("Failed to request balance",

server/l2.go

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,7 @@ func newL2(cfg *config.L2) (*L2, error) {
139139
}
140140

141141
{ // blocks, blockHeight
142-
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
143-
defer cancel()
144-
145-
blockHeight, err := l2.rpc.BlockNumber(ctx)
142+
blockHeight, err := l2.rpc.BlockNumber(context.Background())
146143
if err != nil {
147144
l.Error("Failed to request block number",
148145
zap.Error(err),
@@ -190,9 +187,6 @@ func (l2 *L2) stop() {
190187
func (l2 *L2) processNewBlocks(ctx context.Context) {
191188
l := logutils.LoggerFromContext(ctx)
192189

193-
ctx, cancel := context.WithTimeout(ctx, time.Second)
194-
defer cancel()
195-
196190
blockHeight, err := l2.rpc.BlockNumber(ctx)
197191
if err != nil {
198192
l.Warn("Failed to request block number, skipping this round...",
@@ -243,9 +237,6 @@ func (l2 *L2) processNewBlocks(ctx context.Context) {
243237
func (l2 *L2) processBlock(ctx context.Context, blockNumber uint64) error {
244238
l := logutils.LoggerFromContext(ctx)
245239

246-
ctx, cancel := context.WithTimeout(ctx, time.Second)
247-
defer cancel()
248-
249240
block, err := l2.rpc.BlockByNumber(ctx, big.NewInt(int64(blockNumber)))
250241
if err != nil {
251242
l.Warn("Failed to request block by number",
@@ -391,9 +382,6 @@ func (l2 *L2) processReorgByHash(ctx context.Context) error {
391382
)
392383
}
393384

394-
ctx, cancel := context.WithTimeout(ctx, time.Second)
395-
defer cancel()
396-
397385
block, err := l2.rpc.BlockByNumber(ctx, br.number)
398386
if err != nil {
399387
l.Warn("Failed to request block by number, skipping this round of unwind...",
@@ -549,9 +537,6 @@ func (l2 *L2) observeWallets(ctx context.Context, o otelapi.Observer) error {
549537
errs := make([]error, 0)
550538

551539
for name, addr := range l2.wallets {
552-
ctx, cancel := context.WithTimeout(ctx, time.Second)
553-
defer cancel()
554-
555540
_balance, err := l2.rpc.BalanceAt(ctx, addr, nil)
556541
if err != nil {
557542
l.Warn("Failed to request balance",
@@ -585,10 +570,7 @@ func (l2 *L2) sendProbeTx(ctx context.Context) {
585570
)
586571

587572
{ // get the gas price
588-
_ctx, cancel := context.WithTimeout(ctx, time.Second)
589-
defer cancel()
590-
591-
gasPrice, err = l2.rpc.SuggestGasPrice(_ctx)
573+
gasPrice, err = l2.rpc.SuggestGasPrice(ctx)
592574
if err == nil {
593575
metrics.GasPrice_Old.Record(ctx, gasPrice.Int64())
594576
} else {
@@ -610,10 +592,7 @@ func (l2 *L2) sendProbeTx(ctx context.Context) {
610592
}
611593

612594
if l2.nonce == 0 { // get the nonce
613-
_ctx, cancel := context.WithTimeout(ctx, time.Second)
614-
defer cancel()
615-
616-
nonce, err := l2.rpc.NonceAt(_ctx, l2.monitorAddr, nil)
595+
nonce, err := l2.rpc.NonceAt(ctx, l2.monitorAddr, nil)
617596
if err != nil {
618597
l.Warn("Failed to request a nonce",
619598
zap.Error(err),
@@ -655,10 +634,7 @@ tryingNonces:
655634
return
656635
}
657636

658-
_ctx, cancel := context.WithTimeout(ctx, time.Second)
659-
defer cancel()
660-
661-
err = l2.rpc.SendTransaction(_ctx, signedTx)
637+
err = l2.rpc.SendTransaction(ctx, signedTx)
662638
if err == nil {
663639
metrics.ProbesSentCount.Add(ctx, 1)
664640
l2.nonce++
@@ -705,10 +681,7 @@ tryingNonces:
705681
continue tryingNonces
706682

707683
case strings.Contains(err.Error(), "nonce too low"):
708-
_ctx, cancel := context.WithTimeout(ctx, time.Second)
709-
defer cancel()
710-
711-
nonce, err := l2.rpc.NonceAt(_ctx, l2.monitorAddr, nil)
684+
nonce, err := l2.rpc.NonceAt(ctx, l2.monitorAddr, nil)
712685
if err != nil {
713686
l.Warn("Failed to request a nonce",
714687
zap.Error(err),

0 commit comments

Comments
 (0)