From faa0957d9a8541601e7b4c6da11274cc9e57c8b2 Mon Sep 17 00:00:00 2001 From: Youssef Azzaoui Date: Tue, 22 Apr 2025 16:47:01 -0300 Subject: [PATCH 1/3] Share reference with state object and stateDB's trie for copy operation. --- core/state/state_object.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/state/state_object.go b/core/state/state_object.go index 293875050313..f05f7b92db30 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -28,6 +28,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" + "github.com/ethereum/go-ethereum/trie" "github.com/ethereum/go-ethereum/trie/trienode" "github.com/holiman/uint256" ) @@ -494,8 +495,15 @@ func (s *stateObject) deepCopy(db *StateDB) *stateObject { selfDestructed: s.selfDestructed, newContract: s.newContract, } - if s.trie != nil { + + switch s.trie.(type) { + case *trie.VerkleTrie: + // In the Verkle case, the stateObject's trie shares the same reference as the StateDB's trie. + obj.trie = db.trie + case *trie.StateTrie: obj.trie = mustCopyTrie(s.trie) + case nil: + // do nothing } return obj } From 0dd1a0cb288b3c6ce948a37e44a0bbba905bee2c Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Thu, 16 Oct 2025 15:50:36 +0200 Subject: [PATCH 2/3] prepare for rebase --- core/state/state_object.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/state/state_object.go b/core/state/state_object.go index f05f7b92db30..cde5d11bba9d 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -498,7 +498,8 @@ func (s *stateObject) deepCopy(db *StateDB) *stateObject { switch s.trie.(type) { case *trie.VerkleTrie: - // In the Verkle case, the stateObject's trie shares the same reference as the StateDB's trie. + // Verkle uses only one tree, and the copy has already been + // made in mustCopyTrie. obj.trie = db.trie case *trie.StateTrie: obj.trie = mustCopyTrie(s.trie) From 3b2d6c87ebd66d1491e387bda57ca6b5052bc1e7 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Thu, 16 Oct 2025 15:59:14 +0200 Subject: [PATCH 3/3] add handling for the TransitionTree after rebase --- core/state/database.go | 2 ++ core/state/state_object.go | 4 ++++ trie/transition.go | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/state/database.go b/core/state/database.go index 3a0ac422ee47..58d0ccfe8292 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -302,6 +302,8 @@ func mustCopyTrie(t Trie) Trie { return t.Copy() case *trie.VerkleTrie: return t.Copy() + case *trie.TransitionTrie: + return t.Copy() default: panic(fmt.Errorf("unknown trie type %T", t)) } diff --git a/core/state/state_object.go b/core/state/state_object.go index cde5d11bba9d..fdeb4254c1bc 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -501,6 +501,10 @@ func (s *stateObject) deepCopy(db *StateDB) *stateObject { // Verkle uses only one tree, and the copy has already been // made in mustCopyTrie. obj.trie = db.trie + case *trie.TransitionTrie: + // Same thing for the transition tree, since the MPT is + // read-only. + obj.trie = db.trie case *trie.StateTrie: obj.trie = mustCopyTrie(s.trie) case nil: diff --git a/trie/transition.go b/trie/transition.go index da49c6cdc2c4..c6eecd39376d 100644 --- a/trie/transition.go +++ b/trie/transition.go @@ -211,7 +211,8 @@ func (t *TransitionTrie) UpdateStem(key []byte, values [][]byte) error { func (t *TransitionTrie) Copy() *TransitionTrie { return &TransitionTrie{ overlay: t.overlay.Copy(), - base: t.base.Copy(), + // base in immutable, so there is no need to copy it + base: t.base, storage: t.storage, } }