@@ -57,6 +57,18 @@ type BlockProcessor struct {
57
57
eventMux * event.TypeMux
58
58
}
59
59
60
+ // TODO: type GasPool big.Int
61
+ //
62
+ // GasPool is implemented by state.StateObject. This is a historical
63
+ // coincidence. Gas tracking should move out of StateObject.
64
+
65
+ // GasPool tracks the amount of gas available during
66
+ // execution of the transactions in a block.
67
+ type GasPool interface {
68
+ AddGas (gas , price * big.Int )
69
+ SubGas (gas , price * big.Int ) error
70
+ }
71
+
60
72
func NewBlockProcessor (db , extra common.Database , pow pow.PoW , chainManager * ChainManager , eventMux * event.TypeMux ) * BlockProcessor {
61
73
sm := & BlockProcessor {
62
74
db : db ,
@@ -66,28 +78,24 @@ func NewBlockProcessor(db, extra common.Database, pow pow.PoW, chainManager *Cha
66
78
bc : chainManager ,
67
79
eventMux : eventMux ,
68
80
}
69
-
70
81
return sm
71
82
}
72
83
73
84
func (sm * BlockProcessor ) TransitionState (statedb * state.StateDB , parent , block * types.Block , transientProcess bool ) (receipts types.Receipts , err error ) {
74
- coinbase := statedb .GetOrNewStateObject (block .Coinbase ())
75
- coinbase .SetGasLimit (block .GasLimit ())
85
+ gp := statedb .GetOrNewStateObject (block .Coinbase ())
86
+ gp .SetGasLimit (block .GasLimit ())
76
87
77
88
// Process the transactions on to parent state
78
- receipts , err = sm .ApplyTransactions (coinbase , statedb , block , block .Transactions (), transientProcess )
89
+ receipts , err = sm .ApplyTransactions (gp , statedb , block , block .Transactions (), transientProcess )
79
90
if err != nil {
80
91
return nil , err
81
92
}
82
93
83
94
return receipts , nil
84
95
}
85
96
86
- func (self * BlockProcessor ) ApplyTransaction (coinbase * state.StateObject , statedb * state.StateDB , header * types.Header , tx * types.Transaction , usedGas * big.Int , transientProcess bool ) (* types.Receipt , * big.Int , error ) {
87
- // If we are mining this block and validating we want to set the logs back to 0
88
-
89
- cb := statedb .GetStateObject (coinbase .Address ())
90
- _ , gas , err := ApplyMessage (NewEnv (statedb , self .bc , tx , header ), tx , cb )
97
+ func (self * BlockProcessor ) ApplyTransaction (gp GasPool , statedb * state.StateDB , header * types.Header , tx * types.Transaction , usedGas * big.Int , transientProcess bool ) (* types.Receipt , * big.Int , error ) {
98
+ _ , gas , err := ApplyMessage (NewEnv (statedb , self .bc , tx , header ), tx , gp )
91
99
if err != nil {
92
100
return nil , nil , err
93
101
}
@@ -122,7 +130,7 @@ func (self *BlockProcessor) ChainManager() *ChainManager {
122
130
return self .bc
123
131
}
124
132
125
- func (self * BlockProcessor ) ApplyTransactions (coinbase * state. StateObject , statedb * state.StateDB , block * types.Block , txs types.Transactions , transientProcess bool ) (types.Receipts , error ) {
133
+ func (self * BlockProcessor ) ApplyTransactions (gp GasPool , statedb * state.StateDB , block * types.Block , txs types.Transactions , transientProcess bool ) (types.Receipts , error ) {
126
134
var (
127
135
receipts types.Receipts
128
136
totalUsedGas = big .NewInt (0 )
@@ -134,7 +142,7 @@ func (self *BlockProcessor) ApplyTransactions(coinbase *state.StateObject, state
134
142
for i , tx := range txs {
135
143
statedb .StartRecord (tx .Hash (), block .Hash (), i )
136
144
137
- receipt , txGas , err := self .ApplyTransaction (coinbase , statedb , header , tx , totalUsedGas , transientProcess )
145
+ receipt , txGas , err := self .ApplyTransaction (gp , statedb , header , tx , totalUsedGas , transientProcess )
138
146
if err != nil {
139
147
return nil , err
140
148
}
0 commit comments