aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-03-16 19:12:46 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-03-16 19:12:46 +0800
commit138e7af96c2316f38f0ba8c7692253a7ad97ffba (patch)
tree67ad9e1d6ff43acf35cbc5073738806ea3f871d0
parent8b6ae6bf86091483a7514b272bafcf730def0200 (diff)
parent0228fb57cd58147ab2c3914520c7805e25a8a1c4 (diff)
downloadgo-tangerine-138e7af96c2316f38f0ba8c7692253a7ad97ffba.tar
go-tangerine-138e7af96c2316f38f0ba8c7692253a7ad97ffba.tar.gz
go-tangerine-138e7af96c2316f38f0ba8c7692253a7ad97ffba.tar.bz2
go-tangerine-138e7af96c2316f38f0ba8c7692253a7ad97ffba.tar.lz
go-tangerine-138e7af96c2316f38f0ba8c7692253a7ad97ffba.tar.xz
go-tangerine-138e7af96c2316f38f0ba8c7692253a7ad97ffba.tar.zst
go-tangerine-138e7af96c2316f38f0ba8c7692253a7ad97ffba.zip
Merge pull request #2354 from karalabe/miner-atomic-pending
eth, miner: fetch pending block/state in on go (data race)
-rw-r--r--eth/api.go6
-rw-r--r--miner/miner.go9
-rw-r--r--miner/worker.go12
3 files changed, 10 insertions, 17 deletions
diff --git a/eth/api.go b/eth/api.go
index 487d24ae7..c16c3d142 100644
--- a/eth/api.go
+++ b/eth/api.go
@@ -56,7 +56,8 @@ const defaultGas = uint64(90000)
func blockByNumber(m *miner.Miner, bc *core.BlockChain, blockNr rpc.BlockNumber) *types.Block {
// Pending block is only known by the miner
if blockNr == rpc.PendingBlockNumber {
- return m.PendingBlock()
+ block, _ := m.Pending()
+ return block
}
// Otherwise resolve and return the block
if blockNr == rpc.LatestBlockNumber {
@@ -72,7 +73,8 @@ func blockByNumber(m *miner.Miner, bc *core.BlockChain, blockNr rpc.BlockNumber)
func stateAndBlockByNumber(m *miner.Miner, bc *core.BlockChain, blockNr rpc.BlockNumber, chainDb ethdb.Database) (*state.StateDB, *types.Block, error) {
// Pending state is only known by the miner
if blockNr == rpc.PendingBlockNumber {
- return m.PendingState(), m.PendingBlock(), nil
+ block, state := m.Pending()
+ return state, block, nil
}
// Otherwise resolve the block number and return its state
block := blockByNumber(m, bc, blockNr)
diff --git a/miner/miner.go b/miner/miner.go
index 6d4a84f1a..e52cefaab 100644
--- a/miner/miner.go
+++ b/miner/miner.go
@@ -164,12 +164,9 @@ func (self *Miner) SetExtra(extra []byte) error {
return nil
}
-func (self *Miner) PendingState() *state.StateDB {
- return self.worker.pendingState()
-}
-
-func (self *Miner) PendingBlock() *types.Block {
- return self.worker.pendingBlock()
+// Pending returns the currently pending block and associated state.
+func (self *Miner) Pending() (*types.Block, *state.StateDB) {
+ return self.worker.pending()
}
func (self *Miner) SetEtherbase(addr common.Address) {
diff --git a/miner/worker.go b/miner/worker.go
index f3e95cb5f..108b2d6b5 100644
--- a/miner/worker.go
+++ b/miner/worker.go
@@ -152,13 +152,7 @@ func (self *worker) setEtherbase(addr common.Address) {
self.coinbase = addr
}
-func (self *worker) pendingState() *state.StateDB {
- self.currentMu.Lock()
- defer self.currentMu.Unlock()
- return self.current.state
-}
-
-func (self *worker) pendingBlock() *types.Block {
+func (self *worker) pending() (*types.Block, *state.StateDB) {
self.currentMu.Lock()
defer self.currentMu.Unlock()
@@ -168,9 +162,9 @@ func (self *worker) pendingBlock() *types.Block {
self.current.txs,
nil,
self.current.receipts,
- )
+ ), self.current.state
}
- return self.current.Block
+ return self.current.Block, self.current.state
}
func (self *worker) start() {