From de8d5aaa92ff843e6960eb9b7bd7ec1c1ebc6608 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 2 Sep 2015 12:55:11 +0200 Subject: core, core/state: move gas tracking out of core/state The amount of gas available for tx execution was tracked in the StateObject representing the coinbase account. This commit makes the gas counter a separate type in package core, which avoids unintended consequences of intertwining the counter with state logic. --- core/chain_makers.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'core/chain_makers.go') diff --git a/core/chain_makers.go b/core/chain_makers.go index 85a4955db..e20a05c7d 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -54,7 +54,7 @@ type BlockGen struct { header *types.Header statedb *state.StateDB - coinbase *state.StateObject + gasPool *GasPool txs []*types.Transaction receipts []*types.Receipt uncles []*types.Header @@ -63,15 +63,14 @@ type BlockGen struct { // SetCoinbase sets the coinbase of the generated block. // It can be called at most once. func (b *BlockGen) SetCoinbase(addr common.Address) { - if b.coinbase != nil { + if b.gasPool != nil { if len(b.txs) > 0 { panic("coinbase must be set before adding transactions") } panic("coinbase can only be set once") } b.header.Coinbase = addr - b.coinbase = b.statedb.GetOrNewStateObject(addr) - b.coinbase.SetGasLimit(b.header.GasLimit) + b.gasPool = new(GasPool).AddGas(b.header.GasLimit) } // SetExtra sets the extra data field of the generated block. @@ -88,10 +87,10 @@ func (b *BlockGen) SetExtra(data []byte) { // added. Notably, contract code relying on the BLOCKHASH instruction // will panic during execution. func (b *BlockGen) AddTx(tx *types.Transaction) { - if b.coinbase == nil { + if b.gasPool == nil { b.SetCoinbase(common.Address{}) } - _, gas, err := ApplyMessage(NewEnv(b.statedb, nil, tx, b.header), tx, b.coinbase) + _, gas, err := ApplyMessage(NewEnv(b.statedb, nil, tx, b.header), tx, b.gasPool) if err != nil { panic(err) } -- cgit v1.2.3