remove duplicate preparation of blockHash in statedb

This commit is contained in:
tczpl 2019-12-20 11:37:13 +08:00
parent 6ae9dc15cc
commit 274c727a70
3 changed files with 13 additions and 2 deletions

View file

@ -715,6 +715,13 @@ func (s *StateDB) Prepare(thash, bhash common.Hash, ti int) {
s.bhash = bhash s.bhash = bhash
s.txIndex = ti 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() { func (s *StateDB) clearJournalAndRefund() {
if len(s.journal.entries) > 0 { if len(s.journal.entries) > 0 {

View file

@ -53,6 +53,8 @@ func (p *statePrefetcher) Prefetch(block *types.Block, statedb *state.StateDB, c
header = block.Header() header = block.Header()
gaspool = new(GasPool).AddGas(block.GasLimit()) 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 // Iterate over and process the individual transactions
for i, tx := range block.Transactions() { for i, tx := range block.Transactions() {
// If block precaching was interrupted, abort // If block precaching was interrupted, abort
@ -60,7 +62,7 @@ func (p *statePrefetcher) Prefetch(block *types.Block, statedb *state.StateDB, c
return return
} }
// Block precaching permitted to continue, execute the transaction // 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 { if err := precacheTransaction(p.config, p.bc, nil, gaspool, statedb, header, tx, cfg); err != nil {
return // Ugh, something went horribly wrong, bail out return // Ugh, something went horribly wrong, bail out
} }

View file

@ -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 { if p.config.DAOForkSupport && p.config.DAOForkBlock != nil && p.config.DAOForkBlock.Cmp(block.Number()) == 0 {
misc.ApplyDAOHardFork(statedb) 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 // Iterate over and process the individual transactions
for i, tx := range block.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) receipt, err := ApplyTransaction(p.config, p.bc, nil, gp, statedb, header, tx, usedGas, cfg)
if err != nil { if err != nil {
return nil, nil, 0, err return nil, nil, 0, err