diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-12-13 20:03:18 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-12-13 20:04:05 +0800 |
commit | dadd68935935388b158a510c95b8644be44073ce (patch) | |
tree | 43f2d101c1665756693e8dc3d7a95f76862ebd03 /miner | |
parent | b750cab56a724b2ff0bff3fab0849cb776a4f392 (diff) | |
download | go-tangerine-dadd68935935388b158a510c95b8644be44073ce.tar.gz go-tangerine-dadd68935935388b158a510c95b8644be44073ce.tar.zst go-tangerine-dadd68935935388b158a510c95b8644be44073ce.zip |
miner: fix data race on setting etherbase/extradata
Diffstat (limited to 'miner')
-rw-r--r-- | miner/miner.go | 16 | ||||
-rw-r--r-- | miner/worker.go | 6 |
2 files changed, 12 insertions, 10 deletions
diff --git a/miner/miner.go b/miner/miner.go index 87568ac18..61cd3e049 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -119,15 +119,14 @@ func (m *Miner) SetGasPrice(price *big.Int) { func (self *Miner) Start(coinbase common.Address, threads int) { atomic.StoreInt32(&self.shouldStart, 1) - self.threads = threads - self.worker.coinbase = coinbase + self.worker.setEtherbase(coinbase) self.coinbase = coinbase + self.threads = threads if atomic.LoadInt32(&self.canStart) == 0 { glog.V(logger.Info).Infoln("Can not start mining operation due to network sync (starts when finished)") return } - atomic.StoreInt32(&self.mining, 1) for i := 0; i < threads; i++ { @@ -135,9 +134,7 @@ func (self *Miner) Start(coinbase common.Address, threads int) { } glog.V(logger.Info).Infof("Starting mining operation (CPU=%d TOT=%d)\n", threads, len(self.worker.agents)) - self.worker.start() - self.worker.commitNewWork() } @@ -177,8 +174,7 @@ func (self *Miner) SetExtra(extra []byte) error { if uint64(len(extra)) > params.MaximumExtraDataSize.Uint64() { return fmt.Errorf("Extra exceeds max length. %d > %v", len(extra), params.MaximumExtraDataSize) } - - self.worker.extra = extra + self.worker.setExtra(extra) return nil } @@ -188,9 +184,9 @@ func (self *Miner) Pending() (*types.Block, *state.StateDB) { } // PendingBlock returns the currently pending block. -// -// Note, to access both the pending block and the pending state -// simultaneously, please use Pending(), as the pending state can +// +// Note, to access both the pending block and the pending state +// simultaneously, please use Pending(), as the pending state can // change between multiple method calls func (self *Miner) PendingBlock() *types.Block { return self.worker.pendingBlock() diff --git a/miner/worker.go b/miner/worker.go index 5fa7c4115..fdc6b7d8e 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -161,6 +161,12 @@ func (self *worker) setEtherbase(addr common.Address) { self.coinbase = addr } +func (self *worker) setExtra(extra []byte) { + self.mu.Lock() + defer self.mu.Unlock() + self.extra = extra +} + func (self *worker) pending() (*types.Block, *state.StateDB) { self.currentMu.Lock() defer self.currentMu.Unlock() |