From 60b7210c2a00f5cd1f28503975118c614dbcead7 Mon Sep 17 00:00:00 2001 From: Felix Leupold Date: Sun, 25 Feb 2024 20:51:41 +0200 Subject: [PATCH] [Solution Submission] Return as soon as tx has been submitted to mempool (#2432) --- crates/driver/src/domain/mempools.rs | 11 ++++++++--- crates/driver/src/infra/mempool/mod.rs | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/driver/src/domain/mempools.rs b/crates/driver/src/domain/mempools.rs index d8c63112c7..6ffe0ea709 100644 --- a/crates/driver/src/domain/mempools.rs +++ b/crates/driver/src/domain/mempools.rs @@ -104,11 +104,16 @@ impl Mempools { competition::solution::settlement::Internalization::Enable, ) }; - let hash = mempool.submit(tx.clone(), settlement.gas, solver).await?; + + // Instantiate block stream and skip the current block before we submit the + // settlement. This way we only run iterations in blocks that can potentially + // include the settlement. let mut block_stream = into_stream(self.ethereum.current_block().clone()); + block_stream.next().await; + + let hash = mempool.submit(tx.clone(), settlement.gas, solver).await?; loop { - // Wait for the next block to be mined or we time out. Block stream immediately - // yields the latest block, thus the first iteration starts immediately. + // Wait for the next block to be mined or we time out. if tokio::time::timeout_at(mempool.config().deadline(), block_stream.next()) .await .is_err() diff --git a/crates/driver/src/infra/mempool/mod.rs b/crates/driver/src/infra/mempool/mod.rs index a32038e449..0d7a7ae761 100644 --- a/crates/driver/src/infra/mempool/mod.rs +++ b/crates/driver/src/infra/mempool/mod.rs @@ -57,6 +57,8 @@ impl Inner { Self { config, transport } } + /// Submits a transaction to the mempool. Returns optimistically as soon as + /// the transaction is pending. pub async fn submit( &self, tx: eth::Tx, @@ -74,6 +76,7 @@ impl Inner { .value(tx.value.0) .gas(gas.limit.0) .access_list(web3::types::AccessList::from(tx.access_list)) + .resolve(ethcontract::transaction::ResolveCondition::Pending) .send() .await .map(|result| eth::TxId(result.hash()))