diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 6eff8d9055f1..ab0f69c426aa 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -671,9 +671,8 @@ func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header r.Div(blockReward, big32) reward.Add(reward, r) } - coinbase := utils.GetTreeKeyBalance(header.Coinbase.Bytes()) - - if state.Witness() != nil { + if config.IsCancun(header.Number) { + coinbase := utils.GetTreeKeyBalance(header.Coinbase.Bytes()) state.Witness().TouchAddress(coinbase, state.GetBalance(header.Coinbase).Bytes()) } state.AddBalance(header.Coinbase, reward) diff --git a/core/evm.go b/core/evm.go index 141d730cacba..6c67fc43762c 100644 --- a/core/evm.go +++ b/core/evm.go @@ -69,7 +69,6 @@ func NewEVMTxContext(msg Message) vm.TxContext { return vm.TxContext{ Origin: msg.From(), GasPrice: new(big.Int).Set(msg.GasPrice()), - Accesses: types.NewAccessWitness(), } } diff --git a/core/state/statedb.go b/core/state/statedb.go index 593150523384..49773021a76a 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -148,12 +148,14 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error) journal: newJournal(), accessList: newAccessList(), hasher: crypto.NewKeccakState(), - witness: types.NewAccessWitness(), } - if sdb.snaps == nil && tr.IsVerkle() { - sdb.snaps, err = snapshot.New(db.TrieDB().DiskDB(), db.TrieDB(), 1, root, false, true, false, true) - if err != nil { - return nil, err + if tr.IsVerkle() { + sdb.witness = types.NewAccessWitness() + if sdb.snaps == nil { + sdb.snaps, err = snapshot.New(db.TrieDB().DiskDB(), db.TrieDB(), 1, root, false, true, false, true) + if err != nil { + return nil, err + } } } if sdb.snaps != nil { @@ -182,7 +184,7 @@ func (s *StateDB) StartPrefetcher(namespace string) { s.prefetcher.close() s.prefetcher = nil } - if s.snap != nil { + if s.snap != nil && !s.trie.IsVerkle() { s.prefetcher = newTriePrefetcher(s.db, s.originalRoot, namespace) } } @@ -713,7 +715,9 @@ func (s *StateDB) Copy() *StateDB { preimages: make(map[common.Hash][]byte, len(s.preimages)), journal: newJournal(), hasher: crypto.NewKeccakState(), - witness: s.witness.Copy(), + } + if s.witness != nil { + state.witness = s.witness.Copy() } // Copy the dirty states, logs, and preimages for addr := range s.journal.dirties { diff --git a/core/state_processor.go b/core/state_processor.go index 174ec77ff34e..bdb21ac68664 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -95,6 +95,9 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM) (*types.Receipt, error) { // Create a new context to be used in the EVM environment. txContext := NewEVMTxContext(msg) + if config.IsCancun(blockNumber) { + txContext.Accesses = types.NewAccessWitness() + } evm.Reset(txContext, statedb) // Apply the transaction to the current state (included in the env). diff --git a/core/vm/evm.go b/core/vm/evm.go index 3cb0a0ee53e8..855d67b405ad 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -130,7 +130,7 @@ type EVM struct { // NewEVM returns a new EVM. The returned EVM is not thread safe and should // only ever be used *once*. func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig *params.ChainConfig, config Config) *EVM { - if txCtx.Accesses == nil { + if txCtx.Accesses == nil && chainConfig.IsCancun(blockCtx.BlockNumber) { txCtx.Accesses = types.NewAccessWitness() } evm := &EVM{ diff --git a/miner/worker_test.go b/miner/worker_test.go index d1bcdeafb771..2cbf66214a2b 100644 --- a/miner/worker_test.go +++ b/miner/worker_test.go @@ -267,10 +267,7 @@ func testGenerateBlockAndImport(t *testing.T, isClique bool) { if _, err := chain.InsertChain([]*types.Block{block}); err != nil { t.Fatalf("failed to insert new mined block %d: %v", block.NumberU64(), err) } - // TODO(gballet) the timeout had to be increased from 3s to 7s with verkle - // trees, presumably because calculating an address is orders of magnitude - // slower with perdersen_hash not using the multi-exponentiation. - case <-time.After(5 * time.Second): // Worker needs 1s to include new changes. + case <-time.After(3 * time.Second): // Worker needs 1s to include new changes. t.Fatalf("timeout") } }