Skip to content

Commit

Permalink
Merge branch 'main' into add-base-SwapRouter02
Browse files Browse the repository at this point in the history
  • Loading branch information
m-lord-renkse authored Nov 18, 2024
2 parents 7f6d44e + 4b8c4f7 commit 5a8f293
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
50 changes: 28 additions & 22 deletions crates/autopilot/src/run_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use {
database::order_events::OrderEventLabel,
ethcontract::U256,
ethrpc::block_stream::BlockInfo,
futures::{future::BoxFuture, TryFutureExt},
futures::{future::BoxFuture, FutureExt, TryFutureExt},
itertools::Itertools,
model::solver_competition::{
CompetitionAuction,
Expand Down Expand Up @@ -239,7 +239,7 @@ impl RunLoop {
}

let competition_simulation_block = self.eth.current_block().borrow().number;
let block_deadline = competition_simulation_block + self.config.submission_deadline;
let block_deadline = auction.block + self.config.submission_deadline;

// Post-processing should not be executed asynchronously since it includes steps
// of storing all the competition/auction-related data to the DB.
Expand Down Expand Up @@ -315,7 +315,7 @@ impl RunLoop {
let driver_ = driver.clone();

let settle_fut = async move {
tracing::info!(driver = %driver_.name, "settling");
tracing::info!(driver = %driver_.name, solution = %solution_id, "settling");
let submission_start = Instant::now();

match self_
Expand Down Expand Up @@ -797,24 +797,31 @@ impl RunLoop {
auction_id: i64,
submission_deadline_latest_block: u64,
) -> Result<TxId, SettleError> {
let request = settle::Request {
solution_id,
submission_deadline_latest_block,
auction_id,
};
let settle = async move {
let current_block = self.eth.current_block().borrow().number;
anyhow::ensure!(
current_block < submission_deadline_latest_block,
"submission deadline was missed while waiting for the settlement queue"
);

let request = settle::Request {
solution_id,
submission_deadline_latest_block,
auction_id,
};
driver
.settle(&request, self.config.max_settlement_transaction_wait)
.await
}
.boxed();

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

// Wait for either the settlement transaction to be mined or the driver returned
// a result.
let result = match futures::future::select(
Box::pin(self.wait_for_settlement_transaction(
auction_id,
self.config.submission_deadline,
solver,
)),
Box::pin(driver.settle(&request, self.config.max_settlement_transaction_wait)),
)
.await
{
let result = match futures::future::select(wait_for_settlement_transaction, settle).await {
futures::future::Either::Left((res, _)) => res,
futures::future::Either::Right((driver_result, wait_for_settlement_transaction)) => {
match driver_result {
Expand All @@ -841,12 +848,11 @@ impl RunLoop {
async fn wait_for_settlement_transaction(
&self,
auction_id: i64,
max_blocks_wait: u64,
solver: eth::Address,
submission_deadline_latest_block: u64,
) -> Result<eth::TxId, SettleError> {
let current = self.eth.current_block().borrow().number;
let deadline = current.saturating_add(max_blocks_wait);
tracing::debug!(%current, %deadline, %auction_id, "waiting for tag");
tracing::debug!(%current, deadline=%submission_deadline_latest_block, %auction_id, "waiting for tag");
loop {
let block = ethrpc::block_stream::next_block(self.eth.current_block()).await;
// Run maintenance to ensure the system processed the last available block so
Expand All @@ -869,7 +875,7 @@ impl RunLoop {
);
}
}
if block.number >= deadline {
if block.number >= submission_deadline_latest_block {
break;
}
}
Expand Down
4 changes: 4 additions & 0 deletions crates/driver/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ components:
description: The last block number in which the solution TX can be included.
type: integer
example: 12345
auctionId:
description: Auction ID in which the specified solution ID is competing.
type: string
example: "123"
RevealedResponse:
description: Response of the reveal endpoint.
type: object
Expand Down
8 changes: 1 addition & 7 deletions crates/shared/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use {
},
anyhow::{ensure, Context, Result},
bigdecimal::BigDecimal,
ethcontract::{H160, H256, U256},
ethcontract::{H160, U256},
std::{
fmt::{self, Display, Formatter},
num::NonZeroU64,
Expand Down Expand Up @@ -199,10 +199,6 @@ pub struct Arguments {
#[clap(long, env, value_enum, ignore_case = true, use_value_delimiter = true)]
pub balancer_factories: Option<Vec<BalancerFactoryKind>>,

/// Deny list of balancer pool ids.
#[clap(long, env, use_value_delimiter = true)]
pub balancer_pool_deny_list: Vec<H256>,

/// Value of the authorization header for the solver competition post api.
#[clap(long, env)]
pub solver_competition_auth: Option<String>,
Expand Down Expand Up @@ -352,7 +348,6 @@ impl Display for Arguments {
pool_cache_delay_between_retries,
use_internal_buffers,
balancer_factories,
balancer_pool_deny_list,
solver_competition_auth,
network_block_interval,
settlement_contract_address,
Expand Down Expand Up @@ -394,7 +389,6 @@ impl Display for Arguments {
)?;
writeln!(f, "use_internal_buffers: {}", use_internal_buffers)?;
writeln!(f, "balancer_factories: {:?}", balancer_factories)?;
writeln!(f, "balancer_pool_deny_list: {:?}", balancer_pool_deny_list)?;
display_secret_option(
f,
"solver_competition_auth",
Expand Down

0 comments on commit 5a8f293

Please sign in to comment.