Skip to content

Commit

Permalink
enha: tidying rocksdb - don't store log index
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospb19-cw committed Dec 10, 2024
1 parent bf1ce28 commit dc8335f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/eth/storage/permanent/rocks/rocks_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ impl RocksStorageState {
let logs = block
.transactions
.into_iter()
.flat_map(|transaction| transaction.logs)
.map(|log| LogMined::from_rocks_primitives(log, block.header.number, block.header.hash));
.flat_map(|transaction| transaction.logs.into_iter().enumerate())
.map(|(index, log)| LogMined::from_rocks_primitives(log, block.header.number, block.header.hash, index));

let filtered_logs = logs.filter(|log| filter.matches(log));
logs_result.extend(filtered_logs);
Expand Down
7 changes: 3 additions & 4 deletions src/eth/storage/permanent/rocks/types/log_mined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ 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,
pub log_index: IndexRocksdb,
}

impl From<LogMined> for LogMinedRocksdb {
Expand All @@ -20,20 +20,19 @@ impl From<LogMined> for LogMinedRocksdb {
log: item.log.into(),
transaction_hash: item.transaction_hash.into(),
transaction_index: item.transaction_index.into(),
log_index: item.log_index.into(),
}
}
}

impl LogMined {
pub fn from_rocks_primitives(other: LogMinedRocksdb, block_number: BlockNumberRocksdb, block_hash: HashRocksdb) -> Self {
pub fn from_rocks_primitives(other: LogMinedRocksdb, block_number: BlockNumberRocksdb, block_hash: HashRocksdb, 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: other.log_index.into(),
log_index: Index::from(index as u64),
}
}
}
3 changes: 2 additions & 1 deletion src/eth/storage/permanent/rocks/types/transaction_mined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ impl TransactionMined {
logs: other
.logs
.into_iter()
.map(|log| LogMined::from_rocks_primitives(log, block_number, block_hash))
.enumerate()
.map(|(log_index, log)| LogMined::from_rocks_primitives(log, block_number, block_hash, log_index))
.collect(),
transaction_index: Index::from(index as u64),
}
Expand Down

0 comments on commit dc8335f

Please sign in to comment.