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