fix: configure default timeout for blob clients (#1191)

* feat: configure default timeout for blob clients

* fix typo
This commit is contained in:
Péter Garamvölgyi 2025-05-28 11:19:33 +02:00 committed by GitHub
parent 141a8df143
commit d8f4932bf2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 6 deletions

View file

@ -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
)

View file

@ -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)
}

View file

@ -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,
}
}

View file

@ -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)
}