aboutsummaryrefslogtreecommitdiffstats
path: root/core/chain_makers.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-09-02 18:55:11 +0800
committerFelix Lange <fjl@twurst.com>2015-10-17 16:24:34 +0800
commitde8d5aaa92ff843e6960eb9b7bd7ec1c1ebc6608 (patch)
tree59930f3d627940e1b73030ee2c5685104a04ee34 /core/chain_makers.go
parent10ed107ba2001d1aabba3d319ba88c5ce6e8fdc0 (diff)
downloadgo-tangerine-de8d5aaa92ff843e6960eb9b7bd7ec1c1ebc6608.tar
go-tangerine-de8d5aaa92ff843e6960eb9b7bd7ec1c1ebc6608.tar.gz
go-tangerine-de8d5aaa92ff843e6960eb9b7bd7ec1c1ebc6608.tar.bz2
go-tangerine-de8d5aaa92ff843e6960eb9b7bd7ec1c1ebc6608.tar.lz
go-tangerine-de8d5aaa92ff843e6960eb9b7bd7ec1c1ebc6608.tar.xz
go-tangerine-de8d5aaa92ff843e6960eb9b7bd7ec1c1ebc6608.tar.zst
go-tangerine-de8d5aaa92ff843e6960eb9b7bd7ec1c1ebc6608.zip
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.
Diffstat (limited to 'core/chain_makers.go')
-rw-r--r--core/chain_makers.go11
1 files changed, 5 insertions, 6 deletions
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)
}