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

fix: ungraceful shutdown caused by malicious Vote Monitor #1663

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: 14 additions & 11 deletions eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,15 @@ type handler struct {
peers *peerSet
merger *consensus.Merger

eventMux *event.TypeMux
txsCh chan core.NewTxsEvent
txsSub event.Subscription
reannoTxsCh chan core.ReannoTxsEvent
reannoTxsSub event.Subscription
minedBlockSub *event.TypeMuxSubscription
voteCh chan core.NewVoteEvent
votesSub event.Subscription
eventMux *event.TypeMux
txsCh chan core.NewTxsEvent
txsSub event.Subscription
reannoTxsCh chan core.ReannoTxsEvent
reannoTxsSub event.Subscription
minedBlockSub *event.TypeMuxSubscription
voteCh chan core.NewVoteEvent
votesSub event.Subscription
voteMonitorSub event.Subscription

whitelist map[uint64]common.Hash

Expand Down Expand Up @@ -714,14 +715,13 @@ func (h *handler) Start(maxPeers int, maxPeersPerIP int) {
func (h *handler) startMaliciousVoteMonitor() {
defer h.wg.Done()
voteCh := make(chan core.NewVoteEvent, voteChanSize)
votesSub := h.votepool.SubscribeNewVoteEvent(voteCh)
defer votesSub.Unsubscribe()
h.voteMonitorSub = h.votepool.SubscribeNewVoteEvent(voteCh)
for {
select {
case event := <-voteCh:
pendingBlockNumber := h.chain.CurrentHeader().Number.Uint64() + 1
h.maliciousVoteMonitor.ConflictDetect(event.Vote, pendingBlockNumber)
case <-votesSub.Err():
case <-h.voteMonitorSub.Err():
return
}
}
Expand All @@ -733,6 +733,9 @@ func (h *handler) Stop() {
h.minedBlockSub.Unsubscribe() // quits blockBroadcastLoop
if h.votepool != nil {
h.votesSub.Unsubscribe() // quits voteBroadcastLoop
if h.maliciousVoteMonitor != nil {
h.voteMonitorSub.Unsubscribe()
}
}

// Quit chainSync and txsync64.
Expand Down