From c251c975dc93fd3549fc1e1ce09faa1b2fdab867 Mon Sep 17 00:00:00 2001 From: danwt <30197399+danwt@users.noreply.github.com> Date: Wed, 17 Apr 2024 13:19:35 +0100 Subject: [PATCH 1/3] remove unused sync cond --- block/manager.go | 3 +-- block/retriever.go | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/block/manager.go b/block/manager.go index d79360d2c..0f321e545 100644 --- a/block/manager.go +++ b/block/manager.go @@ -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 diff --git a/block/retriever.go b/block/retriever.go index 906caae7a..b2cff783d 100644 --- a/block/retriever.go +++ b/block/retriever.go @@ -30,9 +30,6 @@ func (m *Manager) RetriveLoop(ctx context.Context) { // 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() } } } From 436709a46520ea0d4b8d057b42ea14b4a50308a9 Mon Sep 17 00:00:00 2001 From: danwt <30197399+danwt@users.noreply.github.com> Date: Wed, 17 Apr 2024 13:54:45 +0100 Subject: [PATCH 2/3] remove from constructor --- block/manager.go | 1 - 1 file changed, 1 deletion(-) diff --git a/block/manager.go b/block/manager.go index 0f321e545..8253d470f 100644 --- a/block/manager.go +++ b/block/manager.go @@ -115,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, From 043cb47e33157a895a129d9981d1d6943bb364e6 Mon Sep 17 00:00:00 2001 From: Michael Tsitrin Date: Thu, 18 Apr 2024 00:25:11 +0300 Subject: [PATCH 3/3] removed redundent snippet and added logging --- block/retriever.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/block/retriever.go b/block/retriever.go index b2cff783d..53dbe4232 100644 --- a/block/retriever.go +++ b/block/retriever.go @@ -26,11 +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()) - } } } } @@ -40,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) @@ -60,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 }