Skip to content

Commit

Permalink
remove stop chan from eth/handler (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
tak1827 authored Oct 18, 2024
1 parent 2ef28a8 commit 10fc075
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ type handler struct {

// channels for fetcher, syncer, txsyncLoop
quitSync chan struct{}
stopCh chan struct{}

chainSync *chainSyncer
wg sync.WaitGroup
Expand Down Expand Up @@ -182,7 +181,6 @@ func newHandler(config *handlerConfig) (*handler, error) {
quitSync: make(chan struct{}),
handlerDoneCh: make(chan struct{}),
handlerStartCh: make(chan struct{}),
stopCh: make(chan struct{}),
}
if config.Sync == downloader.FullSync {
// The database seems empty as the current block is the genesis. Yet the snap
Expand Down Expand Up @@ -630,7 +628,6 @@ func (h *handler) Stop() {
h.voteMonitorSub.Unsubscribe()
}
}
close(h.stopCh)
// Quit chainSync and txsync64.
// After this is done, no new peers will be accepted.
close(h.quitSync)
Expand Down Expand Up @@ -789,18 +786,10 @@ func (h *handler) BroadcastVote(vote *types.VoteEnvelope) {
func (h *handler) minedBroadcastLoop() {
defer h.wg.Done()

for {
select {
case obj := <-h.minedBlockSub.Chan():
if obj == nil {
continue
}
if ev, ok := obj.Data.(core.NewMinedBlockEvent); ok {
h.BroadcastBlock(ev.Block, true) // First propagate block to peers
h.BroadcastBlock(ev.Block, false) // Only then announce to the rest
}
case <-h.stopCh:
return
for obj := range h.minedBlockSub.Chan() {
if ev, ok := obj.Data.(core.NewMinedBlockEvent); ok {
h.BroadcastBlock(ev.Block, true) // First propagate block to peers
h.BroadcastBlock(ev.Block, false) // Only then announce to the rest
}
}
}
Expand All @@ -814,8 +803,6 @@ func (h *handler) txBroadcastLoop() {
h.BroadcastTransactions(event.Txs)
case <-h.txsSub.Err():
return
case <-h.stopCh:
return
}
}
}
Expand All @@ -831,8 +818,6 @@ func (h *handler) voteBroadcastLoop() {
h.BroadcastVote(event.Vote)
case <-h.votesSub.Err():
return
case <-h.stopCh:
return
}
}
}
Expand All @@ -848,8 +833,6 @@ func (h *handler) startMaliciousVoteMonitor() {
h.maliciousVoteMonitor.ConflictDetect(event.Vote, pendingBlockNumber)
case <-h.voteMonitorSub.Err():
return
case <-h.stopCh:
return
}
}
}
Expand Down

0 comments on commit 10fc075

Please sign in to comment.