Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,19 +754,27 @@ func (s *Ethereum) startCheckpointWhitelistService() {
s.retryHeimdallHandler(s.fetchAndHandleWhitelistCheckpoint, tickerDuration, whitelistTimeout)
}

// startMilestoneWhitelistService starts the goroutine to fetch milestiones and update the
// milestone whitelist map.
// startMilestoneWhitelistService starts the goroutine that updates the milestone whitelist map.
// It subscribes to milestone events from heimdall via websocket when available, and falls back
// to polling otherwise.
Comment thread
kamuikatsurgi marked this conversation as resolved.
func (s *Ethereum) startMilestoneWhitelistService() {
ethHandler, bor, _ := s.getHandler()

const (
tickerDuration = 2 * time.Second
)

// If heimdall ws is available use WS subscription to new milestone events instead of polling
// If heimdall WS is available, use WS subscription for new milestone events instead of polling
if bor != nil && bor.HeimdallWSClient != nil {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
<-s.closeCh
cancel()
}()

for {
if err := s.subscribeAndHandleMilestone(context.Background(), ethHandler, bor); err != nil {
if err := s.subscribeAndHandleMilestone(ctx, ethHandler, bor); err != nil {
log.Error("Error subscribing to milestone events", "err", err)
}

Expand All @@ -775,7 +783,7 @@ func (s *Ethereum) startMilestoneWhitelistService() {
case <-s.closeCh:
return
case <-time.After(tickerDuration):
// Continue to retry subscribing to milestone event
// Continue to retry subscribing to milestone events
}
}
}
Expand Down
Loading