Skip to content

Commit 6797902

Browse files
authored
core/state: move UpdateContractCode before the trie hash is computed (#27853)
Context: The UpdateContractCode method was introduced for the state storage commitment schemes that include the whole code for their commitment computation. It must therefore be called before the root hash is computed at the end of IntermediateRoot. This should have no impact on the MPT since, in this context, the method is a no-op.
1 parent 10d9f93 commit 6797902

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

core/state/statedb.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,9 @@ func (s *StateDB) updateStateObject(obj *stateObject) {
546546
if err := s.trie.UpdateAccount(addr, &obj.data); err != nil {
547547
s.setError(fmt.Errorf("updateStateObject (%x) error: %v", addr[:], err))
548548
}
549+
if obj.dirtyCode {
550+
s.trie.UpdateContractCode(obj.Address(), common.BytesToHash(obj.CodeHash()), obj.code)
551+
}
549552
// Cache the data until commit. Note, this update mechanism is not symmetric
550553
// to the deletion, because whereas it is enough to track account updates
551554
// at commit time, deletions need tracking at transaction boundary level to
@@ -1189,7 +1192,6 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
11891192
// Write any contract code associated with the state object
11901193
if obj.code != nil && obj.dirtyCode {
11911194
rawdb.WriteCode(codeWriter, common.BytesToHash(obj.CodeHash()), obj.code)
1192-
s.trie.UpdateContractCode(obj.Address(), common.BytesToHash(obj.CodeHash()), obj.code)
11931195
obj.dirtyCode = false
11941196
}
11951197
// Write any storage changes in the state object to its storage trie

0 commit comments

Comments
 (0)