@@ -263,8 +263,9 @@ func (self *worker) wait() {
263
263
continue
264
264
}
265
265
block := result .Block
266
+ work := result .Work
266
267
267
- self . current .state .Sync ()
268
+ work .state .Sync ()
268
269
if self .fullValidation {
269
270
if _ , err := self .chain .InsertChain (types.Blocks {block }); err != nil {
270
271
glog .V (logger .Error ).Infoln ("mining err" , err )
@@ -292,7 +293,7 @@ func (self *worker) wait() {
292
293
// This puts transactions in a extra db for rpc
293
294
core .PutTransactions (self .extraDb , block , block .Transactions ())
294
295
// store the receipts
295
- core .PutReceipts (self .extraDb , self . current .receipts )
296
+ core .PutReceipts (self .extraDb , work .receipts )
296
297
}
297
298
298
299
// broadcast before waiting for validation
@@ -303,7 +304,7 @@ func (self *worker) wait() {
303
304
self .mux .Post (core.ChainHeadEvent {block })
304
305
self .mux .Post (logs )
305
306
}
306
- }(block , self . current .state .Logs ())
307
+ }(block , work .state .Logs ())
307
308
}
308
309
309
310
// check staleness and display confirmation
@@ -313,7 +314,7 @@ func (self *worker) wait() {
313
314
stale = "stale "
314
315
} else {
315
316
confirm = "Wait 5 blocks for confirmation"
316
- self . current . localMinedBlocks = newLocalMinedBlock (block .Number ().Uint64 (), self . current .localMinedBlocks )
317
+ work . localMinedBlocks = newLocalMinedBlock (block .Number ().Uint64 (), work .localMinedBlocks )
317
318
}
318
319
glog .V (logger .Info ).Infof ("🔨 Mined %sblock (#%v / %x). %s" , stale , block .Number (), block .Hash ().Bytes ()[:4 ], confirm )
319
320
@@ -322,9 +323,9 @@ func (self *worker) wait() {
322
323
}
323
324
}
324
325
325
- func (self * worker ) push () {
326
+ func (self * worker ) push (work * Work ) {
326
327
if atomic .LoadInt32 (& self .mining ) == 1 {
327
- if core .Canary (self . current .state ) {
328
+ if core .Canary (work .state ) {
328
329
glog .Infoln ("Toxicity levels rising to deadly levels. Your canary has died. You can go back or continue down the mineshaft --more--" )
329
330
glog .Infoln ("You turn back and abort mining" )
330
331
return
@@ -335,7 +336,7 @@ func (self *worker) push() {
335
336
atomic .AddInt32 (& self .atWork , 1 )
336
337
337
338
if agent .Work () != nil {
338
- agent .Work () <- self . current
339
+ agent .Work () <- work
339
340
}
340
341
}
341
342
}
@@ -344,7 +345,7 @@ func (self *worker) push() {
344
345
// makeCurrent creates a new environment for the current cycle.
345
346
func (self * worker ) makeCurrent (parent * types.Block , header * types.Header ) {
346
347
state := state .New (parent .Root (), self .eth .StateDb ())
347
- current := & Work {
348
+ work := & Work {
348
349
state : state ,
349
350
ancestors : set .New (),
350
351
family : set .New (),
@@ -357,23 +358,23 @@ func (self *worker) makeCurrent(parent *types.Block, header *types.Header) {
357
358
// when 08 is processed ancestors contain 07 (quick block)
358
359
for _ , ancestor := range self .chain .GetBlocksFromHash (parent .Hash (), 7 ) {
359
360
for _ , uncle := range ancestor .Uncles () {
360
- current .family .Add (uncle .Hash ())
361
+ work .family .Add (uncle .Hash ())
361
362
}
362
- current .family .Add (ancestor .Hash ())
363
- current .ancestors .Add (ancestor .Hash ())
363
+ work .family .Add (ancestor .Hash ())
364
+ work .ancestors .Add (ancestor .Hash ())
364
365
}
365
366
accounts , _ := self .eth .AccountManager ().Accounts ()
366
367
367
368
// Keep track of transactions which return errors so they can be removed
368
- current .remove = set .New ()
369
- current .tcount = 0
370
- current .ignoredTransactors = set .New ()
371
- current .lowGasTransactors = set .New ()
372
- current .ownedAccounts = accountAddressesSet (accounts )
369
+ work .remove = set .New ()
370
+ work .tcount = 0
371
+ work .ignoredTransactors = set .New ()
372
+ work .lowGasTransactors = set .New ()
373
+ work .ownedAccounts = accountAddressesSet (accounts )
373
374
if self .current != nil {
374
- current .localMinedBlocks = self .current .localMinedBlocks
375
+ work .localMinedBlocks = self .current .localMinedBlocks
375
376
}
376
- self .current = current
377
+ self .current = work
377
378
}
378
379
379
380
func (w * worker ) setGasPrice (p * big.Int ) {
@@ -387,13 +388,13 @@ func (w *worker) setGasPrice(p *big.Int) {
387
388
w .mux .Post (core.GasPriceChanged {w .gasPrice })
388
389
}
389
390
390
- func (self * worker ) isBlockLocallyMined (deepBlockNum uint64 ) bool {
391
+ func (self * worker ) isBlockLocallyMined (current * Work , deepBlockNum uint64 ) bool {
391
392
//Did this instance mine a block at {deepBlockNum} ?
392
393
var isLocal = false
393
- for idx , blockNum := range self . current .localMinedBlocks .ints {
394
+ for idx , blockNum := range current .localMinedBlocks .ints {
394
395
if deepBlockNum == blockNum {
395
396
isLocal = true
396
- self . current .localMinedBlocks .ints [idx ] = 0 //prevent showing duplicate logs
397
+ current .localMinedBlocks .ints [idx ] = 0 //prevent showing duplicate logs
397
398
break
398
399
}
399
400
}
@@ -407,12 +408,12 @@ func (self *worker) isBlockLocallyMined(deepBlockNum uint64) bool {
407
408
return block != nil && block .Coinbase () == self .coinbase
408
409
}
409
410
410
- func (self * worker ) logLocalMinedBlocks (previous * Work ) {
411
- if previous != nil && self . current .localMinedBlocks != nil {
412
- nextBlockNum := self . current .Block .NumberU64 ()
411
+ func (self * worker ) logLocalMinedBlocks (current , previous * Work ) {
412
+ if previous != nil && current .localMinedBlocks != nil {
413
+ nextBlockNum := current .Block .NumberU64 ()
413
414
for checkBlockNum := previous .Block .NumberU64 (); checkBlockNum < nextBlockNum ; checkBlockNum ++ {
414
415
inspectBlockNum := checkBlockNum - miningLogAtDepth
415
- if self .isBlockLocallyMined (inspectBlockNum ) {
416
+ if self .isBlockLocallyMined (current , inspectBlockNum ) {
416
417
glog .V (logger .Info ).Infof ("🔨 🔗 Mined %d blocks back: block #%v" , miningLogAtDepth , inspectBlockNum )
417
418
}
418
419
}
@@ -454,14 +455,14 @@ func (self *worker) commitNewWork() {
454
455
455
456
previous := self .current
456
457
self .makeCurrent (parent , header )
457
- current := self .current
458
+ work := self .current
458
459
459
460
// commit transactions for this run.
460
461
transactions := self .eth .TxPool ().GetTransactions ()
461
462
sort .Sort (types.TxByNonce {transactions })
462
- current .coinbase .SetGasLimit (header .GasLimit )
463
- current .commitTransactions (transactions , self .gasPrice , self .proc )
464
- self .eth .TxPool ().RemoveTransactions (current .lowGasTxs )
463
+ work .coinbase .SetGasLimit (header .GasLimit )
464
+ work .commitTransactions (transactions , self .gasPrice , self .proc )
465
+ self .eth .TxPool ().RemoveTransactions (work .lowGasTxs )
465
466
466
467
// compute uncles for the new block.
467
468
var (
@@ -472,7 +473,7 @@ func (self *worker) commitNewWork() {
472
473
if len (uncles ) == 2 {
473
474
break
474
475
}
475
- if err := self .commitUncle (uncle .Header ()); err != nil {
476
+ if err := self .commitUncle (work , uncle .Header ()); err != nil {
476
477
if glog .V (logger .Ridiculousness ) {
477
478
glog .V (logger .Detail ).Infof ("Bad uncle found and will be removed (%x)\n " , hash [:4 ])
478
479
glog .V (logger .Detail ).Infoln (uncle )
@@ -489,36 +490,36 @@ func (self *worker) commitNewWork() {
489
490
490
491
if atomic .LoadInt32 (& self .mining ) == 1 {
491
492
// commit state root after all state transitions.
492
- core .AccumulateRewards (self . current .state , header , uncles )
493
- current .state .SyncObjects ()
494
- header .Root = current .state .Root ()
493
+ core .AccumulateRewards (work .state , header , uncles )
494
+ work .state .SyncObjects ()
495
+ header .Root = work .state .Root ()
495
496
}
496
497
497
498
// create the new block whose nonce will be mined.
498
- current .Block = types .NewBlock (header , current .txs , uncles , current .receipts )
499
- self . current . Block .Td = new (big.Int ).Set (core .CalcTD (self . current . Block , self .chain .GetBlock (self . current .Block .ParentHash ())))
499
+ work .Block = types .NewBlock (header , work .txs , uncles , work .receipts )
500
+ work . Block .Td = new (big.Int ).Set (core .CalcTD (work . Block , self .chain .GetBlock (work .Block .ParentHash ())))
500
501
501
502
// We only care about logging if we're actually mining.
502
503
if atomic .LoadInt32 (& self .mining ) == 1 {
503
- glog .V (logger .Info ).Infof ("commit new work on block %v with %d txs & %d uncles. Took %v\n " , current .Block .Number (), current .tcount , len (uncles ), time .Since (tstart ))
504
- self .logLocalMinedBlocks (previous )
504
+ glog .V (logger .Info ).Infof ("commit new work on block %v with %d txs & %d uncles. Took %v\n " , work .Block .Number (), work .tcount , len (uncles ), time .Since (tstart ))
505
+ self .logLocalMinedBlocks (work , previous )
505
506
}
506
507
507
- self .push ()
508
+ self .push (work )
508
509
}
509
510
510
- func (self * worker ) commitUncle (uncle * types.Header ) error {
511
+ func (self * worker ) commitUncle (work * Work , uncle * types.Header ) error {
511
512
hash := uncle .Hash ()
512
- if self . current .uncles .Has (hash ) {
513
+ if work .uncles .Has (hash ) {
513
514
return core .UncleError ("Uncle not unique" )
514
515
}
515
- if ! self . current .ancestors .Has (uncle .ParentHash ) {
516
+ if ! work .ancestors .Has (uncle .ParentHash ) {
516
517
return core .UncleError (fmt .Sprintf ("Uncle's parent unknown (%x)" , uncle .ParentHash [0 :4 ]))
517
518
}
518
- if self . current .family .Has (hash ) {
519
+ if work .family .Has (hash ) {
519
520
return core .UncleError (fmt .Sprintf ("Uncle already in family (%x)" , hash ))
520
521
}
521
- self . current .uncles .Add (uncle .Hash ())
522
+ work .uncles .Add (uncle .Hash ())
522
523
return nil
523
524
}
524
525
0 commit comments