Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ reth-cli = { git = "https://github.com/okx/reth", rev = "3ba1e5d3820fff48ade7962
reth-cli-commands = { git = "https://github.com/okx/reth", rev = "3ba1e5d3820fff48ade7962769cb367ac183ba92" }
reth-cli-util = { git = "https://github.com/okx/reth", rev = "3ba1e5d3820fff48ade7962769cb367ac183ba92" }
reth-db = { git = "https://github.com/okx/reth", rev = "3ba1e5d3820fff48ade7962769cb367ac183ba92" }
reth-db-api = { git = "https://github.com/okx/reth", rev = "3ba1e5d3820fff48ade7962769cb367ac183ba92" }
reth-errors = { git = "https://github.com/okx/reth", rev = "3ba1e5d3820fff48ade7962769cb367ac183ba92" }
reth-ethereum-forks = { git = "https://github.com/okx/reth", rev = "3ba1e5d3820fff48ade7962769cb367ac183ba92" }
reth-evm = { git = "https://github.com/okx/reth", rev = "3ba1e5d3820fff48ade7962769cb367ac183ba92" }
Expand Down
1 change: 1 addition & 0 deletions crates/innertx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ default = []
[dependencies]
reth-revm.workspace = true
reth-db = { workspace = true, features = ["mdbx"] }
reth-db-api.workspace = true
reth-exex.workspace = true
reth-node-api.workspace = true
reth-provider.workspace = true
Expand Down
54 changes: 32 additions & 22 deletions crates/innertx/src/db_utils.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,56 @@
use std::fmt::Debug;
use std::fmt;

use alloy_primitives::{BlockHash, TxHash};
use alloy_rlp::{decode_exact, encode, Encodable};
use eyre::Report;
use once_cell::sync::OnceCell;

use crate::{
innertx_inspector::InternalTransaction,
structs::{BlockTable, DBTables, TxTable},
};
use crate::innertx_inspector::InternalTransaction;
use reth_db::{
create_db,
mdbx::init_db_for,
mdbx::{Database, DatabaseArguments, Transaction, WriteFlags, RW},
table::Table,
DatabaseEnv,
};
use reth_db_api::{
models::ClientVersion,
table::{Table, TableInfo},
tables, TableSet, TableType, TableViewer,
};

static XLAYERDB: OnceCell<DatabaseEnv> = OnceCell::new();

pub fn initialize_inner_tx_db(db_path: &str) -> Result<(), Report> {
let db_dir = format!("{}/{}", db_path, "xlayerdb");
let db_create_result = create_db(&db_dir, DatabaseArguments::default());
if let Err(e) = db_create_result {
return Err(e.wrap_err(format!("xlayerdb creation failed at path {db_dir}")));
reth_db_api::tables! {
/// Maps transaction hash to vector of internal transactions
/// Key: TxHash (as Vec<u8>)
/// Value: Vec<InternalTransaction> (RLP encoded as Vec<u8>)
table TxTable {
type Key = Vec<u8>;
type Value = Vec<u8>;
}

let mut db = db_create_result.unwrap();

let tables_create_result = db.create_and_track_tables_for::<DBTables>();
if let Err(err) = tables_create_result {
return Err(Into::<Report>::into(err).wrap_err("xlayerdb tables creation failed"));
/// Maps block hash to vector of transaction hashes in that block
/// Key: BlockHash (as Vec<u8>)
/// Value: Vec<TxHash> (RLP encoded as Vec<u8>)
table BlockTable {
type Key = Vec<u8>;
type Value = Vec<u8>;
}
}

let db_set_result = XLAYERDB.set(db);
if db_set_result.is_err() {
return Err(Report::msg("xlayerdb was initialize_inner_tx_db more than once"));
}
pub fn initialize_inner_tx_db(db_path: &str) -> Result<(), Report> {
let db_dir = format!("{}/{}", db_path, "xlayerdb");

let db = init_db_for::<_, Tables>(&db_dir, DatabaseArguments::new(ClientVersion::default()))?;

XLAYERDB.set(db).map_err(|_| Report::msg("xlayerdb was initialized more than once"))?;

Ok(())
}

pub fn write_single<T: Table, P: Encodable + Debug>(key: Vec<u8>, value: P) -> Result<(), Report> {
pub fn write_single<T: Table, P: Encodable + std::fmt::Debug>(
key: Vec<u8>,
value: P,
) -> Result<(), Report> {
let txn_begin_result = XLAYERDB.get().unwrap().begin_rw_txn();
if let Err(err) = txn_begin_result {
return Err(Into::<Report>::into(err).wrap_err("write single txn begin failed"));
Expand Down
1 change: 0 additions & 1 deletion crates/innertx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ pub mod db_utils;
pub mod innertx_inspector;
pub mod replay_utils;
pub mod rpc_utils;
pub mod structs;
pub mod subscriber_utils;
2 changes: 1 addition & 1 deletion crates/innertx/src/replay_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use crate::{
db_utils::{
delete_single, rw_batch_delete, rw_batch_end, rw_batch_start, rw_batch_write, write_single,
},
db_utils::{BlockTable, TxTable},
innertx_inspector::TraceCollector,
structs::{BlockTable, TxTable},
};

pub fn replay_and_index_block<P, E, N>(
Expand Down
56 changes: 0 additions & 56 deletions crates/innertx/src/structs.rs

This file was deleted.