mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-30 10:17:39 +00:00
miner: fix concurrent map access in Miner.HashRate, close XFN-52 (#1634)
This commit is contained in:
parent
f90a12d9f7
commit
76aa15b7d0
2 changed files with 14 additions and 9 deletions
|
|
@ -145,15 +145,7 @@ func (m *Miner) HashRate() (tot int64) {
|
|||
if pow, ok := m.engine.(consensus.PoW); ok {
|
||||
tot += int64(pow.Hashrate())
|
||||
}
|
||||
// do we care this might race? is it worth we're rewriting some
|
||||
// aspects of the worker/locking up agents so we can get an accurate
|
||||
// hashrate?
|
||||
for agent := range m.worker.agents {
|
||||
if _, ok := agent.(*CpuAgent); !ok {
|
||||
tot += agent.GetHashRate()
|
||||
}
|
||||
}
|
||||
return
|
||||
return tot + m.worker.getHashrate()
|
||||
}
|
||||
|
||||
func (m *Miner) SetExtra(extra []byte) error {
|
||||
|
|
|
|||
|
|
@ -379,6 +379,19 @@ func (w *worker) update() {
|
|||
}
|
||||
}
|
||||
|
||||
func (w *worker) getHashrate() int64 {
|
||||
w.mu.Lock()
|
||||
defer w.mu.Unlock()
|
||||
|
||||
total := int64(0)
|
||||
for agent := range w.agents {
|
||||
if _, ok := agent.(*CpuAgent); !ok {
|
||||
total += agent.GetHashRate()
|
||||
}
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
func getResetTime(chain *core.BlockChain, minePeriod int) time.Duration {
|
||||
minePeriodDuration := time.Duration(minePeriod) * time.Second
|
||||
currentBlockTime := int64(chain.CurrentBlock().Time())
|
||||
|
|
|
|||
Loading…
Reference in a new issue