Skip to content

Commit

Permalink
feat(relayer): configurable conf timeout, increase default (#17880)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey authored Aug 6, 2024
1 parent 92344df commit 7bf7d69
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
10 changes: 10 additions & 0 deletions packages/relayer/cmd/flags/indexer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package flags

import (
"time"

"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -107,6 +109,13 @@ var (
Value: 0,
EnvVars: []string{"MIN_FEE_TO_INDEX"},
}
WaitForConfirmationTimeout = &cli.DurationFlag{
Name: "waitForConfirmationTimeout",
Usage: "Timeout waiting for confirmations",
Value: 5 * time.Minute,
Category: indexerCategory,
EnvVars: []string{"WAIT_FOR_CONFIRMATION_TIMEOUT"},
}
)

var IndexerFlags = MergeFlags(CommonFlags, QueueFlags, []cli.Flag{
Expand All @@ -124,4 +133,5 @@ var IndexerFlags = MergeFlags(CommonFlags, QueueFlags, []cli.Flag{
EventName,
MinFeeToIndex,
TargetBlockNumber,
WaitForConfirmationTimeout,
})
2 changes: 2 additions & 0 deletions packages/relayer/indexer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Config struct {
MinFeeToIndex uint64
OpenQueueFunc func() (queue.Queue, error)
OpenDBFunc func() (db.DB, error)
ConfirmationTimeout time.Duration
}

// NewConfigFromCliContext creates a new config instance from command line flags.
Expand Down Expand Up @@ -87,6 +88,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
BackOffMaxRetries: c.Uint64(flags.BackOffMaxRetrys.Name),
BackOffRetryInterval: c.Duration(flags.BackOffRetryInterval.Name),
MinFeeToIndex: c.Uint64(flags.MinFeeToIndex.Name),
ConfirmationTimeout: c.Duration(flags.WaitForConfirmationTimeout.Name),
TargetBlockNumber: func() *uint64 {
if c.IsSet(flags.TargetBlockNumber.Name) {
value := c.Uint64(flags.TargetBlockNumber.Name)
Expand Down
2 changes: 1 addition & 1 deletion packages/relayer/indexer/handle_chain_data_synced_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (i *Indexer) handleChainDataSyncedEvent(

// we need to wait for confirmations to confirm this event is not being reverted,
// removed, or reorged now.
confCtx, confCtxCancel := context.WithTimeout(ctx, defaultCtxTimeout)
confCtx, confCtxCancel := context.WithTimeout(ctx, i.cfg.ConfirmationTimeout)

defer confCtxCancel()

Expand Down
2 changes: 1 addition & 1 deletion packages/relayer/indexer/handle_message_processed_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (i *Indexer) handleMessageProcessedEvent(
if waitForConfirmations {
// we need to wait for confirmations to confirm this event is not being reverted,
// removed, or reorged now.
confCtx, confCtxCancel := context.WithTimeout(ctx, defaultCtxTimeout)
confCtx, confCtxCancel := context.WithTimeout(ctx, i.cfg.ConfirmationTimeout)

defer confCtxCancel()

Expand Down
4 changes: 1 addition & 3 deletions packages/relayer/indexer/handle_message_sent_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"math/big"
"time"

"log/slog"

Expand All @@ -17,7 +16,6 @@ import (
)

var (
defaultCtxTimeout = 3 * time.Minute
defaultConfirmations = 5
)

Expand Down Expand Up @@ -56,7 +54,7 @@ func (i *Indexer) handleMessageSentEvent(
if waitForConfirmations {
// we need to wait for confirmations to confirm this event is not being reverted,
// removed, or reorged now.
confCtx, confCtxCancel := context.WithTimeout(ctx, defaultCtxTimeout)
confCtx, confCtxCancel := context.WithTimeout(ctx, i.cfg.ConfirmationTimeout)

defer confCtxCancel()

Expand Down

0 comments on commit 7bf7d69

Please sign in to comment.