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

enha: force block changes to redis #1576

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 2 additions & 7 deletions src/eth/primitives/execution_account_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,8 @@ impl ExecutionAccountChanges {
}
}

/// Checks if the account was created by this transaction.
pub fn is_creation(&self) -> bool {
self.new_account
}

/// Checks if nonce, balance or bytecode were modified.
pub fn is_changed(&self) -> bool {
/// Checks if account nonce, balance or bytecode were modified.
pub fn is_account_modified(&self) -> bool {
self.nonce.is_modified() || self.balance.is_modified() || self.bytecode.is_modified()
}
}
44 changes: 26 additions & 18 deletions src/eth/storage/redis/redis_permanent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,32 +98,40 @@ impl PermanentStorage for RedisPermanentStorage {
// changes
for changes in block.compact_account_changes() {
// account
let mut account = Account {
address: changes.address,
..Account::default()
};
if let Some(nonce) = changes.nonce.take() {
account.nonce = nonce;
}
if let Some(balance) = changes.balance.take() {
account.balance = balance;
}
if let Some(bytecode) = changes.bytecode.take() {
account.bytecode = bytecode;
if changes.is_account_modified() {
let mut account = Account {
address: changes.address,
..Account::default()
};
if let Some(nonce) = changes.nonce.take() {
account.nonce = nonce;
}
if let Some(balance) = changes.balance.take() {
account.balance = balance;
}
if let Some(bytecode) = changes.bytecode.take() {
account.bytecode = bytecode;
}

// add block number to force slot modification
let mut account_value = to_json_value(&account);
account_value.as_object_mut().unwrap().insert("block".to_owned(), to_json_value(block.number()));
let account_value = to_json_string(&account_value);

mset_values.push((key_account(&account.address), account_value.clone()));
zadd_values.push((key_account_history(&account.address), account_value, block.number().as_u64()));
}
let account_value = to_json_string(&account);
mset_values.push((key_account(&account.address), account_value.clone()));
zadd_values.push((key_account_history(&account.address), account_value, block.number().as_u64()));

// slot
// slots
for slot in changes.slots.into_values() {
if let Some(slot) = slot.take() {
// add block number to force slot modification
let mut slot_value = to_json_value(slot);
slot_value.as_object_mut().unwrap().insert("block".to_owned(), to_json_value(block.number()));
let slot_value = to_json_string(&slot_value);

mset_values.push((key_slot(&account.address, &slot.index), slot_value.clone()));
zadd_values.push((key_slot_history(&account.address, &slot.index), slot_value, block.number().as_u64()));
mset_values.push((key_slot(&changes.address, &slot.index), slot_value.clone()));
zadd_values.push((key_slot_history(&changes.address, &slot.index), slot_value, block.number().as_u64()));
}
}
}
Expand Down