-
Notifications
You must be signed in to change notification settings - Fork 480
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
impl original_storage in SubstrateStackState #871
Changes from all commits
8b83c75
31ccd8e
2db8ec9
54a922f
11fa101
018eb95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -31,7 +31,13 @@ use fp_evm::{CallInfo, CreateInfo, ExecutionInfo, Log, Vicinity}; | |||||
use frame_support::traits::{Currency, ExistenceRequirement, Get}; | ||||||
use sp_core::{H160, H256, U256}; | ||||||
use sp_runtime::traits::UniqueSaturatedInto; | ||||||
use sp_std::{boxed::Box, collections::btree_set::BTreeSet, marker::PhantomData, mem, vec::Vec}; | ||||||
use sp_std::{ | ||||||
boxed::Box, | ||||||
collections::{btree_map::BTreeMap, btree_set::BTreeSet}, | ||||||
marker::PhantomData, | ||||||
mem, | ||||||
vec::Vec, | ||||||
}; | ||||||
|
||||||
#[derive(Default)] | ||||||
pub struct Runner<T: Config> { | ||||||
|
@@ -494,6 +500,7 @@ impl<'config> SubstrateStackSubstate<'config> { | |||||
pub struct SubstrateStackState<'vicinity, 'config, T> { | ||||||
vicinity: &'vicinity Vicinity, | ||||||
substate: SubstrateStackSubstate<'config>, | ||||||
original_storage: BTreeMap<(H160, H256), H256>, | ||||||
_marker: PhantomData<T>, | ||||||
} | ||||||
|
||||||
|
@@ -509,6 +516,7 @@ impl<'vicinity, 'config, T: Config> SubstrateStackState<'vicinity, 'config, T> { | |||||
parent: None, | ||||||
}, | ||||||
_marker: PhantomData, | ||||||
original_storage: BTreeMap::new(), | ||||||
} | ||||||
} | ||||||
} | ||||||
|
@@ -576,8 +584,15 @@ impl<'vicinity, 'config, T: Config> BackendT for SubstrateStackState<'vicinity, | |||||
<AccountStorages<T>>::get(address, index) | ||||||
} | ||||||
|
||||||
fn original_storage(&self, _address: H160, _index: H256) -> Option<H256> { | ||||||
None | ||||||
fn original_storage(&self, address: H160, index: H256) -> Option<H256> { | ||||||
// Not being cached means that it was never changed, which means we | ||||||
// can fetch it from storage. | ||||||
Some( | ||||||
self.original_storage | ||||||
.get(&(address, index)) | ||||||
.cloned() | ||||||
.unwrap_or_else(|| self.storage(address, index)), | ||||||
) | ||||||
} | ||||||
|
||||||
fn block_base_fee_per_gas(&self) -> sp_core::U256 { | ||||||
|
@@ -629,6 +644,18 @@ where | |||||
} | ||||||
|
||||||
fn set_storage(&mut self, address: H160, index: H256, value: H256) { | ||||||
// We cache the current value if this is the first time we modify it | ||||||
// in the transaction. | ||||||
use sp_std::collections::btree_map::Entry::Vacant; | ||||||
if let Vacant(e) = self.original_storage.entry((address, index)) { | ||||||
let original = <AccountStorages<T>>::get(address, index); | ||||||
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. Use
Suggested change
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. Cannot use |
||||||
// No need to cache if same value. | ||||||
if original != value { | ||||||
e.insert(original); | ||||||
} | ||||||
} | ||||||
|
||||||
// Then we insert or remove the entry based on the value. | ||||||
if value == H256::default() { | ||||||
log::debug!( | ||||||
target: "evm", | ||||||
|
@@ -693,7 +720,7 @@ where | |||||
// | ||||||
// This function exists in EVM because a design issue | ||||||
// (arguably a bug) in SELFDESTRUCT that can cause total | ||||||
// issurance to be reduced. We do not need to replicate this. | ||||||
// issuance to be reduced. We do not need to replicate this. | ||||||
} | ||||||
|
||||||
fn touch(&mut self, _address: H160) { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a check beforehand that:
self.original_storage
does not contain the key,Skip inserting into the original_storage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.