@@ -56,6 +56,18 @@ type BlockProcessor struct {
5656 eventMux * event.TypeMux
5757}
5858
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+
5971func NewBlockProcessor (db common.Database , pow pow.PoW , chainManager * ChainManager , eventMux * event.TypeMux ) * BlockProcessor {
6072 sm := & BlockProcessor {
6173 chainDb : db ,
@@ -64,26 +76,24 @@ func NewBlockProcessor(db common.Database, pow pow.PoW, chainManager *ChainManag
6476 bc : chainManager ,
6577 eventMux : eventMux ,
6678 }
67-
6879 return sm
6980}
7081
7182func (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 ())
7485
7586 // 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 )
7788 if err != nil {
7889 return nil , err
7990 }
8091
8192 return receipts , nil
8293}
8394
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 )
8797 if err != nil {
8898 return nil , nil , err
8999 }
@@ -118,7 +128,7 @@ func (self *BlockProcessor) ChainManager() *ChainManager {
118128 return self .bc
119129}
120130
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 ) {
122132 var (
123133 receipts types.Receipts
124134 totalUsedGas = big .NewInt (0 )
@@ -130,7 +140,7 @@ func (self *BlockProcessor) ApplyTransactions(coinbase *state.StateObject, state
130140 for i , tx := range txs {
131141 statedb .StartRecord (tx .Hash (), block .Hash (), i )
132142
133- receipt , txGas , err := self .ApplyTransaction (coinbase , statedb , header , tx , totalUsedGas , transientProcess )
143+ receipt , txGas , err := self .ApplyTransaction (gp , statedb , header , tx , totalUsedGas , transientProcess )
134144 if err != nil {
135145 return nil , err
136146 }
0 commit comments