diff --git a/core/block_processor.go b/core/block_processor.go index 99d27fa717..d16bef8f6b 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -89,7 +89,7 @@ func (self *BlockProcessor) ApplyTransaction(coinbase *state.StateObject, stated } // Update the state with pending changes - statedb.SyncIntermediate() + statedb.SyncIntermediate(header.Coinbase, header.GasLimit) usedGas.Add(usedGas, gas) receipt := types.NewReceipt(statedb.Root().Bytes(), usedGas) diff --git a/core/chain_makers.go b/core/chain_makers.go index b009e0c28c..b826113668 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -93,7 +93,7 @@ func (b *BlockGen) AddTx(tx *types.Transaction) { if err != nil { panic(err) } - b.statedb.SyncIntermediate() + b.statedb.SyncIntermediate(common.Address{}, b.header.GasLimit) b.header.GasUsed.Add(b.header.GasUsed, gas) receipt := types.NewReceipt(b.statedb.Root().Bytes(), b.header.GasUsed) logs := b.statedb.GetLogs(tx.Hash()) @@ -151,7 +151,7 @@ func GenerateChain(parent *types.Block, db common.Database, n int, gen func(int, gen(i, b) } AccumulateRewards(statedb, h, b.uncles) - statedb.SyncIntermediate() + statedb.SyncIntermediate(h.Coinbase, h.GasLimit) h.Root = statedb.Root() return types.NewBlock(h, b.txs, b.uncles, b.receipts) } diff --git a/core/state/statedb.go b/core/state/statedb.go index 577f7162eb..ca73618412 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -349,13 +349,21 @@ func (self *StateDB) Refunds() *big.Int { } // SyncIntermediate updates the intermediate state and all mid steps -func (self *StateDB) SyncIntermediate() { +func (self *StateDB) SyncIntermediate(headerCoinbase common.Address, headerGasLimit *big.Int) { self.refund = new(big.Int) for _, stateObject := range self.stateObjects { if stateObject.dirty { if stateObject.remove { - self.DeleteStateObject(stateObject) + if stateObject.address == headerCoinbase { + gasPoolCopy := new(big.Int).Set(stateObject.gasPool) + self.DeleteStateObject(stateObject) + coinbase := self.CreateAccount(headerCoinbase) + coinbase.SetGasLimit(headerGasLimit) + coinbase.gasPool = gasPoolCopy + } else { + self.DeleteStateObject(stateObject) + } } else { stateObject.Update()