diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index a12e724..344910a 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -375,6 +375,23 @@ pub struct BenchmarkingContext { #[arg(short = 'r', long = "default-repetition-count", default_value_t = 1000)] pub default_repetition_count: usize, + /// This transaction controls whether the benchmarking driver should await for transactions to + /// be included in a block before moving on to the next transaction in the sequence or not. + /// + /// This behavior is useful in certain cases and not so useful in others. For example, in some + /// repetition block if there's some kind of relationship between txs n and n+1 (for example a + /// mint then a transfer) then you would want to wait for the minting to happen and then move on + /// to the transfers. On the other hand, if there's no relationship between the transactions n + /// and n+1 (e.g., mint and another mint of a different token) then awaiting the first mint to + /// be included in a block might not seem necessary. + /// + /// By default, this behavior is set to false to allow the benchmarking framework to saturate + /// the node's mempool as quickly as possible. However, as explained above, there are cases + /// where it's needed and certain workloads where failure to provide this argument would lead to + /// inaccurate results. + #[arg(long)] + pub await_transaction_inclusion: bool, + /// Configuration parameters for the corpus files to use. #[clap(flatten, next_help_heading = "Corpus Configuration")] pub corpus_configuration: CorpusConfiguration, diff --git a/crates/core/src/differential_benchmarks/driver.rs b/crates/core/src/differential_benchmarks/driver.rs index 5dcc2fb..078afd2 100644 --- a/crates/core/src/differential_benchmarks/driver.rs +++ b/crates/core/src/differential_benchmarks/driver.rs @@ -73,6 +73,10 @@ pub struct Driver<'a, I> { /// The number of steps that were executed on the driver. steps_executed: usize, + /// This function controls if the driver should wait for transactions to be included in a block + /// or not before proceeding forward. + await_transaction_inclusion: bool, + /// This is the queue of steps that are to be executed by the driver for this test case. Each /// time `execute_step` is called one of the steps is executed. steps_iterator: I, @@ -89,6 +93,7 @@ where private_key_allocator: Arc>, cached_compiler: &CachedCompiler<'a>, watcher_tx: UnboundedSender, + await_transaction_inclusion: bool, steps: I, ) -> Result { let mut this = Driver { @@ -104,6 +109,7 @@ where execution_state: ExecutionState::empty(), steps_executed: 0, steps_iterator: steps, + await_transaction_inclusion, watcher_tx, }; this.init_execution_state(cached_compiler) @@ -166,7 +172,7 @@ where code, ); let receipt = self - .execute_transaction(tx, None) + .execute_transaction(tx, None, Duration::from_secs(5 * 60)) .and_then(|(_, receipt_fut)| receipt_fut) .await .inspect_err(|err| { @@ -365,7 +371,17 @@ where let tx = step .as_transaction(self.resolver.as_ref(), self.default_resolution_context()) .await?; - Ok(self.execute_transaction(tx, Some(step_path)).await?.0) + + let (tx_hash, receipt_future) = self + .execute_transaction(tx, Some(step_path), Duration::from_secs(30 * 60)) + .await?; + if self.await_transaction_inclusion { + let _ = receipt_future + .await + .context("Failed while waiting for transaction inclusion in block")?; + } + + Ok(tx_hash) } } } @@ -466,6 +482,7 @@ where .collect::>(); steps.into_iter() }, + await_transaction_inclusion: self.await_transaction_inclusion, watcher_tx: self.watcher_tx.clone(), }) .map(|driver| driver.execute_all()); @@ -632,7 +649,7 @@ where }; let receipt = match self - .execute_transaction(tx, step_path) + .execute_transaction(tx, step_path, Duration::from_secs(5 * 60)) .and_then(|(_, receipt_fut)| receipt_fut) .await { @@ -683,6 +700,7 @@ where &self, transaction: TransactionRequest, step_path: Option<&StepPath>, + receipt_wait_duration: Duration, ) -> anyhow::Result<(TxHash, impl Future>)> { let node = self.platform_information.node; let transaction_hash = node @@ -704,7 +722,7 @@ where Ok((transaction_hash, async move { info!("Starting to poll for transaction receipt"); poll( - Duration::from_secs(30 * 60), + receipt_wait_duration, PollingWaitBehavior::Constant(Duration::from_secs(1)), || { async move { diff --git a/crates/core/src/differential_benchmarks/entry_point.rs b/crates/core/src/differential_benchmarks/entry_point.rs index 17b897b..fdaa5af 100644 --- a/crates/core/src/differential_benchmarks/entry_point.rs +++ b/crates/core/src/differential_benchmarks/entry_point.rs @@ -160,6 +160,7 @@ pub async fn handle_differential_benchmarks( private_key_allocator, cached_compiler.as_ref(), watcher_tx.clone(), + context.await_transaction_inclusion, test_definition .case .steps_iterator_for_benchmarks(context.default_repetition_count)