@@ -55,26 +55,20 @@ type Agent interface {
55
55
GetHashRate () int64
56
56
}
57
57
58
- type uint64RingBuffer struct {
59
- ints []uint64 //array of all integers in buffer
60
- next int //where is the next insertion? assert 0 <= next < len(ints)
61
- }
62
-
63
58
// Work is the workers current environment and holds
64
59
// all of the current state information
65
60
type Work struct {
66
61
config * params.ChainConfig
67
62
signer types.Signer
68
63
69
- state * state.StateDB // apply state changes here
70
- ancestors * set.Set // ancestor set (used for checking uncle parent validity)
71
- family * set.Set // family set (used for checking uncle invalidity)
72
- uncles * set.Set // uncle set
73
- tcount int // tx count in cycle
74
- ownedAccounts * set.Set
75
- lowGasTxs types.Transactions
76
- failedTxs types.Transactions
77
- localMinedBlocks * uint64RingBuffer // the most recent block numbers that were mined locally (used to check block inclusion)
64
+ state * state.StateDB // apply state changes here
65
+ ancestors * set.Set // ancestor set (used for checking uncle parent validity)
66
+ family * set.Set // family set (used for checking uncle invalidity)
67
+ uncles * set.Set // uncle set
68
+ tcount int // tx count in cycle
69
+ ownedAccounts * set.Set
70
+ lowGasTxs types.Transactions
71
+ failedTxs types.Transactions
78
72
79
73
Block * types.Block // the new block
80
74
@@ -123,6 +117,8 @@ type worker struct {
123
117
txQueueMu sync.Mutex
124
118
txQueue map [common.Hash ]* types.Transaction
125
119
120
+ unconfirmed * unconfirmedBlocks // set of locally mined blocks pending canonicalness confirmations
121
+
126
122
// atomic status counters
127
123
mining int32
128
124
atWork int32
@@ -144,6 +140,7 @@ func newWorker(config *params.ChainConfig, coinbase common.Address, eth Backend,
144
140
coinbase : coinbase ,
145
141
txQueue : make (map [common.Hash ]* types.Transaction ),
146
142
agents : make (map [Agent ]struct {}),
143
+ unconfirmed : newUnconfirmedBlocks (eth .BlockChain (), 5 ),
147
144
fullValidation : false ,
148
145
}
149
146
worker .events = worker .mux .Subscribe (core.ChainHeadEvent {}, core.ChainSideEvent {}, core.TxPreEvent {})
@@ -269,18 +266,6 @@ func (self *worker) update() {
269
266
}
270
267
}
271
268
272
- func newLocalMinedBlock (blockNumber uint64 , prevMinedBlocks * uint64RingBuffer ) (minedBlocks * uint64RingBuffer ) {
273
- if prevMinedBlocks == nil {
274
- minedBlocks = & uint64RingBuffer {next : 0 , ints : make ([]uint64 , miningLogAtDepth + 1 )}
275
- } else {
276
- minedBlocks = prevMinedBlocks
277
- }
278
-
279
- minedBlocks .ints [minedBlocks .next ] = blockNumber
280
- minedBlocks .next = (minedBlocks .next + 1 ) % len (minedBlocks .ints )
281
- return minedBlocks
282
- }
283
-
284
269
func (self * worker ) wait () {
285
270
for {
286
271
mustCommitNewWork := true
@@ -355,17 +340,8 @@ func (self *worker) wait() {
355
340
}
356
341
}(block , work .state .Logs (), work .receipts )
357
342
}
358
-
359
- // check staleness and display confirmation
360
- var stale , confirm string
361
- canonBlock := self .chain .GetBlockByNumber (block .NumberU64 ())
362
- if canonBlock != nil && canonBlock .Hash () != block .Hash () {
363
- stale = "stale "
364
- } else {
365
- confirm = "Wait 5 blocks for confirmation"
366
- work .localMinedBlocks = newLocalMinedBlock (block .Number ().Uint64 (), work .localMinedBlocks )
367
- }
368
- glog .V (logger .Info ).Infof ("🔨 Mined %sblock (#%v / %x). %s" , stale , block .Number (), block .Hash ().Bytes ()[:4 ], confirm )
343
+ // Insert the block into the set of pending ones to wait for confirmations
344
+ self .unconfirmed .Insert (block .NumberU64 (), block .Hash ())
369
345
370
346
if mustCommitNewWork {
371
347
self .commitNewWork ()
@@ -417,9 +393,6 @@ func (self *worker) makeCurrent(parent *types.Block, header *types.Header) error
417
393
// Keep track of transactions which return errors so they can be removed
418
394
work .tcount = 0
419
395
work .ownedAccounts = accountAddressesSet (accounts )
420
- if self .current != nil {
421
- work .localMinedBlocks = self .current .localMinedBlocks
422
- }
423
396
self .current = work
424
397
return nil
425
398
}
@@ -435,38 +408,6 @@ func (w *worker) setGasPrice(p *big.Int) {
435
408
w .mux .Post (core.GasPriceChanged {Price : w .gasPrice })
436
409
}
437
410
438
- func (self * worker ) isBlockLocallyMined (current * Work , deepBlockNum uint64 ) bool {
439
- //Did this instance mine a block at {deepBlockNum} ?
440
- var isLocal = false
441
- for idx , blockNum := range current .localMinedBlocks .ints {
442
- if deepBlockNum == blockNum {
443
- isLocal = true
444
- current .localMinedBlocks .ints [idx ] = 0 //prevent showing duplicate logs
445
- break
446
- }
447
- }
448
- //Short-circuit on false, because the previous and following tests must both be true
449
- if ! isLocal {
450
- return false
451
- }
452
-
453
- //Does the block at {deepBlockNum} send earnings to my coinbase?
454
- var block = self .chain .GetBlockByNumber (deepBlockNum )
455
- return block != nil && block .Coinbase () == self .coinbase
456
- }
457
-
458
- func (self * worker ) logLocalMinedBlocks (current , previous * Work ) {
459
- if previous != nil && current .localMinedBlocks != nil {
460
- nextBlockNum := current .Block .NumberU64 ()
461
- for checkBlockNum := previous .Block .NumberU64 (); checkBlockNum < nextBlockNum ; checkBlockNum ++ {
462
- inspectBlockNum := checkBlockNum - miningLogAtDepth
463
- if self .isBlockLocallyMined (current , inspectBlockNum ) {
464
- glog .V (logger .Info ).Infof ("🔨 🔗 Mined %d blocks back: block #%v" , miningLogAtDepth , inspectBlockNum )
465
- }
466
- }
467
- }
468
- }
469
-
470
411
func (self * worker ) commitNewWork () {
471
412
self .mu .Lock ()
472
413
defer self .mu .Unlock ()
@@ -513,7 +454,6 @@ func (self *worker) commitNewWork() {
513
454
}
514
455
}
515
456
}
516
- previous := self .current
517
457
// Could potentially happen if starting to mine in an odd state.
518
458
err := self .makeCurrent (parent , header )
519
459
if err != nil {
@@ -574,7 +514,7 @@ func (self *worker) commitNewWork() {
574
514
// We only care about logging if we're actually mining.
575
515
if atomic .LoadInt32 (& self .mining ) == 1 {
576
516
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 ))
577
- self .logLocalMinedBlocks (work , previous )
517
+ self .unconfirmed . Shift (work . Block . NumberU64 () - 1 )
578
518
}
579
519
self .push (work )
580
520
}
0 commit comments