Skip to content

Commit

Permalink
Merge pull request #2507 from OffchainLabs/timeout-for-headerreader-h…
Browse files Browse the repository at this point in the history
…eaderbynumber-calls

Configurable timeout for HeaderReader polling
  • Loading branch information
Tristan-Wilson authored Jul 22, 2024
2 parents 1905917 + 9a82cae commit e645114
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion util/headerreader/header_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Config struct {
Enable bool `koanf:"enable"`
PollOnly bool `koanf:"poll-only" reload:"hot"`
PollInterval time.Duration `koanf:"poll-interval" reload:"hot"`
PollTimeout time.Duration `koanf:"poll-timeout" reload:"hot"`
SubscribeErrInterval time.Duration `koanf:"subscribe-err-interval" reload:"hot"`
TxTimeout time.Duration `koanf:"tx-timeout" reload:"hot"`
OldHeaderTimeout time.Duration `koanf:"old-header-timeout" reload:"hot"`
Expand All @@ -80,6 +81,7 @@ var DefaultConfig = Config{
Enable: true,
PollOnly: false,
PollInterval: 15 * time.Second,
PollTimeout: 5 * time.Second,
SubscribeErrInterval: 5 * time.Minute,
TxTimeout: 5 * time.Minute,
OldHeaderTimeout: 5 * time.Minute,
Expand All @@ -94,6 +96,7 @@ func AddOptions(prefix string, f *flag.FlagSet) {
f.Bool(prefix+".poll-only", DefaultConfig.PollOnly, "do not attempt to subscribe to header events")
f.Bool(prefix+".use-finality-data", DefaultConfig.UseFinalityData, "use l1 data about finalized/safe blocks")
f.Duration(prefix+".poll-interval", DefaultConfig.PollInterval, "interval when polling endpoint")
f.Duration(prefix+".poll-timeout", DefaultConfig.PollTimeout, "timeout when polling endpoint")
f.Duration(prefix+".subscribe-err-interval", DefaultConfig.SubscribeErrInterval, "interval for subscribe error")
f.Duration(prefix+".tx-timeout", DefaultConfig.TxTimeout, "timeout when waiting for a transaction")
f.Duration(prefix+".old-header-timeout", DefaultConfig.OldHeaderTimeout, "warns if the latest l1 block is at least this old")
Expand All @@ -108,6 +111,7 @@ var TestConfig = Config{
Enable: true,
PollOnly: false,
PollInterval: time.Millisecond * 10,
PollTimeout: time.Second * 5,
TxTimeout: time.Second * 5,
OldHeaderTimeout: 5 * time.Minute,
UseFinalityData: false,
Expand Down Expand Up @@ -287,7 +291,9 @@ func (s *HeaderReader) broadcastLoop(ctx context.Context) {
s.possiblyBroadcast(h)
timer.Stop()
case <-timer.C:
h, err := s.client.HeaderByNumber(ctx, nil)
timedCtx, cancelFunc := context.WithTimeout(ctx, s.config().PollTimeout)
h, err := s.client.HeaderByNumber(timedCtx, nil)
cancelFunc()
if err != nil {
s.setError(fmt.Errorf("failed reading HeaderByNumber: %w", err))
if !errors.Is(err, context.Canceled) {
Expand Down

0 comments on commit e645114

Please sign in to comment.