Skip to content

Commit

Permalink
Simplify the flow of sync when the DB is readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
omerfirmak committed Nov 7, 2023
1 parent 2d84d88 commit 82e738e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,19 +233,22 @@ func (s *Synchronizer) syncBlocks(syncCtx context.Context) {
s.highestBlockHeader.Store(nil)
}()

fetchers, verifiers := s.setupWorkers()
streamCtx, streamCancel := context.WithCancel(syncCtx)

nextHeight := s.nextHeight()
startingHeight := nextHeight
s.startingBlockNumber = &startingHeight

pendingSem := make(chan struct{}, 1)
if !s.readOnlyBlockchain {
go s.pollPending(syncCtx, pendingSem)
}
latestSem := make(chan struct{}, 1)
if s.readOnlyBlockchain {
s.pollLatest(syncCtx, latestSem)
return
}

fetchers, verifiers := s.setupWorkers()
streamCtx, streamCancel := context.WithCancel(syncCtx)

go s.pollLatest(syncCtx, latestSem)
pendingSem := make(chan struct{}, 1)
go s.pollPending(syncCtx, pendingSem)

for {
select {
Expand All @@ -266,9 +269,6 @@ func (s *Synchronizer) syncBlocks(syncCtx context.Context) {
s.log.Warnw("Restarting sync process", "height", nextHeight, "catchUpMode", s.catchUpMode)
}
default:
if s.readOnlyBlockchain {
<-streamCtx.Done()
}
curHeight, curStreamCtx, curCancel := nextHeight, streamCtx, streamCancel
fetchers.Go(func() stream.Callback {
fetchTimer := time.Now()
Expand Down

0 comments on commit 82e738e

Please sign in to comment.