From cb9b50ec75e0c71ef3444c1f2b9dbcb560268deb Mon Sep 17 00:00:00 2001 From: sherpalden Date: Mon, 16 Dec 2024 15:12:30 +0545 Subject: [PATCH 1/2] fix: wait for tx result for evm properly --- relayer/chains/evm/client.go | 5 ++--- relayer/chains/evm/provider.go | 31 ++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/relayer/chains/evm/client.go b/relayer/chains/evm/client.go index cfe8bbf6..bbfe8363 100644 --- a/relayer/chains/evm/client.go +++ b/relayer/chains/evm/client.go @@ -17,9 +17,8 @@ import ( ) const ( - DefaultPollingInterval = time.Second * 30 - MaximumPollTry = 15 - DefaultCreateTimeout = time.Second * 10 + DefaultTxConfirmationTimeout = time.Second * 45 + DefaultCreateTimeout = time.Second * 10 ) func newClient(ctx context.Context, connectionContract, XcallContract common.Address, rpcUrl, websocketUrl string, l *zap.Logger) (IClient, error) { diff --git a/relayer/chains/evm/provider.go b/relayer/chains/evm/provider.go index 3974dce2..ddbec03e 100644 --- a/relayer/chains/evm/provider.go +++ b/relayer/chains/evm/provider.go @@ -178,26 +178,35 @@ func (p *Provider) FinalityBlock(ctx context.Context) uint64 { } func (p *Provider) WaitForResults(ctx context.Context, tx *ethTypes.Transaction) (*coreTypes.Receipt, error) { - ticker := time.NewTicker(DefaultPollingInterval) + ticker := time.NewTicker(3 * time.Second) defer ticker.Stop() - counter := 0 + startTime := time.Now() for { select { case <-ctx.Done(): return nil, ctx.Err() case <-ticker.C: - if counter >= MaximumPollTry { - return nil, fmt.Errorf("failed to get receipt after %d tries", counter) + txReceipt, err := p.client.TransactionReceipt(ctx, tx.Hash()) + if err != nil && !errors.Is(err, ethereum.NotFound) { + return txReceipt, err } - counter++ - txr, err := p.client.TransactionReceipt(ctx, tx.Hash()) - if err == nil { - return txr, nil + + if txReceipt != nil { + if txReceipt.Status == ethTypes.ReceiptStatusFailed { + return txReceipt, fmt.Errorf("txn failed [tx hash: %s]", tx.Hash()) + } else { + return txReceipt, nil + } } - if errors.Is(err, ethereum.NotFound) { - continue + + // handle txn not found case: + if time.Since(startTime) > DefaultTxConfirmationTimeout { + if err != nil { + return txReceipt, err + } else { + return txReceipt, fmt.Errorf("tx confirmation timed out [tx hash: %s]", tx.Hash()) + } } - return txr, err } } } From 2f4c5856b1368226ed140c9e8d6a9628837125a7 Mon Sep 17 00:00:00 2001 From: sherpalden Date: Mon, 16 Dec 2024 15:14:57 +0545 Subject: [PATCH 2/2] fix: remove unncessary error handling --- relayer/chains/evm/provider.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/relayer/chains/evm/provider.go b/relayer/chains/evm/provider.go index ddbec03e..3b503e6d 100644 --- a/relayer/chains/evm/provider.go +++ b/relayer/chains/evm/provider.go @@ -201,11 +201,7 @@ func (p *Provider) WaitForResults(ctx context.Context, tx *ethTypes.Transaction) // handle txn not found case: if time.Since(startTime) > DefaultTxConfirmationTimeout { - if err != nil { - return txReceipt, err - } else { - return txReceipt, fmt.Errorf("tx confirmation timed out [tx hash: %s]", tx.Hash()) - } + return txReceipt, fmt.Errorf("tx confirmation timed out [tx hash: %s]", tx.Hash()) } } }