Skip to content

Commit

Permalink
enha: force block changes to redis (#1576)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhani-cw authored Jul 30, 2024
1 parent 64e72a6 commit 42580c0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
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

0 comments on commit 42580c0

Please sign in to comment.