Skip to content

Commit

Permalink
improved waiting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
vgeddes committed Dec 5, 2024
1 parent 252e6b2 commit ea64829
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions relayer/relays/beefy/on-demand-sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (relay *OnDemandRelay) Start(ctx context.Context) error {
relay.tokenBucket.Start(ctx)

for {
sleep(ctx, time.Minute*1)
log.Info("Starting check")

paraNonce, ethNonce, err := relay.queryNonces(ctx)
Expand All @@ -105,7 +106,7 @@ func (relay *OnDemandRelay) Start(ctx context.Context) error {

// Check if we are rate-limited
if !relay.tokenBucket.TryConsume(1) {
sleep(ctx, time.Minute*1)
log.Info("Rate-limit exceeded")
continue
}

Expand All @@ -131,12 +132,28 @@ func (relay *OnDemandRelay) Start(ctx context.Context) error {

log.Info("Sync completed")

// Sleep for 10 minute to allow message relayer to sync nonces
// Sleep for 10 minutes to allow message relayer to sync nonces
sleep(ctx, time.Minute*10)
} else {

relay.waitUntilMessagesSynced(ctx, paraNonce)
}
}
}

func (relay *OnDemandRelay) waitUntilMessagesSynced(ctx context.Context, paraNonce uint64) {
for {
ethNonce, err := relay.fetchEthereumNonce(ctx)
if err != nil {
log.WithError(err).Error("fetch latest ethereum nonce")
sleep(ctx, time.Minute*1)
continue
}

if ethNonce >= paraNonce {
return
}
}

}

func sleep(ctx context.Context, d time.Duration) {
Expand Down

0 comments on commit ea64829

Please sign in to comment.