forked from cerc-io/plugeth
miner: one-shot update loop
This commit is contained in:
parent
207bd55751
commit
907848997b
@ -39,6 +39,10 @@ func New(eth core.Backend, mux *event.TypeMux, pow pow.PoW) *Miner {
|
||||
return miner
|
||||
}
|
||||
|
||||
// update keeps track of the downloader events. Please be aware that this is a one shot type of update loop.
|
||||
// It's entered once and as soon as `Done` or `Failed` has been broadcasted the events are unregistered and
|
||||
// the loop is exited. This to prevent a major security vuln where external parties can DOS you with blocks
|
||||
// and halt your mining operation for as long as the DOS continues.
|
||||
func (self *Miner) update() {
|
||||
events := self.mux.Subscribe(downloader.StartEvent{}, downloader.DoneEvent{}, downloader.FailedEvent{})
|
||||
for ev := range events.Chan() {
|
||||
@ -59,6 +63,8 @@ func (self *Miner) update() {
|
||||
self.Start(self.coinbase, self.threads)
|
||||
}
|
||||
}
|
||||
// unsubscribe. we're only interested in this event once
|
||||
events.Unsubscribe()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user