Skip to content

Commit 2c3a014

Browse files
committed
Resolved some bugs in the miner
* TODO nonce error sometimes persists * Fixed mining on wrong blocks * Fixed state error & receipt fail
1 parent c924a84 commit 2c3a014

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

cmd/mist/assets/qml/views/transaction.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Rectangle {
177177
mainContractColumn.state = "ERROR"
178178
} else {
179179
txResult.text = "Your transaction has been submitted:\n"
180-
txOutput.text = res[0].address
180+
txOutput.text = res.toString()
181181
mainContractColumn.state = "DONE"
182182

183183
console.log(res)

core/chain_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
392392

393393
self.setTotalDifficulty(td)
394394
self.insert(block)
395-
self.transState = state.New(cblock.Root(), self.db) //state.New(cblock.Trie().Copy())
395+
self.transState = state.New(cblock.Root(), self.db)
396396

397397
self.eventMux.Post(ChainEvent{block, td})
398398
}

miner/worker.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"math/big"
66
"sort"
7+
"sync"
78

89
"github.com/ethereum/go-ethereum/core"
910
"github.com/ethereum/go-ethereum/core/types"
@@ -55,6 +56,7 @@ type Agent interface {
5556
}
5657

5758
type worker struct {
59+
mu sync.Mutex
5860
agents []Agent
5961
recv chan Work
6062
mux *event.TypeMux
@@ -115,9 +117,7 @@ out:
115117
select {
116118
case event := <-events.Chan():
117119
switch event.(type) {
118-
case core.ChainEvent:
119-
self.commitNewWork()
120-
case core.TxPreEvent:
120+
case core.ChainEvent, core.TxPreEvent:
121121
self.commitNewWork()
122122
}
123123
case <-self.quit:
@@ -163,6 +163,9 @@ func (self *worker) push() {
163163
}
164164

165165
func (self *worker) commitNewWork() {
166+
self.mu.Lock()
167+
defer self.mu.Unlock()
168+
166169
self.current = env(self.chain.NewBlock(self.coinbase), self.eth)
167170
parent := self.chain.GetBlock(self.current.block.ParentHash())
168171
self.current.coinbase.SetGasPool(core.CalcGasLimit(parent, self.current.block))
@@ -176,12 +179,11 @@ func (self *worker) commitNewWork() {
176179
err := self.commitTransaction(tx)
177180
switch {
178181
case core.IsNonceErr(err):
182+
// Remove invalid transactions
179183
remove = append(remove, tx)
180184
case core.IsGasLimitErr(err):
181185
// Break on gas limit
182186
break
183-
default:
184-
remove = append(remove, tx)
185187
}
186188

187189
if err != nil {
@@ -227,16 +229,13 @@ func (self *worker) commitUncle(uncle *types.Header) error {
227229

228230
func (self *worker) commitTransaction(tx *types.Transaction) error {
229231
snapshot := self.current.state.Copy()
230-
receipt, txGas, err := self.proc.ApplyTransaction(self.current.coinbase, self.current.state, self.current.block, tx, self.current.totalUsedGas, true)
231-
if err != nil {
232-
if core.IsNonceErr(err) || core.IsGasLimitErr(err) {
233-
self.current.state.Set(snapshot)
234-
}
232+
receipt, _, err := self.proc.ApplyTransaction(self.current.coinbase, self.current.state, self.current.block, tx, self.current.totalUsedGas, true)
233+
if err != nil && (core.IsNonceErr(err) || core.IsGasLimitErr(err)) {
234+
self.current.state.Set(snapshot)
235235

236236
return err
237237
}
238238

239-
self.current.totalUsedGas.Add(self.current.totalUsedGas, txGas)
240239
self.current.block.AddTransaction(tx)
241240
self.current.block.AddReceipt(receipt)
242241

0 commit comments

Comments
 (0)