From 274c727a700545a53da254216b60d30c973bfab9 Mon Sep 17 00:00:00 2001 From: tczpl Date: Fri, 20 Dec 2019 11:37:13 +0800 Subject: [PATCH] remove duplicate preparation of blockHash in statedb --- core/state/statedb.go | 7 +++++++ core/state_prefetcher.go | 4 +++- core/state_processor.go | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index 03e118d117..d4f89f3626 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -715,6 +715,13 @@ func (s *StateDB) Prepare(thash, bhash common.Hash, ti int) { s.bhash = bhash s.txIndex = ti } +func (s *StateDB) PrepareTransaction(thash, ti int) { + s.thash = thash + s.txIndex = ti +} +func (s *StateDB) PrepareBlock(bhash common.Hash) { + s.bhash = bhash +} func (s *StateDB) clearJournalAndRefund() { if len(s.journal.entries) > 0 { diff --git a/core/state_prefetcher.go b/core/state_prefetcher.go index cb85a05b57..ea19731376 100644 --- a/core/state_prefetcher.go +++ b/core/state_prefetcher.go @@ -53,6 +53,8 @@ func (p *statePrefetcher) Prefetch(block *types.Block, statedb *state.StateDB, c header = block.Header() gaspool = new(GasPool).AddGas(block.GasLimit()) ) + // Prepare the block hash which is used when the EVM emits new state logs + statedb.PrepareBlock(block.Hash()) // Iterate over and process the individual transactions for i, tx := range block.Transactions() { // If block precaching was interrupted, abort @@ -60,7 +62,7 @@ func (p *statePrefetcher) Prefetch(block *types.Block, statedb *state.StateDB, c return } // Block precaching permitted to continue, execute the transaction - statedb.Prepare(tx.Hash(), block.Hash(), i) + statedb.PrepareTransaction(tx.Hash(), i) if err := precacheTransaction(p.config, p.bc, nil, gaspool, statedb, header, tx, cfg); err != nil { return // Ugh, something went horribly wrong, bail out } diff --git a/core/state_processor.go b/core/state_processor.go index cfe17d587b..1a9deb30c6 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -65,9 +65,11 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg if p.config.DAOForkSupport && p.config.DAOForkBlock != nil && p.config.DAOForkBlock.Cmp(block.Number()) == 0 { misc.ApplyDAOHardFork(statedb) } + // Prepare the block hash which is used when the EVM emits new state logs + statedb.PrepareBlock(block.Hash()) // Iterate over and process the individual transactions for i, tx := range block.Transactions() { - statedb.Prepare(tx.Hash(), block.Hash(), i) + statedb.PrepareTransaction(tx.Hash(), i) receipt, err := ApplyTransaction(p.config, p.bc, nil, gp, statedb, header, tx, usedGas, cfg) if err != nil { return nil, nil, 0, err