From d8f4932bf202f5d7f405c1f82bd1de72d87dc84a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Wed, 28 May 2025 11:19:33 +0200 Subject: [PATCH] fix: configure default timeout for blob clients (#1191) * feat: configure default timeout for blob clients * fix typo --- params/version.go | 2 +- .../da_syncer/blob_client/beacon_node_client.go | 15 ++++++++++++--- rollup/da_syncer/blob_client/blob_scan_client.go | 7 ++++++- .../da_syncer/blob_client/block_native_client.go | 9 ++++++++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/params/version.go b/params/version.go index de0b4211f6..12c6206f54 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 5 // Major version component of the current release VersionMinor = 8 // Minor version component of the current release - VersionPatch = 49 // Patch version component of the current release + VersionPatch = 50 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string ) diff --git a/rollup/da_syncer/blob_client/beacon_node_client.go b/rollup/da_syncer/blob_client/beacon_node_client.go index adb61a4199..f7129af76d 100644 --- a/rollup/da_syncer/blob_client/beacon_node_client.go +++ b/rollup/da_syncer/blob_client/beacon_node_client.go @@ -9,12 +9,18 @@ import ( "net/http" "net/url" "strconv" + "time" "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/crypto/kzg4844" ) +const ( + BeaconNodeDefaultTimeout = 15 * time.Second +) + type BeaconNodeClient struct { + client *http.Client apiEndpoint string genesisTime uint64 secondsPerSlot uint64 @@ -27,12 +33,14 @@ var ( ) func NewBeaconNodeClient(apiEndpoint string) (*BeaconNodeClient, error) { + client := &http.Client{Timeout: BeaconNodeDefaultTimeout} + // get genesis time genesisPath, err := url.JoinPath(apiEndpoint, beaconNodeGenesisEndpoint) if err != nil { return nil, fmt.Errorf("failed to join path, err: %w", err) } - resp, err := http.Get(genesisPath) + resp, err := client.Get(genesisPath) if err != nil { return nil, fmt.Errorf("cannot do request, err: %w", err) } @@ -62,7 +70,7 @@ func NewBeaconNodeClient(apiEndpoint string) (*BeaconNodeClient, error) { if err != nil { return nil, fmt.Errorf("failed to join path, err: %w", err) } - resp, err = http.Get(specPath) + resp, err = client.Get(specPath) if err != nil { return nil, fmt.Errorf("cannot do request, err: %w", err) } @@ -91,6 +99,7 @@ func NewBeaconNodeClient(apiEndpoint string) (*BeaconNodeClient, error) { } return &BeaconNodeClient{ + client: client, apiEndpoint: apiEndpoint, genesisTime: genesisTime, secondsPerSlot: secondsPerSlot, @@ -105,7 +114,7 @@ func (c *BeaconNodeClient) GetBlobByVersionedHashAndBlockTime(ctx context.Contex if err != nil { return nil, fmt.Errorf("failed to join path, err: %w", err) } - resp, err := http.Get(blobSidecarPath) + resp, err := c.client.Get(blobSidecarPath) if err != nil { return nil, fmt.Errorf("cannot do request, err: %w", err) } diff --git a/rollup/da_syncer/blob_client/blob_scan_client.go b/rollup/da_syncer/blob_client/blob_scan_client.go index 0185cc9dc9..75fe4fdfbd 100644 --- a/rollup/da_syncer/blob_client/blob_scan_client.go +++ b/rollup/da_syncer/blob_client/blob_scan_client.go @@ -8,12 +8,17 @@ import ( "fmt" "net/http" "net/url" + "time" "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/common/hexutil" "github.com/scroll-tech/go-ethereum/crypto/kzg4844" ) +const ( + BlobScanDefaultTimeout = 15 * time.Second +) + type BlobScanClient struct { client *http.Client apiEndpoint string @@ -21,7 +26,7 @@ type BlobScanClient struct { func NewBlobScanClient(apiEndpoint string) *BlobScanClient { return &BlobScanClient{ - client: http.DefaultClient, + client: &http.Client{Timeout: BlobScanDefaultTimeout}, apiEndpoint: apiEndpoint, } } diff --git a/rollup/da_syncer/blob_client/block_native_client.go b/rollup/da_syncer/blob_client/block_native_client.go index 1fe6efbbab..d96f54a3cf 100644 --- a/rollup/da_syncer/blob_client/block_native_client.go +++ b/rollup/da_syncer/blob_client/block_native_client.go @@ -8,18 +8,25 @@ import ( "fmt" "net/http" "net/url" + "time" "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/common/hexutil" "github.com/scroll-tech/go-ethereum/crypto/kzg4844" ) +const ( + BlockNativeDefaultTimeout = 15 * time.Second +) + type BlockNativeClient struct { + client *http.Client apiEndpoint string } func NewBlockNativeClient(apiEndpoint string) *BlockNativeClient { return &BlockNativeClient{ + client: &http.Client{Timeout: BlockNativeDefaultTimeout}, apiEndpoint: apiEndpoint, } } @@ -34,7 +41,7 @@ func (c *BlockNativeClient) GetBlobByVersionedHashAndBlockTime(ctx context.Conte if err != nil { return nil, fmt.Errorf("cannot create request, err: %w", err) } - resp, err := http.DefaultClient.Do(req) + resp, err := c.client.Do(req) if err != nil { return nil, fmt.Errorf("cannot do request, err: %w", err) }