Only close the sync channel if it is open
@@ -221,7 +221,16 @@ func NewLedger(kv store.KV, client *skademlia.Client, opts ...Option) *Ledger {
// Close stops all goroutines and waits for them to complete.
func (l *Ledger) Close() {
+ syncOpen := true
+ select {
+ case _, syncOpen = <-l.sync:
+ default:
+ }
+
+ if syncOpen {
close(l.sync)
+ }
+
l.consensus.Wait()
close(l.stop)
