-
Notifications
You must be signed in to change notification settings - Fork 992
Persist reverted account and storage slot lookups in JournaledState
#1437
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
Merged
rakita
merged 2 commits into
bluealloy:main
from
fractal-zkp:feat/journaled_state_persist_lookups
Jun 8, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -322,7 +322,7 @@ impl JournaledState { | |
| for entry in journal_entries.into_iter().rev() { | ||
| match entry { | ||
| JournalEntry::AccountLoaded { address } => { | ||
| state.remove(&address); | ||
| state.get_mut(&address).unwrap().mark_cold(); | ||
| } | ||
| JournalEntry::AccountTouched { address } => { | ||
| if is_spurious_dragon_enabled && address == PRECOMPILE3 { | ||
|
|
@@ -378,7 +378,7 @@ impl JournaledState { | |
| if let Some(had_value) = had_value { | ||
| storage.get_mut(&key).unwrap().present_value = had_value; | ||
| } else { | ||
| storage.remove(&key); | ||
| storage.get_mut(&key).unwrap().mark_cold(); | ||
| } | ||
| } | ||
| JournalEntry::TransientStorageChange { | ||
|
|
@@ -555,8 +555,12 @@ impl JournaledState { | |
| address: Address, | ||
| db: &mut DB, | ||
| ) -> Result<(&mut Account, bool), EVMError<DB::Error>> { | ||
| Ok(match self.state.entry(address) { | ||
| Entry::Occupied(entry) => (entry.into_mut(), false), | ||
| let (value, is_cold) = match self.state.entry(address) { | ||
| Entry::Occupied(entry) => { | ||
| let account = entry.into_mut(); | ||
| let is_cold = account.mark_warm(); | ||
| (account, is_cold) | ||
| } | ||
| Entry::Vacant(vac) => { | ||
| let account = | ||
| if let Some(account) = db.basic(address).map_err(EVMError::Database)? { | ||
|
|
@@ -565,18 +569,22 @@ impl JournaledState { | |
| Account::new_not_existing() | ||
| }; | ||
|
|
||
| // journal loading of account. AccessList touch. | ||
| self.journal | ||
| .last_mut() | ||
| .unwrap() | ||
| .push(JournalEntry::AccountLoaded { address }); | ||
|
|
||
| // precompiles are warm loaded so we need to take that into account | ||
| let is_cold = !self.warm_preloaded_addresses.contains(&address); | ||
|
|
||
| (vac.insert(account), is_cold) | ||
| } | ||
| }) | ||
| }; | ||
|
|
||
| // journal loading of cold account. | ||
| if is_cold { | ||
| self.journal | ||
| .last_mut() | ||
| .unwrap() | ||
| .push(JournalEntry::AccountLoaded { address }); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome change! |
||
|
|
||
| Ok((value, is_cold)) | ||
| } | ||
|
|
||
| /// Load account from database to JournaledState. | ||
|
|
@@ -641,31 +649,39 @@ impl JournaledState { | |
| let account = self.state.get_mut(&address).unwrap(); | ||
| // only if account is created in this tx we can assume that storage is empty. | ||
| let is_newly_created = account.is_created(); | ||
| let load = match account.storage.entry(key) { | ||
| Entry::Occupied(occ) => (occ.get().present_value, false), | ||
| let (value, is_cold) = match account.storage.entry(key) { | ||
| Entry::Occupied(occ) => { | ||
| let slot = occ.into_mut(); | ||
| let is_cold = slot.mark_warm(); | ||
| (slot.present_value, is_cold) | ||
|
rakita marked this conversation as resolved.
|
||
| } | ||
| Entry::Vacant(vac) => { | ||
| // if storage was cleared, we don't need to ping db. | ||
| let value = if is_newly_created { | ||
| U256::ZERO | ||
| } else { | ||
| db.storage(address, key).map_err(EVMError::Database)? | ||
| }; | ||
| // add it to journal as cold loaded. | ||
| self.journal | ||
| .last_mut() | ||
| .unwrap() | ||
| .push(JournalEntry::StorageChange { | ||
| address, | ||
| key, | ||
| had_value: None, | ||
| }); | ||
|
|
||
| vac.insert(StorageSlot::new(value)); | ||
|
|
||
| (value, true) | ||
| } | ||
| }; | ||
| Ok(load) | ||
|
|
||
| if is_cold { | ||
| // add it to journal as cold loaded. | ||
| self.journal | ||
| .last_mut() | ||
| .unwrap() | ||
| .push(JournalEntry::StorageChange { | ||
| address, | ||
| key, | ||
| had_value: None, | ||
| }); | ||
| } | ||
|
|
||
| Ok((value, is_cold)) | ||
| } | ||
|
|
||
| /// Stores storage slot. | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.