state: Replace create-revert erase with a nonexistent flag#1600
Conversation
There was a problem hiding this comment.
Pull request overview
This PR changes the test State implementation to avoid erasing m_modified entries when reverting a new-account create, preserving pointer stability by marking such entries with a revertible Account::nonexistent flag (ignored by find()/build_diff() and resurrected in-place by insert()).
Changes:
- Add a revertible
Account::nonexistentflag and journal it viaJournalAccountFlags. - Rework create journaling: new-account creates journal a flags snapshot restoring
nonexistent=true; pre-existing-account creates journalJournalCreateand roll back by resetting nonce/code. - Teach
find()/insert()/build_diff()to treatnonexistentnodes as absent.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| test/state/state.hpp | Extends JournalAccountFlags with nonexistent and simplifies JournalCreate. |
| test/state/state.cpp | Implements nonexistent handling in build_diff(), insert(), find(), create journaling, and rollback. |
| test/state/account.hpp | Adds and documents the new Account::nonexistent flag. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (!inserted) | ||
| { | ||
| assert(it->second.nonexistent); | ||
| it->second = std::move(account); | ||
| } |
| // TODO: Avoid double lookup (find+insert) and not cached initial state lookup for non-existent | ||
| // accounts. If we want to cache non-existent account we need a proper flag for it. |
| auto& a = get(e.addr); | ||
| a.access_status = e.access_status; | ||
| a.nonexistent = e.nonexistent; | ||
| a.destructed = e.destructed; | ||
| a.erase_if_empty = e.erase_if_empty; |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1600 +/- ##
=======================================
Coverage 97.39% 97.40%
=======================================
Files 164 164
Lines 14653 14658 +5
Branches 3388 3391 +3
=======================================
+ Hits 14272 14277 +5
Misses 280 280
Partials 101 101
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
362d5ca to
4dcb30a
Compare
Introduce nonexistent flag to Account. In case of create revert just set the flag instead of doing full erase from the hash map. Now we also need to recognize the flag on the query side.
4dcb30a to
5f0cc59
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
test/state/state.cpp:410
- When rolling back a newly-created account to the "nonexistent" sentinel state, the node retains potentially large buffers (code/storage/transient_storage). This can significantly increase peak memory for transactions with many failed creates, and keeps stale data around even though find() will treat the account as absent. Consider clearing these buffers (and resetting non-revertible flags) when restoring nonexistent==true to keep the sentinel lightweight while still preserving m_modified node stability.
auto& a = get(e.addr);
a.access_status = e.access_status;
a.nonexistent = e.nonexistent;
a.destructed = e.destructed;
a.erase_if_empty = e.erase_if_empty;
// TODO: On restoring nonexistent (un-created create) the node keeps its
// code/storage/transient buffers until tx end; could clear them here.
Introduce nonexistent flag to Account. In case of create revert
just set the flag instead of doing full erase from the hash map.
Now we also need to recognize the flag on the query side.