Skip to content

Commit

Permalink
debug: try mdbx_txn_reset
Browse files Browse the repository at this point in the history
  • Loading branch information
kien-rise committed Aug 14, 2024
1 parent 3c42de2 commit d5b6edf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
10 changes: 10 additions & 0 deletions crates/libmdbx-rs/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ where
self.txn_execute(|txn| unsafe { ffi::mdbx_txn_id(txn) })
}

pub fn mdbx_txn_reset(&self) -> Result<()> {
mdbx_result(unsafe { ffi::mdbx_txn_reset(self.inner.txn.txn) })?;
Ok(())
}

pub fn mdbx_txn_renew(&self) -> Result<()> {
mdbx_result(unsafe { ffi::mdbx_txn_renew(self.inner.txn.txn) })?;
Ok(())
}

/// Gets an item from a database.
///
/// This function retrieves the data associated with the given key in the
Expand Down
24 changes: 21 additions & 3 deletions src/storage/on_disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ impl OnDiskStorage {
let tx_ref = self
.cache_txs
.entry(std::thread::current().id())
.or_insert_with(|| self.env.begin_ro_txn().unwrap());
.or_insert_with(|| {
let tx = self.env.begin_ro_txn().unwrap();
tx.mdbx_txn_reset().unwrap();
tx
});
tx_ref.value().mdbx_txn_renew()?;
let bytes: Option<Vec<u8>> = tx_ref
.value()
.get(self.table_accounts.dbi(), address.as_ref())?;
tx_ref.value().mdbx_txn_reset()?;
drop(tx_ref);
let account: Option<EvmAccount> = match bytes {
Some(bytes) => Some(
Expand Down Expand Up @@ -90,10 +96,16 @@ impl Storage for OnDiskStorage {
let tx_ref = self
.cache_txs
.entry(std::thread::current().id())
.or_insert_with(|| self.env.begin_ro_txn().unwrap());
.or_insert_with(|| {
let tx = self.env.begin_ro_txn().unwrap();
tx.mdbx_txn_reset().unwrap();
tx
});
tx_ref.value().mdbx_txn_renew()?;
let bytes: Option<Vec<u8>> = tx_ref
.value()
.get(self.table_bytecodes.dbi(), code_hash.as_ref())?;
tx_ref.value().mdbx_txn_reset()?;
drop(tx_ref);
let code: Option<EvmCode> = match bytes {
Some(bytes) => Some(
Expand Down Expand Up @@ -133,10 +145,16 @@ impl Storage for OnDiskStorage {
let tx_ref = self
.cache_txs
.entry(std::thread::current().id())
.or_insert_with(|| self.env.begin_ro_txn().unwrap());
.or_insert_with(|| {
let tx = self.env.begin_ro_txn().unwrap();
tx.mdbx_txn_reset().unwrap();
tx
});
tx_ref.value().mdbx_txn_renew()?;
let bytes: Option<[u8; 32]> = tx_ref
.value()
.get(self.table_block_hashes.dbi(), B64::from(*number).as_ref())?;
tx_ref.value().mdbx_txn_reset()?;
drop(tx_ref);
let block_hash = match bytes {
Some(bytes) => B256::from(bytes),
Expand Down

0 comments on commit d5b6edf

Please sign in to comment.