From d57d5b773d8204ad5a398ef512b251677372f856 Mon Sep 17 00:00:00 2001 From: Sergi Rene Date: Sun, 28 Jul 2024 10:56:17 +0200 Subject: [PATCH] feat(da): add default retry value for celestia (#985) --- da/celestia/celestia.go | 10 +++++++--- da/celestia/config.go | 9 +++++---- da/celestia/config_test.go | 9 +++++++-- go.mod | 1 - 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/da/celestia/celestia.go b/da/celestia/celestia.go index e72f85e6a..1bed204f8 100644 --- a/da/celestia/celestia.go +++ b/da/celestia/celestia.go @@ -61,7 +61,7 @@ func WithRPCRetryDelay(delay time.Duration) da.Option { // WithRPCAttempts sets failed rpc calls retry attempts. func WithRPCAttempts(attempts int) da.Option { return func(daLayerClient da.DataAvailabilityLayerClient) { - daLayerClient.(*DataAvailabilityLayerClient).config.RetryAttempts = attempts + daLayerClient.(*DataAvailabilityLayerClient).config.RetryAttempts = &attempts } } @@ -122,6 +122,10 @@ func createConfig(bz []byte) (c Config, err error) { if c.Backoff == (uretry.BackoffConfig{}) { c.Backoff = defaultSubmitBackoff } + if c.RetryAttempts == nil { + attempts := defaultRpcRetryAttempts + c.RetryAttempts = &attempts + } return c, nil } @@ -270,7 +274,7 @@ func (c *DataAvailabilityLayerClient) RetrieveBatches(daMetaData *da.DASubmitMet return nil }, - retry.Attempts(uint(c.config.RetryAttempts)), + retry.Attempts(uint(*c.config.RetryAttempts)), retry.DelayType(retry.FixedDelay), retry.Delay(c.config.RetryDelay), ) @@ -399,7 +403,7 @@ func (c *DataAvailabilityLayerClient) CheckBatchAvailability(daMetaData *da.DASu } return nil - }, retry.Attempts(uint(c.config.RetryAttempts)), retry.DelayType(retry.FixedDelay), retry.Delay(c.config.RetryDelay)) + }, retry.Attempts(uint(*c.config.RetryAttempts)), retry.DelayType(retry.FixedDelay), retry.Delay(c.config.RetryDelay)) if err != nil { c.logger.Error("CheckAvailability process failed.", "error", err) } diff --git a/da/celestia/config.go b/da/celestia/config.go index fafc40252..44a8a5d7c 100644 --- a/da/celestia/config.go +++ b/da/celestia/config.go @@ -12,9 +12,10 @@ import ( ) const ( - defaultRpcRetryDelay = 3 * time.Second - namespaceVersion = 0 - DefaultGasPrices = 0.1 + defaultRpcRetryDelay = 3 * time.Second + namespaceVersion = 0 + DefaultGasPrices = 0.1 + defaultRpcRetryAttempts = 5 ) var defaultSubmitBackoff = uretry.NewBackoffConfig( @@ -31,7 +32,7 @@ type Config struct { NamespaceIDStr string `json:"namespace_id,omitempty"` AuthToken string `json:"auth_token,omitempty"` Backoff uretry.BackoffConfig `json:"backoff,omitempty"` - RetryAttempts int `json:"retry_attempts,omitempty"` + RetryAttempts *int `json:"retry_attempts,omitempty"` RetryDelay time.Duration `json:"retry_delay,omitempty"` NamespaceID openrpcns.Namespace `json:"-"` } diff --git a/da/celestia/config_test.go b/da/celestia/config_test.go index cad82d7b2..2838b9a28 100644 --- a/da/celestia/config_test.go +++ b/da/celestia/config_test.go @@ -17,14 +17,17 @@ func TestCreateConfig(t *testing.T) { bz, _ := json.Marshal(v) return bz } + t.Run("simple", func(t *testing.T) { + retryAttempts := 10 + c := Config{ BaseURL: TestConfig.BaseURL, AppNodeURL: TestConfig.AppNodeURL, Timeout: TestConfig.Timeout, GasPrices: 42, Backoff: uretry.NewBackoffConfig(uretry.WithGrowthFactor(1.65)), - RetryAttempts: 10, + RetryAttempts: &retryAttempts, RetryDelay: 10 * time.Second, } bz := mustMarshal(c) @@ -47,6 +50,8 @@ func TestCreateConfig(t *testing.T) { assert.Equal(t, defaultSubmitBackoff, gotC.Backoff) }) t.Run("generate example", func(t *testing.T) { + retryAttempts := 4 + c := Config{ BaseURL: TestConfig.BaseURL, AppNodeURL: TestConfig.AppNodeURL, @@ -54,7 +59,7 @@ func TestCreateConfig(t *testing.T) { GasPrices: 0.1, AuthToken: "TOKEN", Backoff: defaultSubmitBackoff, - RetryAttempts: 4, + RetryAttempts: &retryAttempts, RetryDelay: 3 * time.Second, } bz := mustMarshal(c) diff --git a/go.mod b/go.mod index 42c992a5a..7016f5bf5 100644 --- a/go.mod +++ b/go.mod @@ -281,7 +281,6 @@ replace ( github.com/gorilla/rpc => github.com/dymensionxyz/rpc v1.3.1 github.com/libp2p/go-libp2p-pubsub => github.com/dymensionxyz/go-libp2p-pubsub v0.0.0-20240513081713-3ecd83c19ea2 github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.28 - ) replace github.com/osmosis-labs/osmosis/v15 => github.com/dymensionxyz/osmosis/v15 v15.2.0-dymension-v1.1.2