Skip to content

Commit

Permalink
feat(relayer): confirmations before indexing for relayer should be co…
Browse files Browse the repository at this point in the history
…nfigurable (#18466)
  • Loading branch information
cyberhorsey authored Nov 8, 2024
1 parent 051b619 commit 1fee7bb
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/relayer/.l1indexer.example.env
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ SRC_RPC_URL=wss://l1ws.internal.taiko.xyz
DEST_RPC_URL=wss://ws.internal.taiko.xyz
CORS_ORIGINS=*
NUM_GOROUTINES=50
BLOCK_BATCH_SIZE=100
BLOCK_BATCH_SIZE=100
CONFIRMATIONS_BEFORE_INDEXING=1
8 changes: 8 additions & 0 deletions packages/relayer/cmd/flags/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ var (
Category: indexerCategory,
EnvVars: []string{"WAIT_FOR_CONFIRMATION_TIMEOUT"},
}
IndexingConfirmations = &cli.Uint64Flag{
Name: "confirmations",
Usage: "Confirmations to wait for on source chain before indexing an event",
Value: 1,
Category: indexerCategory,
EnvVars: []string{"CONFIRMATIONS_BEFORE_INDEXING"},
}
)

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

// NewConfigFromCliContext creates a new config instance from command line flags.
Expand Down Expand Up @@ -89,6 +90,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
BackOffRetryInterval: c.Duration(flags.BackOffRetryInterval.Name),
MinFeeToIndex: c.Uint64(flags.MinFeeToIndex.Name),
ConfirmationTimeout: c.Duration(flags.WaitForConfirmationTimeout.Name),
Confirmations: c.Uint64(flags.IndexingConfirmations.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 @@ -40,7 +40,7 @@ func (i *Indexer) handleChainDataSyncedEvent(
if err := relayer.WaitConfirmations(
confCtx,
i.srcEthClient,
uint64(defaultConfirmations),
i.confirmations,
event.Raw.TxHash,
); err != nil {
return err
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 @@ -52,7 +52,7 @@ func (i *Indexer) handleMessageProcessedEvent(
if err := relayer.WaitConfirmations(
confCtx,
i.srcEthClient,
uint64(defaultConfirmations),
i.confirmations,
event.Raw.TxHash,
); err != nil {
return err
Expand Down
6 changes: 1 addition & 5 deletions packages/relayer/indexer/handle_message_sent_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import (
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/queue"
)

var (
defaultConfirmations = 5
)

// handleMessageSentEvent handles an individual MessageSent event
func (i *Indexer) handleMessageSentEvent(
ctx context.Context,
Expand Down Expand Up @@ -61,7 +57,7 @@ func (i *Indexer) handleMessageSentEvent(
if err := relayer.WaitConfirmations(
confCtx,
i.srcEthClient,
uint64(defaultConfirmations),
i.confirmations,
event.Raw.TxHash,
); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions packages/relayer/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ type Indexer struct {
minFeeToIndex uint64

cfg *Config

confirmations uint64
}

// InitFromCli inits a new Indexer from command line or environment variables.
Expand Down Expand Up @@ -234,6 +236,8 @@ func InitFromConfig(ctx context.Context, i *Indexer, cfg *Config) (err error) {

i.cfg = cfg

i.confirmations = cfg.Confirmations

i.ctx = ctx

i.minFeeToIndex = i.cfg.MinFeeToIndex
Expand Down

0 comments on commit 1fee7bb

Please sign in to comment.