Skip to content

Commit d8f4932

Browse files
authored
fix: configure default timeout for blob clients (#1191)
* feat: configure default timeout for blob clients * fix typo
1 parent 141a8df commit d8f4932

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

params/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
const (
2525
VersionMajor = 5 // Major version component of the current release
2626
VersionMinor = 8 // Minor version component of the current release
27-
VersionPatch = 49 // Patch version component of the current release
27+
VersionPatch = 50 // Patch version component of the current release
2828
VersionMeta = "mainnet" // Version metadata to append to the version string
2929
)
3030

rollup/da_syncer/blob_client/beacon_node_client.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ import (
99
"net/http"
1010
"net/url"
1111
"strconv"
12+
"time"
1213

1314
"github.com/scroll-tech/go-ethereum/common"
1415
"github.com/scroll-tech/go-ethereum/crypto/kzg4844"
1516
)
1617

18+
const (
19+
BeaconNodeDefaultTimeout = 15 * time.Second
20+
)
21+
1722
type BeaconNodeClient struct {
23+
client *http.Client
1824
apiEndpoint string
1925
genesisTime uint64
2026
secondsPerSlot uint64
@@ -27,12 +33,14 @@ var (
2733
)
2834

2935
func NewBeaconNodeClient(apiEndpoint string) (*BeaconNodeClient, error) {
36+
client := &http.Client{Timeout: BeaconNodeDefaultTimeout}
37+
3038
// get genesis time
3139
genesisPath, err := url.JoinPath(apiEndpoint, beaconNodeGenesisEndpoint)
3240
if err != nil {
3341
return nil, fmt.Errorf("failed to join path, err: %w", err)
3442
}
35-
resp, err := http.Get(genesisPath)
43+
resp, err := client.Get(genesisPath)
3644
if err != nil {
3745
return nil, fmt.Errorf("cannot do request, err: %w", err)
3846
}
@@ -62,7 +70,7 @@ func NewBeaconNodeClient(apiEndpoint string) (*BeaconNodeClient, error) {
6270
if err != nil {
6371
return nil, fmt.Errorf("failed to join path, err: %w", err)
6472
}
65-
resp, err = http.Get(specPath)
73+
resp, err = client.Get(specPath)
6674
if err != nil {
6775
return nil, fmt.Errorf("cannot do request, err: %w", err)
6876
}
@@ -91,6 +99,7 @@ func NewBeaconNodeClient(apiEndpoint string) (*BeaconNodeClient, error) {
9199
}
92100

93101
return &BeaconNodeClient{
102+
client: client,
94103
apiEndpoint: apiEndpoint,
95104
genesisTime: genesisTime,
96105
secondsPerSlot: secondsPerSlot,
@@ -105,7 +114,7 @@ func (c *BeaconNodeClient) GetBlobByVersionedHashAndBlockTime(ctx context.Contex
105114
if err != nil {
106115
return nil, fmt.Errorf("failed to join path, err: %w", err)
107116
}
108-
resp, err := http.Get(blobSidecarPath)
117+
resp, err := c.client.Get(blobSidecarPath)
109118
if err != nil {
110119
return nil, fmt.Errorf("cannot do request, err: %w", err)
111120
}

rollup/da_syncer/blob_client/blob_scan_client.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,25 @@ import (
88
"fmt"
99
"net/http"
1010
"net/url"
11+
"time"
1112

1213
"github.com/scroll-tech/go-ethereum/common"
1314
"github.com/scroll-tech/go-ethereum/common/hexutil"
1415
"github.com/scroll-tech/go-ethereum/crypto/kzg4844"
1516
)
1617

18+
const (
19+
BlobScanDefaultTimeout = 15 * time.Second
20+
)
21+
1722
type BlobScanClient struct {
1823
client *http.Client
1924
apiEndpoint string
2025
}
2126

2227
func NewBlobScanClient(apiEndpoint string) *BlobScanClient {
2328
return &BlobScanClient{
24-
client: http.DefaultClient,
29+
client: &http.Client{Timeout: BlobScanDefaultTimeout},
2530
apiEndpoint: apiEndpoint,
2631
}
2732
}

rollup/da_syncer/blob_client/block_native_client.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,25 @@ import (
88
"fmt"
99
"net/http"
1010
"net/url"
11+
"time"
1112

1213
"github.com/scroll-tech/go-ethereum/common"
1314
"github.com/scroll-tech/go-ethereum/common/hexutil"
1415
"github.com/scroll-tech/go-ethereum/crypto/kzg4844"
1516
)
1617

18+
const (
19+
BlockNativeDefaultTimeout = 15 * time.Second
20+
)
21+
1722
type BlockNativeClient struct {
23+
client *http.Client
1824
apiEndpoint string
1925
}
2026

2127
func NewBlockNativeClient(apiEndpoint string) *BlockNativeClient {
2228
return &BlockNativeClient{
29+
client: &http.Client{Timeout: BlockNativeDefaultTimeout},
2330
apiEndpoint: apiEndpoint,
2431
}
2532
}
@@ -34,7 +41,7 @@ func (c *BlockNativeClient) GetBlobByVersionedHashAndBlockTime(ctx context.Conte
3441
if err != nil {
3542
return nil, fmt.Errorf("cannot create request, err: %w", err)
3643
}
37-
resp, err := http.DefaultClient.Do(req)
44+
resp, err := c.client.Do(req)
3845
if err != nil {
3946
return nil, fmt.Errorf("cannot do request, err: %w", err)
4047
}

0 commit comments

Comments
 (0)