diff --git a/pkg/node/chain.go b/pkg/node/chain.go index 78fc0a5448d..d72709435ab 100644 --- a/pkg/node/chain.go +++ b/pkg/node/chain.go @@ -9,8 +9,11 @@ import ( "encoding/hex" "errors" "fmt" + "io" "math/big" + "net/http" "strings" + "syscall" "time" "github.com/ethereum/go-ethereum/common" @@ -37,8 +40,92 @@ const ( maxDelay = 1 * time.Minute cancellationDepth = 12 additionalConfirmations = 2 + maxRetries = 3 + retryBackoff = 100 * time.Millisecond ) +// retryRoundTripper implements http.RoundTripper with retry logic for transient network errors. +type retryRoundTripper struct { + transport http.RoundTripper + maxRetries int + backoff time.Duration +} + +// RoundTrip executes a single HTTP transaction, returning a Response for the Request. +// It retries on transient errors like EOF, connection reset, and connection refused. +func (r *retryRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { + var lastErr error + + for attempt := 0; attempt <= r.maxRetries; attempt++ { + if attempt > 0 { + backoffDuration := min(r.backoff*time.Duration(1<