fix(executor): preserve existing account state (#1691)

This commit is contained in:
Roman Krasiuk
2023-03-09 19:14:36 +02:00
committed by GitHub
parent e913a536f0
commit 8ba0a190b8
3 changed files with 54 additions and 6 deletions

8
Cargo.lock generated
View File

@@ -5159,7 +5159,7 @@ dependencies = [
[[package]]
name = "revm"
version = "3.0.0"
source = "git+https://github.com/bluealloy/revm?rev=d8dc6526#d8dc6526b33d94af8ce46dd9c8d2559c04593504"
source = "git+https://github.com/bluealloy/revm?rev=afc3066#afc30663270f77df9b4399ad9d4cfb0ad2b814ec"
dependencies = [
"auto_impl",
"revm-interpreter",
@@ -5169,7 +5169,7 @@ dependencies = [
[[package]]
name = "revm-interpreter"
version = "1.0.0"
source = "git+https://github.com/bluealloy/revm?rev=d8dc6526#d8dc6526b33d94af8ce46dd9c8d2559c04593504"
source = "git+https://github.com/bluealloy/revm?rev=afc3066#afc30663270f77df9b4399ad9d4cfb0ad2b814ec"
dependencies = [
"derive_more",
"enumn",
@@ -5180,7 +5180,7 @@ dependencies = [
[[package]]
name = "revm-precompile"
version = "2.0.0"
source = "git+https://github.com/bluealloy/revm?rev=d8dc6526#d8dc6526b33d94af8ce46dd9c8d2559c04593504"
source = "git+https://github.com/bluealloy/revm?rev=afc3066#afc30663270f77df9b4399ad9d4cfb0ad2b814ec"
dependencies = [
"k256",
"num",
@@ -5196,7 +5196,7 @@ dependencies = [
[[package]]
name = "revm-primitives"
version = "1.0.0"
source = "git+https://github.com/bluealloy/revm?rev=d8dc6526#d8dc6526b33d94af8ce46dd9c8d2559c04593504"
source = "git+https://github.com/bluealloy/revm?rev=afc3066#afc30663270f77df9b4399ad9d4cfb0ad2b814ec"
dependencies = [
"arbitrary",
"auto_impl",

View File

@@ -47,7 +47,7 @@ inherits = "release"
debug = true
[patch.crates-io]
revm = { git = "https://github.com/bluealloy/revm", rev = "d8dc6526" }
revm-primitives = { git = "https://github.com/bluealloy/revm", rev = "d8dc6526" }
revm = { git = "https://github.com/bluealloy/revm", rev = "afc3066" }
revm-primitives = { git = "https://github.com/bluealloy/revm", rev = "afc3066" }
# patched for quantity U256 responses <https://github.com/recmo/uint/issues/224>
ruint = { git = "https://github.com/paradigmxyz/uint" }

View File

@@ -195,6 +195,10 @@ where
new_account.account_state = if account.storage_cleared {
new_account.storage.clear();
AccountState::StorageCleared
} else if new_account.account_state.is_storage_cleared() {
// the account already exists and its storage was cleared, preserve its previous
// state
AccountState::StorageCleared
} else {
AccountState::Touched
};
@@ -953,4 +957,48 @@ mod tests {
})
);
}
#[test]
fn test_account_state_preserved() {
let account = Address::from_str("c94f5374fce5edbc8e2a8697c15331677e6ebf0b").unwrap();
let mut db = StateProviderTest::default();
db.insert_account(account, Account::default(), None, HashMap::default());
let chain_spec = Arc::new(ChainSpecBuilder::mainnet().istanbul_activated().build());
let db = SubState::new(State::new(db));
let default_acc = RevmAccount {
info: AccountInfo::default(),
storage: hash_map::HashMap::default(),
is_destroyed: false,
is_touched: false,
storage_cleared: false,
is_not_existing: false,
};
let mut executor = Executor::new(chain_spec, db);
// touch account
executor.commit_changes(hash_map::HashMap::from([(
account,
RevmAccount { ..default_acc.clone() },
)]));
// destroy account
executor.commit_changes(hash_map::HashMap::from([(
account,
RevmAccount { is_destroyed: true, is_touched: true, ..default_acc.clone() },
)]));
// re-create account
executor.commit_changes(hash_map::HashMap::from([(
account,
RevmAccount { is_touched: true, storage_cleared: true, ..default_acc.clone() },
)]));
// touch account
executor
.commit_changes(hash_map::HashMap::from([(account, RevmAccount { ..default_acc })]));
let db = executor.db();
let account = db.load_account(account).unwrap();
assert_eq!(account.account_state, AccountState::StorageCleared);
}
}