Skip to content

Commit

Permalink
feat(da): add default retry value for celestia (#985)
Browse files Browse the repository at this point in the history
  • Loading branch information
srene authored Jul 28, 2024
1 parent c5f8f07 commit d57d5b7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
10 changes: 7 additions & 3 deletions da/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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),
)
Expand Down Expand Up @@ -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)
}
Expand Down
9 changes: 5 additions & 4 deletions da/celestia/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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:"-"`
}
Expand Down
9 changes: 7 additions & 2 deletions da/celestia/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -47,14 +50,16 @@ 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,
Timeout: TestConfig.Timeout,
GasPrices: 0.1,
AuthToken: "TOKEN",
Backoff: defaultSubmitBackoff,
RetryAttempts: 4,
RetryAttempts: &retryAttempts,
RetryDelay: 3 * time.Second,
}
bz := mustMarshal(c)
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d57d5b7

Please sign in to comment.