Skip to content

Commit

Permalink
fix(relayer): func WaitConfirmations should not wait forever for ethe…
Browse files Browse the repository at this point in the history
…reum.NotFound (#16547)
  • Loading branch information
xiaodino committed Mar 28, 2024
1 parent 61ca676 commit 5578687
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/relayer/processor/process_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (p *Processor) processMessage(

slog.Info("waiting for confirmations",
"msgHash", common.BytesToHash(msgBody.Event.MsgHash[:]).Hex(),
"txHash", msgBody.Event.Raw.TxHash,
)

if err := p.waitForConfirmations(ctx, msgBody.Event.Raw.TxHash, msgBody.Event.Raw.BlockNumber); err != nil {
Expand Down
14 changes: 12 additions & 2 deletions packages/relayer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ var (

// WaitConfirmations won't return before N blocks confirmations have been seen
// on destination chain, or context is cancelled.
// txHash is from Raw.TxHash in event or SignalServiceChainDataSynced.
func WaitConfirmations(ctx context.Context, confirmer confirmer, confirmations uint64, txHash common.Hash) error {
notFoundCount := 0

checkConfs := func() error {
receipt, err := confirmer.TransactionReceipt(ctx, txHash)
if err != nil {
Expand All @@ -83,7 +86,7 @@ func WaitConfirmations(ctx context.Context, confirmer confirmer, confirmations u
want := receipt.BlockNumber.Uint64() + confirmations

if latest < want {
slog.Info("waiting for confirmations", "latestBlockNum", latest, "wantBlockNum", want)
slog.Info("waiting for confirmations", "latestBlockNum", latest, "wantBlockNum", want, "txHash", txHash.Hex())

return errStillWaiting
}
Expand All @@ -107,7 +110,14 @@ func WaitConfirmations(ctx context.Context, confirmer confirmer, confirmations u
return ctx.Err()
case <-ticker.C:
if err := checkConfs(); err != nil {
if err == ethereum.NotFound || err == errStillWaiting {
if err == ethereum.NotFound {
notFoundCount++
if notFoundCount >= 10 {
return err
}

continue
} else if err == errStillWaiting {
continue
}

Expand Down

0 comments on commit 5578687

Please sign in to comment.