Skip to content

Commit

Permalink
enha: rocks tidying - don't store tx hash or index in log
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospb19-cw committed Dec 10, 2024
1 parent dc8335f commit 41512b5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
10 changes: 5 additions & 5 deletions src/eth/storage/permanent/rocks/rocks_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,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);
Expand Down
24 changes: 12 additions & 12 deletions src/eth/storage/permanent/rocks/types/log_mined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@ 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;

#[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<LogMined> 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),
}
}
}
17 changes: 9 additions & 8 deletions src/eth/storage/permanent/rocks/types/transaction_mined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@ impl From<TransactionMined> for TransactionMinedRocksdb {
}

impl TransactionMined {
pub fn from_rocks_primitives(other: TransactionMinedRocksdb, block_number: BlockNumberRocksdb, block_hash: HashRocksdb, index: usize) -> Self {
pub fn from_rocks_primitives(other: TransactionMinedRocksdb, block_number: BlockNumberRocksdb, block_hash: HashRocksdb, tx_index: usize) -> Self {
let logs = other
.logs
.into_iter()
.enumerate()
.map(|(log_index, log)| LogMined::from_rocks_primitives(log, block_number, block_hash, tx_index, 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: Index::from(index as u64),
logs,
transaction_index: Index::from(tx_index as u64),
}
}
}

0 comments on commit 41512b5

Please sign in to comment.