Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove stopCh from eth/handler #82

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここのループも問題なく抜けます。
Unsubscribeすると、対応するチャンネルがクローズされるので。

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