Ensure coinbase state object exists for each tx during block proc

This commit is contained in:
Gustav Simonsson 2015-09-01 18:25:03 +02:00
parent 9dc23ce284
commit d056824683
3 changed files with 13 additions and 5 deletions

View file

@ -89,7 +89,7 @@ func (self *BlockProcessor) ApplyTransaction(coinbase *state.StateObject, stated
} }
// Update the state with pending changes // Update the state with pending changes
statedb.SyncIntermediate() statedb.SyncIntermediate(header.Coinbase, header.GasLimit)
usedGas.Add(usedGas, gas) usedGas.Add(usedGas, gas)
receipt := types.NewReceipt(statedb.Root().Bytes(), usedGas) receipt := types.NewReceipt(statedb.Root().Bytes(), usedGas)

View file

@ -93,7 +93,7 @@ func (b *BlockGen) AddTx(tx *types.Transaction) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
b.statedb.SyncIntermediate() b.statedb.SyncIntermediate(common.Address{}, b.header.GasLimit)
b.header.GasUsed.Add(b.header.GasUsed, gas) b.header.GasUsed.Add(b.header.GasUsed, gas)
receipt := types.NewReceipt(b.statedb.Root().Bytes(), b.header.GasUsed) receipt := types.NewReceipt(b.statedb.Root().Bytes(), b.header.GasUsed)
logs := b.statedb.GetLogs(tx.Hash()) 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) gen(i, b)
} }
AccumulateRewards(statedb, h, b.uncles) AccumulateRewards(statedb, h, b.uncles)
statedb.SyncIntermediate() statedb.SyncIntermediate(h.Coinbase, h.GasLimit)
h.Root = statedb.Root() h.Root = statedb.Root()
return types.NewBlock(h, b.txs, b.uncles, b.receipts) return types.NewBlock(h, b.txs, b.uncles, b.receipts)
} }

View file

@ -349,13 +349,21 @@ func (self *StateDB) Refunds() *big.Int {
} }
// SyncIntermediate updates the intermediate state and all mid steps // 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) self.refund = new(big.Int)
for _, stateObject := range self.stateObjects { for _, stateObject := range self.stateObjects {
if stateObject.dirty { if stateObject.dirty {
if stateObject.remove { if stateObject.remove {
if stateObject.address == headerCoinbase {
gasPoolCopy := new(big.Int).Set(stateObject.gasPool)
self.DeleteStateObject(stateObject) self.DeleteStateObject(stateObject)
coinbase := self.CreateAccount(headerCoinbase)
coinbase.SetGasLimit(headerGasLimit)
coinbase.gasPool = gasPoolCopy
} else {
self.DeleteStateObject(stateObject)
}
} else { } else {
stateObject.Update() stateObject.Update()