Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(relayer): Wait N confirmations on source chain before processing message on destination chain #270

Merged
merged 13 commits into from
Nov 16, 2022
9 changes: 7 additions & 2 deletions packages/relayer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func WaitReceipt(ctx context.Context, client *ethclient.Client, tx *types.Transa

// WaitConfirmations won't return before N blocks confirmations have been seen
// on destination chain.
func WaitConfirmations(ctx context.Context, client *ethclient.Client, confirmations uint64, begin uint64) error {
func WaitConfirmations(ctx context.Context, client *ethclient.Client, confirmations uint64, txHash common.Hash) error {
ticker := time.NewTicker(time.Second)
defer ticker.Stop()

Expand All @@ -61,12 +61,17 @@ func WaitConfirmations(ctx context.Context, client *ethclient.Client, confirmati
case <-ctx.Done():
return ctx.Err()
case <-ticker.C:
receipt, err := client.TransactionReceipt(ctx, txHash)
davidtaikocha marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}

latest, err := client.BlockNumber(ctx)
davidtaikocha marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}

if latest < begin+confirmations {
if latest < receipt.BlockNumber.Uint64()+confirmations {
continue
}

Expand Down