Skip to content

Commit

Permalink
Improved retry backoff (#35)
Browse files Browse the repository at this point in the history
* Deleted unused code

* Improved retry backoff
  • Loading branch information
ironbeer authored Jul 19, 2024
1 parent 16342fd commit e00d315
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 875 deletions.
23 changes: 17 additions & 6 deletions cmd/config_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"os"
"strings"
"time"

"github.com/oasysgames/oasys-optimism-verifier/config"
"github.com/spf13/cobra"
Expand All @@ -27,8 +28,10 @@ type configLoader struct {
scc, l2oo string
}
verifier struct {
use bool
wallet config.Wallet
use bool
wallet config.Wallet
MaxRetryBackoff time.Duration
RetryTimeout time.Duration
}
submitter struct {
use bool
Expand Down Expand Up @@ -101,10 +104,12 @@ func mustNewConfigLoader(cmd *cobra.Command) *configLoader {
{
name: "verifier",
flags: map[string]func(name string){
"": argConfigFlag(&opts.verifier.use, f.BoolVar, "Enable the verifier feature"),
"wallet.address": argConfigFlag(&opts.verifier.wallet.Address, f.StringVar, "Address of the verifier wallet"),
"wallet.password": argConfigFlag(&opts.verifier.wallet.Password, f.StringVar, "Password file of the verifier wallet"),
"wallet.plain": argConfigFlag(&opts.verifier.wallet.Plain, f.StringVar, "Plaintext private key of the verifier wallet"),
"": argConfigFlag(&opts.verifier.use, f.BoolVar, "Enable the verifier feature"),
"wallet.address": argConfigFlag(&opts.verifier.wallet.Address, f.StringVar, "Address of the verifier wallet"),
"wallet.password": argConfigFlag(&opts.verifier.wallet.Password, f.StringVar, "Password file of the verifier wallet"),
"wallet.plain": argConfigFlag(&opts.verifier.wallet.Plain, f.StringVar, "Plaintext private key of the verifier wallet"),
"max-retry-backoff": argConfigFlag(&opts.verifier.MaxRetryBackoff, f.DurationVar, "Maximum exponential backoff time for retries"),
"retry-timeout": argConfigFlag(&opts.verifier.RetryTimeout, f.DurationVar, "Maximum duration to attempt retries"),
},
},
{
Expand Down Expand Up @@ -177,6 +182,12 @@ func (opts *configLoader) load(enableStrictValidation bool) (*config.Config, err
opts.cfg.Wallets["verifier"] = &opts.verifier.wallet
opts.cfg.Verifier.Enable = true
opts.cfg.Verifier.Wallet = "verifier"
if opts.verifier.MaxRetryBackoff > 0 {
opts.cfg.Verifier.MaxRetryBackoff = opts.verifier.MaxRetryBackoff
}
if opts.verifier.RetryTimeout > 0 {
opts.cfg.Verifier.RetryTimeout = opts.verifier.RetryTimeout
}
}

if opts.submitter.use {
Expand Down
12 changes: 8 additions & 4 deletions cmd/config_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func (s *ConfigLoaderTestSuite) TestLoadConfigFromYAML() {
verifier:
enable: true
wallet: verifier
max_retry_backoff: 1m
retry_timeout: 2m
submitter:
enable: true
Expand Down Expand Up @@ -186,6 +188,8 @@ func (s *ConfigLoaderTestSuite) TestLoadConfigWithVerifierArgs() {
"--config.verifier.wallet.address", "0x08E9441C28c9f34dcB1fa06f773a0450f15B6F43",
"--config.verifier.wallet.password", s.passwdFile1.Name(),
"--config.verifier.wallet.plain", "0x5ea366a14e0bd46e7da7e894c8cc896ebecd1f6452b674aaa41688878f45ff73",
"--config.verifier.max-retry-backoff", "1m",
"--config.verifier.retry-timeout", "2m",
})

s.Equal(want, got)
Expand Down Expand Up @@ -331,14 +335,12 @@ func (s *ConfigLoaderTestSuite) configWithMinCliArgs() *config.Config {
Enable: false,
Wallet: "",
Interval: defaults["verifier.interval"].(time.Duration),
Concurrency: defaults["verifier.concurrency"].(int),
BlockLimit: defaults["verifier.block_limit"].(int),
EventFilterLimit: defaults["verifier.event_filter_limit"].(int),
StateCollectLimit: defaults["verifier.state_collect_limit"].(int),
StateCollectTimeout: defaults["verifier.state_collect_timeout"].(time.Duration),
OptimizeInterval: defaults["verifier.db_optimize_interval"].(time.Duration),
Confirmations: defaults["verifier.confirmations"].(int),
StartBlockOffset: defaults["verifier.start_block_offset"].(uint64),
MaxRetryBackoff: defaults["verifier.max_retry_backoff"].(time.Duration),
RetryTimeout: defaults["verifier.retry_timeout"].(time.Duration),
},
Submitter: config.Submitter{
Enable: false,
Expand Down Expand Up @@ -417,6 +419,8 @@ func (s *ConfigLoaderTestSuite) applyVerifierCliArgs(c *config.Config) {
}
c.Verifier.Enable = true
c.Verifier.Wallet = "verifier"
c.Verifier.MaxRetryBackoff = time.Minute
c.Verifier.RetryTimeout = time.Minute * 2
}

func (s *ConfigLoaderTestSuite) applySubmitterCliArgs(c *config.Config) {
Expand Down
191 changes: 0 additions & 191 deletions collector/block_collector.go

This file was deleted.

Loading

0 comments on commit e00d315

Please sign in to comment.