@@ -444,7 +444,11 @@ worker
444
444
445
445
coinbase common.Address // 挖矿者的地址
446
446
extra [ ] byte //
447
-
447
+
448
+ snapshotMu sync.RWMutex // 快照 RWMutex(快照读写锁)
449
+ snapshotBlock * types.Block // 快照 Block
450
+ snapshotState * state.StateDB // 快照 StateDB
451
+
448
452
currentMu sync.Mutex
449
453
current * Work
450
454
@@ -708,12 +712,23 @@ makeCurrent,未当前的周期创建一个新的环境。
708
712
commitTransactions
709
713
710
714
func (env * Work) commitTransactions(mux * event.TypeMux, txs * types.TransactionsByPriceAndNonce, bc * core.BlockChain, coinbase common.Address) {
711
- gp := new(core.GasPool).AddGas(env.header.GasLimit)
715
+ // 由于是打包新的区块中交易,所以将总 gasPool 初始化为 env.header.GasLimit
716
+ if env.gasPool == nil {
717
+ env.gasPool = new(core.GasPool).AddGas(env.header.GasLimit)
718
+ }
712
719
713
720
var coalescedLogs [ ] * types.Log
714
721
715
722
for {
723
+ // If we don't have enough gas for any further transactions then we're done
724
+ // 如果当前区块中所有 Gas 消耗已经使用完,则退出打包交易
725
+ if env.gasPool.Gas() < params.TxGas {
726
+ log.Trace("Not enough gas for further transactions", "have", env.gasPool, "want", params.TxGas)
727
+ break
728
+ }
729
+
716
730
// Retrieve the next transaction and abort if all done
731
+ // 检索下一笔交易,如果交易集合为空则退出 commit
717
732
tx := txs.Peek()
718
733
if tx == nil {
719
734
break
@@ -966,4 +981,4 @@ Start
966
981
log.Info("Starting mining operation")
967
982
self.worker.start() // 启动worker 开始挖矿
968
983
self.worker.commitNewWork() //提交新的挖矿任务。
969
- }
984
+ }
0 commit comments