From 78692003f749f64d14f51bae9aa29da7934086dd Mon Sep 17 00:00:00 2001 From: Gustav Simonsson Date: Tue, 1 Sep 2015 17:17:23 +0200 Subject: [PATCH] core: ensure coinbase account is created during block processing --- core/block_processor.go | 12 +++++++----- miner/worker.go | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/block_processor.go b/core/block_processor.go index 99d27fa717..43bd56dbae 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -73,7 +73,7 @@ func (sm *BlockProcessor) TransitionState(statedb *state.StateDB, parent, block coinbase.SetGasLimit(block.GasLimit()) // Process the transactions on to parent state - receipts, err = sm.ApplyTransactions(coinbase, statedb, block, block.Transactions(), transientProcess) + receipts, err = sm.ApplyTransactions(statedb, block, block.Transactions(), transientProcess) if err != nil { return nil, err } @@ -81,8 +81,10 @@ func (sm *BlockProcessor) TransitionState(statedb *state.StateDB, parent, block return receipts, nil } -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) { - cb := statedb.GetStateObject(coinbase.Address()) +func (self *BlockProcessor) ApplyTransaction(statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *big.Int, transientProcess bool) (*types.Receipt, *big.Int, error) { + cb := statedb.GetOrNewStateObject(header.Coinbase) + cb.SetGasLimit(header.GasLimit) + _, gas, err := ApplyMessage(NewEnv(statedb, self.bc, tx, header), tx, cb) if err != nil { return nil, nil, err @@ -118,7 +120,7 @@ func (self *BlockProcessor) ChainManager() *ChainManager { return self.bc } -func (self *BlockProcessor) ApplyTransactions(coinbase *state.StateObject, statedb *state.StateDB, block *types.Block, txs types.Transactions, transientProcess bool) (types.Receipts, error) { +func (self *BlockProcessor) ApplyTransactions(statedb *state.StateDB, block *types.Block, txs types.Transactions, transientProcess bool) (types.Receipts, error) { var ( receipts types.Receipts totalUsedGas = big.NewInt(0) @@ -130,7 +132,7 @@ func (self *BlockProcessor) ApplyTransactions(coinbase *state.StateObject, state for i, tx := range txs { statedb.StartRecord(tx.Hash(), block.Hash(), i) - receipt, txGas, err := self.ApplyTransaction(coinbase, statedb, header, tx, totalUsedGas, transientProcess) + receipt, txGas, err := self.ApplyTransaction(statedb, header, tx, totalUsedGas, transientProcess) if err != nil { return nil, err } diff --git a/miner/worker.go b/miner/worker.go index 86970ec071..001341bea3 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -619,7 +619,7 @@ func (env *Work) commitTransactions(transactions types.Transactions, gasPrice *b func (env *Work) commitTransaction(tx *types.Transaction, proc *core.BlockProcessor) error { snap := env.state.Copy() - receipt, _, err := proc.ApplyTransaction(env.coinbase, env.state, env.header, tx, env.header.GasUsed, true) + receipt, _, err := proc.ApplyTransaction(env.state, env.header, tx, env.header.GasUsed, true) if err != nil { env.state.Set(snap) return err