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

fix(concurrency): remove unused sync cond #706

Merged
merged 4 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ type Manager struct {
// Synchronization
syncTargetDiode diodes.Diode

syncTarget atomic.Uint64
isSyncedCond sync.Cond
syncTarget atomic.Uint64

// Block production
shouldProduceBlocksCh chan bool
Expand Down Expand Up @@ -116,7 +115,6 @@ func NewManager(
retriever: dalc.(da.BatchRetriever),
// channels are buffered to avoid blocking on input/output operations, buffer sizes are arbitrary
syncTargetDiode: diodes.NewOneToOne(1, nil),
isSyncedCond: *sync.NewCond(new(sync.Mutex)),
shouldProduceBlocksCh: make(chan bool, 1),
produceEmptyBlockCh: make(chan bool, 1),
logger: logger,
Expand Down
15 changes: 7 additions & 8 deletions block/retriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ func (m *Manager) RetriveLoop(ctx context.Context) {
if err != nil {
panic(err)
}
// Check if after we sync we are synced or a new syncTarget was already set.
// If we are synced then signal all goroutines waiting on isSyncedCond.
if m.store.Height() >= m.syncTarget.Load() {
m.logger.Info("Synced at height", "height", m.store.Height())
m.isSyncedCond.L.Lock()
m.isSyncedCond.Signal()
m.isSyncedCond.L.Unlock()
}
}
}
}
Expand All @@ -43,6 +35,12 @@ func (m *Manager) RetriveLoop(ctx context.Context) {
// the actual blocks from the DA.
func (m *Manager) syncUntilTarget(ctx context.Context, syncTarget uint64) error {
currentHeight := m.store.Height()

if currentHeight >= syncTarget {
m.logger.Info("Already synced", "current height", currentHeight, "syncTarget", syncTarget)
return nil
}

for currentHeight < syncTarget {
currStateIdx := atomic.LoadUint64(&m.lastState.SLStateIndex) + 1
m.logger.Info("Syncing until target", "height", currentHeight, "state_index", currStateIdx, "syncTarget", syncTarget)
Expand All @@ -63,6 +61,7 @@ func (m *Manager) syncUntilTarget(ctx context.Context, syncTarget uint64) error
return err
}
}
m.logger.Info("Synced", "current height", currentHeight, "syncTarget", syncTarget)
return nil
}

Expand Down
Loading