ledger: do not stop consensus worker if sync snowball raises a false alarm that we are out of sync
@@ -575,6 +575,16 @@ func (l *Ledger) SyncToLatestRound() {
}
}
+ // Reset syncing Snowball sampler. Check if it is a false alarm such that we don't have to sync.
+
+ current := l.rounds.Latest()
+ proposed := l.syncer.Preferred()
+ l.syncer.Reset()
+
+ if proposed.Index < sys.SyncIfRoundsDifferBy+current.Index {
+ continue
+ }
+
shutdown := func() {
close(l.sync)
l.consensus.Wait() // Wait for all consensus-related workers to shutdown.
@@ -582,6 +592,8 @@ func (l *Ledger) SyncToLatestRound() {
voteWG.Add(1)
close(l.syncVotes)
voteWG.Wait() // Wait for the vote processor worker to shutdown.
+
+ l.finalizer.Reset() // Reset consensus Snowball sampler.
}
restart := func() { // Respawn all previously stopped workers.
@@ -592,22 +604,7 @@ func (l *Ledger) SyncToLatestRound() {
l.PerformConsensus()
}
- shutdown()
-
- // Reset all Snowball samplers.
-
- current := l.rounds.Latest()
- proposed := l.syncer.Preferred()
-
- l.finalizer.Reset()
- l.syncer.Reset()
-
- // Check if it is a false alarm such that we don't have to sync.
-
- if proposed.Index < sys.SyncIfRoundsDifferBy+current.Index {
- restart()
- continue
- }
+ shutdown() // Shutdown all consensus-related workers.
logger := log.Sync("syncing")
logger.Info().
