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 11, 2024
1 parent ce50751 commit 04d8095
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 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 @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/eth/storage/permanent/rocks/types/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Index> for IndexRocksdb {
fn from(item: Index) -> Self {
IndexRocksdb(item.0 as u32)
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),
}
}
}
15 changes: 9 additions & 6 deletions src/eth/storage/permanent/rocks/types/transaction_mined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,21 @@ impl From<TransactionMined> 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,
}
}
}

0 comments on commit 04d8095

Please sign in to comment.