From 39412004d3a7281782b5d05baa0d5eff151c5b6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marcos=20Bezerra?= Date: Thu, 5 Dec 2024 23:07:03 -0300 Subject: [PATCH] enha: tidying rocksdb - don't store block number and hash for each tx log --- .../storage/permanent/rocks/rocks_state.rs | 4 ++-- .../permanent/rocks/types/log_mined.rs | 20 ++++++++----------- .../rocks/types/transaction_mined.rs | 6 +++++- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/eth/storage/permanent/rocks/rocks_state.rs b/src/eth/storage/permanent/rocks/rocks_state.rs index 004cddf3c..2c2c0bcf0 100644 --- a/src/eth/storage/permanent/rocks/rocks_state.rs +++ b/src/eth/storage/permanent/rocks/rocks_state.rs @@ -292,12 +292,12 @@ impl RocksStorageState { break; } + let block = block.into_inner(); let logs = block - .into_inner() .transactions .into_iter() .flat_map(|transaction| transaction.logs) - .map(LogMined::from); + .map(|log| LogMined::from_rocks_primitives(log, block.header.number, block.header.hash)); let filtered_logs = logs.filter(|log| filter.matches(log)); logs_result.extend(filtered_logs); diff --git a/src/eth/storage/permanent/rocks/types/log_mined.rs b/src/eth/storage/permanent/rocks/types/log_mined.rs index c452af6d9..2f1c21d8a 100644 --- a/src/eth/storage/permanent/rocks/types/log_mined.rs +++ b/src/eth/storage/permanent/rocks/types/log_mined.rs @@ -12,8 +12,6 @@ pub struct LogMinedRocksdb { pub transaction_hash: HashRocksdb, pub transaction_index: IndexRocksdb, pub log_index: IndexRocksdb, - pub block_number: BlockNumberRocksdb, - pub block_hash: HashRocksdb, } impl From for LogMinedRocksdb { @@ -23,21 +21,19 @@ impl From for LogMinedRocksdb { transaction_hash: item.transaction_hash.into(), transaction_index: item.transaction_index.into(), log_index: item.log_index.into(), - block_number: item.block_number.into(), - block_hash: item.block_hash.into(), } } } -impl From for LogMined { - fn from(item: LogMinedRocksdb) -> Self { +impl LogMined { + pub fn from_rocks_primitives(other: LogMinedRocksdb, block_number: BlockNumberRocksdb, block_hash: HashRocksdb) -> Self { Self { - log: item.log.into(), - transaction_hash: item.transaction_hash.into(), - transaction_index: item.transaction_index.into(), - log_index: item.log_index.into(), - block_number: item.block_number.into(), - block_hash: item.block_hash.into(), + 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: other.log_index.into(), } } } diff --git a/src/eth/storage/permanent/rocks/types/transaction_mined.rs b/src/eth/storage/permanent/rocks/types/transaction_mined.rs index b17845114..99acfc9c0 100644 --- a/src/eth/storage/permanent/rocks/types/transaction_mined.rs +++ b/src/eth/storage/permanent/rocks/types/transaction_mined.rs @@ -35,7 +35,11 @@ impl TransactionMined { block_hash: block_hash.into(), input: other.input.into(), execution: other.execution.into(), - logs: other.logs.into_iter().map(LogMined::from).collect(), + logs: other + .logs + .into_iter() + .map(|log| LogMined::from_rocks_primitives(log, block_number, block_hash)) + .collect(), transaction_index: other.transaction_index.into(), } }