diff --git a/core/blockchain.go b/core/blockchain.go index 0167faf41a..ce1b79a6da 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -922,6 +922,7 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) { reportBlock(block, err) return i, err } + self.stateCache.SetBlockContext(block.Hash(), block.NumberU64(), self) // Process block using the parent state as reference point. receipts, logs, usedGas, err := self.processor.Process(block, self.stateCache, self.config.VmConfig) if err != nil { diff --git a/core/chain_makers.go b/core/chain_makers.go index b361a69a31..a2c31c8dda 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -105,7 +105,7 @@ func (b *BlockGen) AddTx(tx *types.Transaction) { if b.gasPool == nil { b.SetCoinbase(common.Address{}) } - b.statedb.SetTxContext(common.Hash{}, b.header.Number.Uint64(), tx.Hash(), len(b.txs), nil) + b.statedb.SetTxContext(tx.Hash(), len(b.txs)) receipt, _, _, err := ApplyTransaction(MakeChainConfig(), nil, b.gasPool, b.statedb, b.header, tx, b.header.GasUsed, vm.Config{}) if err != nil { panic(err) diff --git a/core/state/statedb.go b/core/state/statedb.go index dc5323f2b1..a135dbabd4 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -107,7 +107,7 @@ func New(root common.Hash, db ethdb.Database) (*StateDB, error) { refund: new(big.Int), logs: make(map[common.Hash]vm.Logs), } - ret.SetTxContext(common.Hash{}, 0, common.Hash{}, 0, nil) + ret.SetBlockContext(common.Hash{}, 0, nil) return ret, nil } @@ -130,7 +130,7 @@ func (self *StateDB) New(root common.Hash) (*StateDB, error) { refund: new(big.Int), logs: make(map[common.Hash]vm.Logs), } - ret.SetTxContext(common.Hash{}, 0, common.Hash{}, 0, nil) + ret.SetBlockContext(common.Hash{}, 0, nil) return ret, nil } @@ -153,8 +153,8 @@ func (self *StateDB) Reset(root common.Hash) error { self.logs = make(map[common.Hash]vm.Logs) self.logSize = 0 self.clearJournalAndRefund() - self.SetTxContext(common.Hash{}, 0, common.Hash{}, 0, nil) - + self.SetBlockContext(common.Hash{}, 0, nil) + self.SetTxContext(common.Hash{}, 0) return nil } @@ -183,11 +183,8 @@ func (self *StateDB) pushTrie(t *trie.Trie) { } } -func (self *StateDB) SetTxContext(blockHash common.Hash, blockNum uint64, txHash common.Hash, txIndex int, validator trie.CacheValidator) { +func (self *StateDB) SetBlockContext(blockHash common.Hash, blockNum uint64, validator trie.CacheValidator) { self.bhash = blockHash - self.thash = txHash - self.txIndex = txIndex - if validator == nil { validator = &trie.NullCacheValidator{} } @@ -195,6 +192,11 @@ func (self *StateDB) SetTxContext(blockHash common.Hash, blockNum uint64, txHash self.storage = trie.NewSecure(storage, self.db) } +func (self *StateDB) SetTxContext(txHash common.Hash, txIndex int) { + self.thash = txHash + self.txIndex = txIndex +} + func (self *StateDB) AddLog(log *vm.Log) { self.journal = append(self.journal, addLogChange{txhash: self.thash}) diff --git a/core/state_processor.go b/core/state_processor.go index 8722e3c342..63cdf19d0a 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -71,7 +71,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg } // Iterate over and process the individual transactions for i, tx := range block.Transactions() { - statedb.SetTxContext(block.Hash(), block.NumberU64(), tx.Hash(), i, p.bc) + statedb.SetTxContext(tx.Hash(), i) receipt, logs, _, err := ApplyTransaction(p.config, p.bc, gp, statedb, header, tx, totalUsedGas, cfg) if err != nil { return nil, nil, totalUsedGas, err diff --git a/miner/worker.go b/miner/worker.go index 7826605238..b9a3eaac1d 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -583,7 +583,7 @@ func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsB continue } // Start executing the transaction - env.state.SetTxContext(common.Hash{}, env.header.Number.Uint64(), tx.Hash(), env.tcount, bc) + env.state.SetTxContext(tx.Hash(), env.tcount) err, logs := env.commitTransaction(tx, bc, gp) switch {