Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statedb: avoid getting code from cache #480

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ func (s *StateDB) updateStateObject(obj *stateObject) {
}
// Encode the account and update the account trie
addr := obj.Address()
if err := s.trie.UpdateAccount(addr, &obj.data, len(obj.code)); err != nil {
if err := s.trie.UpdateAccount(addr, &obj.data, len(s.GetCode(addr))); err != nil {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem appeared in the dumped state for the 2935 contract.
In the post-state, the codeLen encoded in basicData was 0 which made no sense.

After looking, the problem is that obj.code was nil since technically the EVM never called GetCode(...). GetCode(...) actually fills obj.code as a cache.

Since we were accessing the cache directly, we were re-encoding basicdata with length 0 which was wrong.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normal contract would have already call GetCode(...) in the EVM, so this extra call will simply return it from the cache.

But this will cover for system contracts (like 2935) which update from storage directly as an optimization.

s.setError(fmt.Errorf("updateStateObject (%x) error: %v", addr[:], err))
}
if obj.dirtyCode {
Expand Down
Loading