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..3b503e6d 100644 --- a/relayer/chains/evm/provider.go +++ b/relayer/chains/evm/provider.go @@ -178,26 +178,31 @@ 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 { + return txReceipt, fmt.Errorf("tx confirmation timed out [tx hash: %s]", tx.Hash()) } - return txr, err } } }