Skip to content

Commit

Permalink
feat(settlement): expose hub retry params to config (#863)
Browse files Browse the repository at this point in the history
  • Loading branch information
srene authored May 16, 2024
1 parent 977019f commit 10c6ee9
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 40 deletions.
18 changes: 11 additions & 7 deletions config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,17 @@ func DefaultConfig(home, chainId string) *NodeConfig {
}

defaultSLconfig := settlement.Config{
KeyringBackend: "test",
NodeAddress: "http://127.0.0.1:36657",
RollappID: chainId,
KeyringHomeDir: keyringDir,
DymAccountName: "sequencer",
GasPrices: "1000000000adym",
SLGrpc: defaultSlGrpcConfig,
KeyringBackend: "test",
NodeAddress: "http://127.0.0.1:36657",
RollappID: chainId,
KeyringHomeDir: keyringDir,
DymAccountName: "sequencer",
GasPrices: "1000000000adym",
SLGrpc: defaultSlGrpcConfig,
RetryMinDelay: 1 * time.Second,
RetryMaxDelay: 10 * time.Second,
BatchAcceptanceTimeout: 120 * time.Second,
RetryAttempts: 10,
}
cfg.SettlementConfig = defaultSLconfig

Expand Down
4 changes: 4 additions & 0 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ node_address = "{{ .SettlementConfig.NodeAddress }}"
gas_limit = {{ .SettlementConfig.GasLimit }}
gas_prices = "{{ .SettlementConfig.GasPrices }}"
gas_fees = "{{ .SettlementConfig.GasFees }}"
retry_max_delay = "{{ .SettlementConfig.RetryMaxDelay }}"
retry_min_delay = "{{ .SettlementConfig.RetryMinDelay }}"
retry_attempts = "{{ .SettlementConfig.RetryAttempts }}"
batch_acceptance_timeout = "{{ .SettlementConfig.BatchAcceptanceTimeout }}"
#keyring and key name to be used for sequencer
keyring_backend = "{{ .SettlementConfig.KeyringBackend }}"
Expand Down
26 changes: 16 additions & 10 deletions settlement/config.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package settlement

import "errors"
import (
"errors"
"time"
)

// Config for the DymensionLayerClient
type Config struct {
KeyringBackend string `mapstructure:"keyring_backend"`
NodeAddress string `mapstructure:"node_address"`
KeyringHomeDir string `mapstructure:"keyring_home_dir"`
DymAccountName string `mapstructure:"dym_account_name"`
RollappID string `mapstructure:"rollapp_id"`
GasLimit uint64 `mapstructure:"gas_limit"`
GasPrices string `mapstructure:"gas_prices"`
GasFees string `mapstructure:"gas_fees"`

KeyringBackend string `mapstructure:"keyring_backend"`
NodeAddress string `mapstructure:"node_address"`
KeyringHomeDir string `mapstructure:"keyring_home_dir"`
DymAccountName string `mapstructure:"dym_account_name"`
RollappID string `mapstructure:"rollapp_id"`
GasLimit uint64 `mapstructure:"gas_limit"`
GasPrices string `mapstructure:"gas_prices"`
GasFees string `mapstructure:"gas_fees"`
RetryAttempts uint `mapstructure:"retry_attempts"`
RetryMaxDelay time.Duration `mapstructure:"retry_max_delay"`
RetryMinDelay time.Duration `mapstructure:"retry_min_delay"`
BatchAcceptanceTimeout time.Duration `mapstructure:"batch_acceptance_timeout"`
// For testing only. probably should be refactored
ProposerPubKey string `json:"proposer_pub_key"`
// Config used for sl shared grpc mock
Expand Down
45 changes: 24 additions & 21 deletions settlement/dymension/dymension.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ const (
eventSequencersListUpdate = "sequencers_list_update.rollapp_id='%s'"
)

const (
batchRetryDelay = 10 * time.Second
batchRetryMaxDelay = 1 * time.Minute
batchAcceptanceTimeout = 120 * time.Second
batchRetryAttempts = 10
)

const (
postBatchSubscriberPrefix = "postBatchSubscriber"
)
Expand All @@ -64,6 +57,7 @@ var _ settlement.LayerI = &LayerClient{}

// Init is called once. it initializes the struct members.
func (dlc *LayerClient) Init(config settlement.Config, pubsub *pubsub.Server, logger types.Logger, options ...settlement.Option) error {

DymensionCosmosClient, err := NewDymensionHubClient(config, pubsub, logger)
if err != nil {
return err
Expand Down Expand Up @@ -99,8 +93,9 @@ type HubClient struct {
// channel for getting notified when a batch is accepted by the settlement layer.
// only one batch of a specific height can get accepted and we can are currently sending only one batch at a time.
// for that reason it's safe to assume that if a batch is accepted, it refers to the last batch we've sent.
batchRetryAttempts uint
batchRetryDelay time.Duration
retryAttempts uint
retryMinDelay time.Duration
retryMaxDelay time.Duration
batchAcceptanceTimeout time.Duration
}

Expand All @@ -116,10 +111,10 @@ func WithCosmosClient(cosmosClient CosmosClient) Option {
}
}

// WithBatchRetryAttempts is an option that sets the number of attempts to retry sending a batch to the settlement layer.
func WithBatchRetryAttempts(batchRetryAttempts uint) Option {
// WithRetryAttempts is an option that sets the number of attempts to retry when interacting with the settlement layer.
func WithRetryAttempts(batchRetryAttempts uint) Option {
return func(d *HubClient) {
d.batchRetryAttempts = batchRetryAttempts
d.retryAttempts = batchRetryAttempts
}
}

Expand All @@ -130,10 +125,17 @@ func WithBatchAcceptanceTimeout(batchAcceptanceTimeout time.Duration) Option {
}
}

// WithBatchRetryDelay is an option that sets the delay between batch retry attempts.
func WithBatchRetryDelay(batchRetryDelay time.Duration) Option {
// WithRetryMinDelay is an option that sets the retry function mindelay between hub retry attempts.
func WithRetryMinDelay(retryMinDelay time.Duration) Option {
return func(d *HubClient) {
d.retryMinDelay = retryMinDelay
}
}

// WithRetryMaxDelay is an option that sets the retry function max delay between hub retry attempts.
func WithRetryMaxDelay(retryMaxDelay time.Duration) Option {
return func(d *HubClient) {
d.batchRetryDelay = batchRetryDelay
d.retryMaxDelay = retryMaxDelay
}
}

Expand All @@ -156,9 +158,10 @@ func NewDymensionHubClient(config settlement.Config, pubsub *pubsub.Server, logg
cancel: cancel,
eventMap: eventMap,
protoCodec: protoCodec,
batchRetryAttempts: batchRetryAttempts,
batchAcceptanceTimeout: batchAcceptanceTimeout,
batchRetryDelay: batchRetryDelay,
retryAttempts: config.RetryAttempts,
batchAcceptanceTimeout: config.BatchAcceptanceTimeout,
retryMinDelay: config.RetryMinDelay,
retryMaxDelay: config.RetryMaxDelay,
}

for _, option := range options {
Expand Down Expand Up @@ -557,8 +560,8 @@ func (d *HubClient) RunWithRetry(operation func() error) error {
return retry.Do(operation,
retry.Context(d.ctx),
retry.LastErrorOnly(true),
retry.Delay(d.batchRetryDelay),
retry.Attempts(d.batchRetryAttempts),
retry.MaxDelay(batchRetryMaxDelay),
retry.Delay(d.retryMinDelay),
retry.Attempts(d.retryAttempts),
retry.MaxDelay(d.retryMaxDelay),
)
}
5 changes: 3 additions & 2 deletions settlement/dymension/dymension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ func TestPostBatch(t *testing.T) {
options := []dymension.Option{
dymension.WithCosmosClient(cosmosClientMock),
dymension.WithBatchAcceptanceTimeout(time.Millisecond * 300),
dymension.WithBatchRetryAttempts(2),
dymension.WithBatchRetryDelay(time.Millisecond * 200),
dymension.WithRetryAttempts(2),
dymension.WithRetryMinDelay(time.Millisecond * 200),
dymension.WithRetryMaxDelay(time.Second * 2),
}

// Create a batch which will be submitted
Expand Down

0 comments on commit 10c6ee9

Please sign in to comment.