From d4fad67f2c05a3529a95882cbcab9c7149846609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 28 Jan 2024 15:17:58 +0000 Subject: [PATCH] vochain/indexer: remove recoveryBootLock The blockMu mutex already prevents Commit and AfterSyncBootstrap to both run at the same time, so this mutex is now unnecessary. --- vochain/indexer/indexer.go | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/vochain/indexer/indexer.go b/vochain/indexer/indexer.go index 390128e4d..aa336fdea 100644 --- a/vochain/indexer/indexer.go +++ b/vochain/indexer/indexer.go @@ -89,9 +89,6 @@ type Indexer struct { // eventOnResults is the list of external callbacks that will be executed by the indexer eventOnResults []EventListener - // recoveryBootLock prevents Commit() to add new votes while the recovery bootstratp is - // being executed. - recoveryBootLock sync.RWMutex // ignoreLiveResults if true, partial/live results won't be calculated (only final results) ignoreLiveResults bool } @@ -300,13 +297,10 @@ func (idx *Indexer) AfterSyncBootstrap(inTest bool) { } log.Infof("running indexer after-sync bootstrap") - // Block the new votes addition until the recovery finishes. - // TODO: perhaps redundant with lockPool now? - idx.recoveryBootLock.Lock() - defer idx.recoveryBootLock.Unlock() - + // Note that holding blockMu means new votes aren't added until the recovery finishes. idx.blockMu.Lock() defer idx.blockMu.Unlock() + queries := idx.blockTxQueries() ctx := context.TODO() @@ -479,15 +473,9 @@ func (idx *Indexer) Commit(height uint32) error { } } // Commit votes (store to disk) - func() { - // If the recovery bootstrap is running, wait - idx.recoveryBootLock.RLock() - defer idx.recoveryBootLock.RUnlock() - - if err := idx.commitVotesUnsafe(queries, pid, proc.Results(), addedResults, subtractedResults, idx.App.Height()); err != nil { - log.Errorf("cannot commit live votes from block %d: (%v)", err, height) - } - }() + if err := idx.commitVotesUnsafe(queries, pid, proc.Results(), addedResults, subtractedResults, idx.App.Height()); err != nil { + log.Errorf("cannot commit live votes from block %d: (%v)", err, height) + } } clear(idx.votePool)