From 3f75d4baf699cca586edf813ab3bc790c5a242a7 Mon Sep 17 00:00:00 2001 From: Franco Barpp Gomes Date: Fri, 8 Nov 2024 06:37:19 +0100 Subject: [PATCH] feat: Add indexer confirmations config --- packages/relayer/.l1indexer.example.env | 3 ++- packages/relayer/cmd/flags/indexer.go | 8 ++++++++ packages/relayer/indexer/config.go | 2 ++ .../relayer/indexer/handle_chain_data_synced_event.go | 2 +- .../relayer/indexer/handle_message_processed_event.go | 2 +- packages/relayer/indexer/handle_message_sent_event.go | 6 +----- packages/relayer/indexer/indexer.go | 4 ++++ 7 files changed, 19 insertions(+), 8 deletions(-) diff --git a/packages/relayer/.l1indexer.example.env b/packages/relayer/.l1indexer.example.env index 8a11abd4a6e..04fda9e1aa0 100644 --- a/packages/relayer/.l1indexer.example.env +++ b/packages/relayer/.l1indexer.example.env @@ -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 \ No newline at end of file +BLOCK_BATCH_SIZE=100 +CONFIRMATIONS_BEFORE_INDEXING=1 \ No newline at end of file diff --git a/packages/relayer/cmd/flags/indexer.go b/packages/relayer/cmd/flags/indexer.go index 72b7aae3cb5..4ca08198afe 100644 --- a/packages/relayer/cmd/flags/indexer.go +++ b/packages/relayer/cmd/flags/indexer.go @@ -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{ @@ -134,4 +141,5 @@ var IndexerFlags = MergeFlags(CommonFlags, QueueFlags, []cli.Flag{ MinFeeToIndex, TargetBlockNumber, WaitForConfirmationTimeout, + IndexingConfirmations, }) diff --git a/packages/relayer/indexer/config.go b/packages/relayer/indexer/config.go index fdc52cdb0fa..9e313af5641 100644 --- a/packages/relayer/indexer/config.go +++ b/packages/relayer/indexer/config.go @@ -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. @@ -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) diff --git a/packages/relayer/indexer/handle_chain_data_synced_event.go b/packages/relayer/indexer/handle_chain_data_synced_event.go index c00a3cf2971..23b1b6d7c11 100644 --- a/packages/relayer/indexer/handle_chain_data_synced_event.go +++ b/packages/relayer/indexer/handle_chain_data_synced_event.go @@ -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 diff --git a/packages/relayer/indexer/handle_message_processed_event.go b/packages/relayer/indexer/handle_message_processed_event.go index 38c04da166a..aab50ac4ebd 100644 --- a/packages/relayer/indexer/handle_message_processed_event.go +++ b/packages/relayer/indexer/handle_message_processed_event.go @@ -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 diff --git a/packages/relayer/indexer/handle_message_sent_event.go b/packages/relayer/indexer/handle_message_sent_event.go index c1e3b79e7c9..e176e144b70 100644 --- a/packages/relayer/indexer/handle_message_sent_event.go +++ b/packages/relayer/indexer/handle_message_sent_event.go @@ -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, @@ -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 diff --git a/packages/relayer/indexer/indexer.go b/packages/relayer/indexer/indexer.go index 3cd92ea5e69..fd5cc8b2557 100644 --- a/packages/relayer/indexer/indexer.go +++ b/packages/relayer/indexer/indexer.go @@ -121,6 +121,8 @@ type Indexer struct { minFeeToIndex uint64 cfg *Config + + confirmations uint64 } // InitFromCli inits a new Indexer from command line or environment variables. @@ -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