From 04d809503033cf3ec3ba46a47f2bed9b008b5f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marcos=20Bezerra?= Date: Thu, 5 Dec 2024 23:36:20 -0300 Subject: [PATCH] enha: rocks tidying - don't store tx hash or index in log --- .../storage/permanent/rocks/rocks_state.rs | 10 ++++---- .../storage/permanent/rocks/types/index.rs | 6 +++++ .../permanent/rocks/types/log_mined.rs | 24 +++++++++---------- .../rocks/types/transaction_mined.rs | 15 +++++++----- 4 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/eth/storage/permanent/rocks/rocks_state.rs b/src/eth/storage/permanent/rocks/rocks_state.rs index d4d4fe157..b40f25023 100644 --- a/src/eth/storage/permanent/rocks/rocks_state.rs +++ b/src/eth/storage/permanent/rocks/rocks_state.rs @@ -293,11 +293,11 @@ impl RocksStorageState { } let block = block.into_inner(); - let logs = block - .transactions - .into_iter() - .flat_map(|transaction| transaction.logs.into_iter().enumerate()) - .map(|(index, log)| LogMined::from_rocks_primitives(log, block.header.number, block.header.hash, index)); + let logs = block.transactions.into_iter().enumerate().flat_map(|(tx_index, transaction)| { + transaction.logs.into_iter().enumerate().map(move |(log_index, log)| { + LogMined::from_rocks_primitives(log, block.header.number, block.header.hash, tx_index, transaction.input.hash, log_index) + }) + }); let filtered_logs = logs.filter(|log| filter.matches(log)); logs_result.extend(filtered_logs); diff --git a/src/eth/storage/permanent/rocks/types/index.rs b/src/eth/storage/permanent/rocks/types/index.rs index 6ca7bf13b..1e515a49b 100644 --- a/src/eth/storage/permanent/rocks/types/index.rs +++ b/src/eth/storage/permanent/rocks/types/index.rs @@ -5,6 +5,12 @@ use crate::eth::primitives::Index; #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, derive_more::Add, Copy, Hash, fake::Dummy)] pub struct IndexRocksdb(pub(self) u32); +impl IndexRocksdb { + pub fn as_usize(&self) -> usize { + self.0 as usize + } +} + impl From for IndexRocksdb { fn from(item: Index) -> Self { IndexRocksdb(item.0 as u32) diff --git a/src/eth/storage/permanent/rocks/types/log_mined.rs b/src/eth/storage/permanent/rocks/types/log_mined.rs index c5a3fd93f..c5db8d235 100644 --- a/src/eth/storage/permanent/rocks/types/log_mined.rs +++ b/src/eth/storage/permanent/rocks/types/log_mined.rs @@ -2,7 +2,6 @@ use std::fmt::Debug; use super::block_number::BlockNumberRocksdb; use super::hash::HashRocksdb; -use super::index::IndexRocksdb; use super::log::LogRocksdb; use crate::eth::primitives::Index; use crate::eth::primitives::LogMined; @@ -10,29 +9,30 @@ use crate::eth::primitives::LogMined; #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, fake::Dummy)] pub struct LogMinedRocksdb { pub log: LogRocksdb, - pub transaction_hash: HashRocksdb, - pub transaction_index: IndexRocksdb, } impl From for LogMinedRocksdb { fn from(item: LogMined) -> Self { - Self { - log: item.log.into(), - transaction_hash: item.transaction_hash.into(), - transaction_index: item.transaction_index.into(), - } + Self { log: item.log.into() } } } impl LogMined { - pub fn from_rocks_primitives(other: LogMinedRocksdb, block_number: BlockNumberRocksdb, block_hash: HashRocksdb, index: usize) -> Self { + pub fn from_rocks_primitives( + other: LogMinedRocksdb, + block_number: BlockNumberRocksdb, + block_hash: HashRocksdb, + tx_index: usize, + tx_hash: HashRocksdb, + log_index: usize, + ) -> Self { Self { block_number: block_number.into(), block_hash: block_hash.into(), log: other.log.into(), - transaction_hash: other.transaction_hash.into(), - transaction_index: other.transaction_index.into(), - log_index: Index::from(index as u64), + transaction_hash: tx_hash.into(), + transaction_index: Index::from(tx_index as u64), + log_index: Index::from(log_index as u64), } } } diff --git a/src/eth/storage/permanent/rocks/types/transaction_mined.rs b/src/eth/storage/permanent/rocks/types/transaction_mined.rs index b377ece18..a2f948800 100644 --- a/src/eth/storage/permanent/rocks/types/transaction_mined.rs +++ b/src/eth/storage/permanent/rocks/types/transaction_mined.rs @@ -30,18 +30,21 @@ impl From for TransactionMinedRocksdb { impl TransactionMined { pub fn from_rocks_primitives(other: TransactionMinedRocksdb, block_number: BlockNumberRocksdb, block_hash: HashRocksdb) -> Self { + let logs = other + .logs + .into_iter() + .enumerate() + .map(|(log_index, log)| { + LogMined::from_rocks_primitives(log, block_number, block_hash, other.transaction_index.as_usize(), other.input.hash, log_index) + }) + .collect(); Self { block_number: block_number.into(), block_hash: block_hash.into(), input: other.input.into(), execution: other.execution.into(), - logs: other - .logs - .into_iter() - .enumerate() - .map(|(log_index, log)| LogMined::from_rocks_primitives(log, block_number, block_hash, log_index)) - .collect(), transaction_index: other.transaction_index.into(), + logs, } } }