Skip to content

Commit

Permalink
Check for cancellation error (#1346)
Browse files Browse the repository at this point in the history
  • Loading branch information
vgeddes authored Dec 5, 2024
1 parent 11eb194 commit f9b3fc2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions relayer/relays/beefy/on-demand-sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package beefy

import (
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -94,6 +95,9 @@ func (relay *OnDemandRelay) Start(ctx context.Context) error {

paraNonce, ethNonce, err := relay.queryNonces(ctx)
if err != nil {
if errors.Is(err, context.Canceled) {
return nil
}
log.WithError(err).Error("Query nonces")
continue
}
Expand All @@ -115,18 +119,27 @@ func (relay *OnDemandRelay) Start(ctx context.Context) error {

beefyBlockHash, err := relay.relaychainConn.API().RPC.Beefy.GetFinalizedHead()
if err != nil {
if errors.Is(err, context.Canceled) {
return nil
}
log.WithError(err).Error("Fetch latest beefy block hash")
continue
}

header, err := relay.relaychainConn.API().RPC.Chain.GetHeader(beefyBlockHash)
if err != nil {
if errors.Is(err, context.Canceled) {
return nil
}
log.WithError(err).Error("Fetch latest beefy block header")
continue
}

err = relay.sync(ctx, uint64(header.Number))
if err != nil {
if errors.Is(err, context.Canceled) {
return nil
}
log.WithError(err).Error("Sync failed")
continue
}
Expand All @@ -143,6 +156,9 @@ func (relay *OnDemandRelay) waitUntilMessagesSynced(ctx context.Context, paraNon
for {
ethNonce, err := relay.fetchEthereumNonce(ctx)
if err != nil {
if errors.Is(err, context.Canceled) {
return
}
log.WithError(err).Error("fetch latest ethereum nonce")
sleep(ctx, time.Minute*1)
continue
Expand Down

0 comments on commit f9b3fc2

Please sign in to comment.