From a99da61ec199ce2a16fce3f64b735a864d87a3a8 Mon Sep 17 00:00:00 2001 From: Renato Dinhani <101204870+dinhani-cw@users.noreply.github.com> Date: Mon, 12 Aug 2024 20:35:11 -0300 Subject: [PATCH] perf: avoid recomputing tx_hash when saving execution (#1634) --- src/eth/miner/miner.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/eth/miner/miner.rs b/src/eth/miner/miner.rs index b9f90b57f..d31d5e77a 100644 --- a/src/eth/miner/miner.rs +++ b/src/eth/miner/miner.rs @@ -94,9 +94,11 @@ impl Miner { /// Persists a transaction execution. pub fn save_execution(&self, tx_execution: TransactionExecution, check_conflicts: bool) -> Result<(), StratusError> { + let tx_hash = tx_execution.hash(); + // track #[cfg(feature = "tracing")] - let _span = info_span!("miner::save_execution", tx_hash = %tx_execution.hash()).entered(); + let _span = info_span!("miner::save_execution", %tx_hash).entered(); // if automine is enabled, only one transaction can enter the block at time. let _save_execution_lock = if self.mode.is_automine() { @@ -106,11 +108,12 @@ impl Miner { }; // save execution to temporary storage - let tx_hash = tx_execution.hash(); self.storage.save_execution(tx_execution, check_conflicts)?; - // if automine is enabled, automatically mines a block + // notify let _ = self.notifier_pending_txs.send(tx_hash); + + // if automine is enabled, automatically mines a block if self.mode.is_automine() { self.mine_local_and_commit()?; }