From d5f1145438ebc403717458915da9ad7284d37399 Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Wed, 4 Dec 2024 00:02:21 +0700 Subject: [PATCH 1/3] chore(simple_client): Add explicit ServiceUnavailable error type --- client/simple.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/client/simple.go b/client/simple.go index 6079da3..32ecd1b 100644 --- a/client/simple.go +++ b/client/simple.go @@ -8,6 +8,11 @@ import ( "net/http" ) +var ( + // 503 error type informing rollup to failover to other DA location + ErrServiceUnavailable = fmt.Errorf("eigenda service is unavailable") +) + // TODO: Add support for custom http client option type Config struct { URL string @@ -23,18 +28,11 @@ type SimpleCommitmentClient struct { httpClient *http.Client } -func New(cfg *Config) *SimpleCommitmentClient { - return &SimpleCommitmentClient{ - cfg, - http.DefaultClient, - } -} - // Health indicates if the server is operational; useful for event based awaits // when integration testing func (c *SimpleCommitmentClient) Health() error { url := c.cfg.URL + "/health" - req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil) + req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { return err } @@ -43,7 +41,6 @@ func (c *SimpleCommitmentClient) Health() error { if err != nil { return err } - defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return fmt.Errorf("received bad status code: %d", resp.StatusCode) @@ -81,7 +78,8 @@ func (c *SimpleCommitmentClient) GetData(ctx context.Context, comm []byte) ([]by return b, nil } -// SetData writes raw byte data to DA and returns the respective certificate +// SetData writes raw byte data to DA and returns the associated certificate +// which should be verified within the proxy func (c *SimpleCommitmentClient) SetData(ctx context.Context, b []byte) ([]byte, error) { url := fmt.Sprintf("%s/put?commitment_mode=simple", c.cfg.URL) req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(b)) @@ -100,6 +98,10 @@ func (c *SimpleCommitmentClient) SetData(ctx context.Context, b []byte) ([]byte, return nil, err } + if resp.StatusCode == http.StatusServiceUnavailable { + return nil, ErrServiceUnavailable + } + if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("failed to store data: %v, err = %s", resp.StatusCode, string(b)) } From 216773240e86c31742f31db5fcb9e33018a61b79 Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Wed, 4 Dec 2024 00:07:07 +0700 Subject: [PATCH 2/3] chore(simple_client): Add explicit ServiceUnavailable error type - bring back constructor --- client/simple.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/client/simple.go b/client/simple.go index 32ecd1b..2f973c1 100644 --- a/client/simple.go +++ b/client/simple.go @@ -28,6 +28,13 @@ type SimpleCommitmentClient struct { httpClient *http.Client } +func New(cfg *Config) *SimpleCommitmentClient { + return &SimpleCommitmentClient{ + cfg, + http.DefaultClient, + } +} + // Health indicates if the server is operational; useful for event based awaits // when integration testing func (c *SimpleCommitmentClient) Health() error { From 133861169bd6199293ccb561017fc25fc7de4972 Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Wed, 4 Dec 2024 00:34:41 +0700 Subject: [PATCH 3/3] chore(simple_client): Add explicit ServiceUnavailable error type - fix lint --- client/simple.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/simple.go b/client/simple.go index 2f973c1..8879743 100644 --- a/client/simple.go +++ b/client/simple.go @@ -39,7 +39,7 @@ func New(cfg *Config) *SimpleCommitmentClient { // when integration testing func (c *SimpleCommitmentClient) Health() error { url := c.cfg.URL + "/health" - req, err := http.NewRequest(http.MethodGet, url, nil) + req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil) if err != nil { return err } @@ -48,6 +48,7 @@ func (c *SimpleCommitmentClient) Health() error { if err != nil { return err } + defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return fmt.Errorf("received bad status code: %d", resp.StatusCode)