From d749d54ea5895dec182a4f2d4627461e6ec1d05c Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Thu, 5 Feb 2026 14:13:04 +0800 Subject: [PATCH] feate(core, trie): add UpdateContractCode to the Trie interface #27476 (#1167) Verkle trees store the code inside the trie. This PR changes the interface to pass the code, as well as the dirty flag to tell the trie package if the code is dirty and needs to be updated. This is a no-op for the MPT and the odr trie. Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com> --- core/state/database.go | 4 ++++ core/state/statedb.go | 1 + trie/secure_trie.go | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/core/state/database.go b/core/state/database.go index 45060348f8..8de5c2e3cd 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -93,6 +93,10 @@ type Trie interface { // in the trie with provided address. UpdateAccount(address common.Address, account *types.StateAccount) error + // UpdateContractCode abstracts code write to the trie. It is expected + // to be moved to the stateWriter interface when the latter is ready. + UpdateContractCode(address common.Address, codeHash common.Hash, code []byte) error + // DeleteStorage removes any existing value for key from the trie. If a node // was not found in the database, a trie.MissingNodeError is returned. DeleteStorage(addr common.Address, key []byte) error diff --git a/core/state/statedb.go b/core/state/statedb.go index 499da5a5d1..33f64de377 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -918,6 +918,7 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er if obj := s.stateObjects[addr]; !obj.deleted { // Write any contract code associated with the state object if obj.code != nil && obj.dirtyCode { + s.trie.UpdateContractCode(obj.Address(), common.BytesToHash(obj.CodeHash()), obj.code) rawdb.WriteCode(codeWriter, common.BytesToHash(obj.CodeHash()), obj.code) obj.dirtyCode = false } diff --git a/trie/secure_trie.go b/trie/secure_trie.go index 5d638f444f..140894e8d1 100644 --- a/trie/secure_trie.go +++ b/trie/secure_trie.go @@ -176,6 +176,10 @@ func (t *StateTrie) UpdateAccount(address common.Address, acc *types.StateAccoun return nil } +func (t *StateTrie) UpdateContractCode(_ common.Address, _ common.Hash, _ []byte) error { + return nil +} + // MustDelete removes any existing value for key from the trie. This function // will omit any encountered error but just print out an error message. func (t *StateTrie) MustDelete(key []byte) {