Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions crates/autopilot/src/infra/persistence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,13 @@ impl Persistence {
ex.commit().await.context("commit")
}

/// For a given auction and solver, tries to find the settlement
/// transaction.
/// Tries to find the transaction executing a given solution proposed
/// by the solver.
pub async fn find_settlement_transaction(
&self,
auction_id: i64,
solver: eth::Address,
solution_uid: usize,
) -> Result<Option<eth::TxId>, DatabaseError> {
let _timer = Metrics::get()
.database_queries
Expand All @@ -342,6 +343,9 @@ impl Persistence {
&mut ex,
auction_id,
ByteArray(solver.0.0),
solution_uid
.try_into()
.context("could not convert solution id to i64")?,
)
.await?
.map(|hash| H256(hash.0).into()))
Expand Down
10 changes: 8 additions & 2 deletions crates/autopilot/src/run_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,12 @@ impl RunLoop {
.boxed();

let wait_for_settlement_transaction = self
.wait_for_settlement_transaction(auction_id, solver, submission_deadline_latest_block)
.wait_for_settlement_transaction(
auction_id,
solver,
submission_deadline_latest_block,
solution_uid,
)
.boxed();

// Wait for either the settlement transaction to be mined or the driver returned
Expand Down Expand Up @@ -885,6 +890,7 @@ impl RunLoop {
auction_id: i64,
solver: eth::Address,
submission_deadline_latest_block: u64,
solution_uid: usize,
) -> Result<eth::TxId, SettleError> {
let current = self.eth.current_block().borrow().number;
tracing::debug!(%current, deadline=%submission_deadline_latest_block, %auction_id, "waiting for tag");
Expand All @@ -896,7 +902,7 @@ impl RunLoop {

match self
.persistence
.find_settlement_transaction(auction_id, solver)
.find_settlement_transaction(auction_id, solver, solution_uid)
.await
{
Ok(Some(transaction)) => return Ok(transaction),
Expand Down
4 changes: 3 additions & 1 deletion crates/database/src/settlements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ pub async fn find_settlement_transaction(
ex: &mut PgConnection,
auction_id: i64,
solver: Address,
solution_uid: i64,
) -> Result<Option<TransactionHash>, sqlx::Error> {
const QUERY: &str = r#"
SELECT tx_hash
FROM settlements
WHERE
auction_id = $1 AND solver = $2
auction_id = $1 AND solver = $2 AND solution_uid = $3
"#;
sqlx::query_as(QUERY)
.bind(auction_id)
.bind(solver)
.bind(solution_uid)
.fetch_optional(ex)
.await
}
Expand Down
Loading