Skip to content

Commit

Permalink
[Solution Submission] Return as soon as tx has been submitted to memp…
Browse files Browse the repository at this point in the history
…ool (#2432)
  • Loading branch information
fleupold authored Feb 25, 2024
1 parent 8f8ef93 commit 60b7210
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 8 additions & 3 deletions crates/driver/src/domain/mempools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions crates/driver/src/infra/mempool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()))
Expand Down

0 comments on commit 60b7210

Please sign in to comment.