Skip to content

Commit dc9508d

Browse files
committed
fix: forward tx no blocking context timeout
1 parent 78411f7 commit dc9508d

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

eth/api_backend.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction)
290290
// If the transaction pool is enabled, we send the transaction to the sequencer RPC asynchronously as this is
291291
// additional to the public mempool.
292292
go func() {
293+
// create a new context with a timeout
294+
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
295+
defer cancel()
293296
err := b.sendToSequencer(ctx, signedTx)
294297
if err != nil {
295298
log.Warn("failed to forward tx to sequencer", "tx", signedTx.Hash(), "err", err)

eth/gasprice/scroll_gasprice.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gasprice
22

33
import (
44
"context"
5+
"errors"
56
"math/big"
67
"sort"
78

@@ -43,6 +44,15 @@ func (oracle *Oracle) calculateSuggestPriorityFee(ctx context.Context, header *t
4344
// capacity margin
4445
receipts, err := oracle.backend.GetReceipts(ctx, header.Hash())
4546
if receipts == nil || err != nil {
47+
// Handle context cancellation gracefully
48+
if errors.Is(err, context.Canceled) {
49+
log.Debug("gas price calculation cancelled due to context cancellation", "block number", header.Number)
50+
// Return cached values if available, otherwise use defaults
51+
if lastIsCongested {
52+
return lastPrice, lastIsCongested
53+
}
54+
return suggestion, isCongested
55+
}
4656
log.Debug("failed to get block receipts during calculating suggest priority fee", "block number", header.Number, "err", err)
4757
// If the lastIsCongested is true on the cache, return the lastPrice.
4858
// We believe it's better to err on the side of returning a higher-than-needed suggestion than a lower-than-needed one.
@@ -68,6 +78,11 @@ func (oracle *Oracle) calculateSuggestPriorityFee(ctx context.Context, header *t
6878
)
6979
block, err := oracle.backend.BlockByNumber(ctx, rpc.BlockNumber(header.Number.Int64()))
7080
if block == nil || err != nil {
81+
// Handle context cancellation gracefully
82+
if errors.Is(err, context.Canceled) {
83+
log.Debug("block retrieval cancelled due to context cancellation", "block number", header.Number)
84+
return suggestion, isCongested
85+
}
7186
log.Error("failed to get last block", "err", err)
7287
return suggestion, isCongested
7388
}
@@ -138,8 +153,10 @@ func (oracle *Oracle) calculateSuggestPriorityFee(ctx context.Context, header *t
138153
}
139154

140155
// update the cache only if it's latest block header
141-
latestHeader, _ := oracle.backend.HeaderByNumber(ctx, rpc.LatestBlockNumber)
142-
if header.Hash() == latestHeader.Hash() {
156+
latestHeader, err := oracle.backend.HeaderByNumber(ctx, rpc.LatestBlockNumber)
157+
if err != nil && errors.Is(err, context.Canceled) {
158+
log.Debug("latest header retrieval cancelled, skipping cache update", "block number", header.Number)
159+
} else if latestHeader != nil && header.Hash() == latestHeader.Hash() {
143160
oracle.cacheLock.Lock()
144161
oracle.lastHead = header.Hash()
145162
oracle.lastPrice = suggestion

0 commit comments

Comments
 (0)