From 42580c0868fd9cfbeb7d516e06ac37d91a90e910 Mon Sep 17 00:00:00 2001 From: Renato Dinhani <101204870+dinhani-cw@users.noreply.github.com> Date: Tue, 30 Jul 2024 20:41:54 -0300 Subject: [PATCH] enha: force block changes to redis (#1576) --- .../primitives/execution_account_changes.rs | 9 +--- src/eth/storage/redis/redis_permanent.rs | 44 +++++++++++-------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/eth/primitives/execution_account_changes.rs b/src/eth/primitives/execution_account_changes.rs index 153f1e87f..abf45930b 100644 --- a/src/eth/primitives/execution_account_changes.rs +++ b/src/eth/primitives/execution_account_changes.rs @@ -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() } } diff --git a/src/eth/storage/redis/redis_permanent.rs b/src/eth/storage/redis/redis_permanent.rs index d4ceebc0b..99edc0893 100644 --- a/src/eth/storage/redis/redis_permanent.rs +++ b/src/eth/storage/redis/redis_permanent.rs @@ -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())); } } }