Skip to content

Commit

Permalink
Merge branch 'main' into feature/storing-call-data-in-quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrug committed Dec 11, 2024
2 parents ebd3e3b + 2ad85a3 commit 8baf668
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions crates/driver/src/domain/mempools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl Mempools {
block_stream.next().await;

let hash = mempool.submit(tx.clone(), settlement.gas, solver).await?;
tracing::debug!(?hash, "submitted tx to the mempool");

// Wait for the transaction to be mined, expired or failing.
let result = async {
Expand Down
8 changes: 5 additions & 3 deletions crates/driver/src/infra/api/routes/settle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ async fn route(
// aborts the endpoint handler code.
// This can happen due do connection issues or when the autopilot aborts
// the `/settle` call when we reach the submission deadline.
Ok(tokio::task::spawn(handle_request)
.await
.unwrap_or_else(|_| Err(competition::Error::SubmissionError))?)
Ok(
::observe::request_id::spawn_task_with_current_request_id(handle_request)
.await
.unwrap_or_else(|_| Err(competition::Error::SubmissionError))?,
)
}
17 changes: 16 additions & 1 deletion crates/observe/src/request_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
//! And when we issue requests to another process we can simply fetch the
//! current identifier specific to our task and send that along with the
//! request.
use std::future::Future;
use {std::future::Future, tokio::task::JoinHandle};

tokio::task_local! {
pub static REQUEST_ID: String;
}
Expand All @@ -39,6 +40,20 @@ where
REQUEST_ID.scope(id, scope).await
}

/// Spawns a new task and ensures it uses the same request id as the current
/// task (if present). This allows for tracing requests across task boundaries.
pub fn spawn_task_with_current_request_id<F>(future: F) -> JoinHandle<F::Output>
where
F: Future + Send + 'static,
F::Output: Send + 'static,
{
if let Some(id) = get_task_local_storage() {
tokio::task::spawn(REQUEST_ID.scope(id, future))
} else {
tokio::task::spawn(future)
}
}

/// Takes a `tower::Service` and embeds it in a `make_service` function that
/// spawns one of these services per incoming request.
/// But crucially before spawning that service task local storage will be
Expand Down

0 comments on commit 8baf668

Please sign in to comment.