Skip to content

Commit d921ea9

Browse files
authored
Merge branch 'main' into sell=buy
2 parents 858ac73 + ae55d1f commit d921ea9

File tree

3 files changed

+41
-26
lines changed

3 files changed

+41
-26
lines changed

crates/autopilot/src/arguments.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,16 @@ pub struct Arguments {
255255
#[clap(flatten)]
256256
pub db_based_solver_participation_guard: DbBasedSolverParticipationGuardConfig,
257257

258-
/// Configures whether the autopilot is supposed to do any non-trivial
259-
/// order filtering (e.g. based on balances or EIP-1271 signature validity).
258+
/// Configures whether the autopilot filters out orders with insufficient
259+
/// balances.
260260
#[clap(long, env, default_value = "false", action = clap::ArgAction::Set)]
261-
pub disable_order_filtering: bool,
261+
pub disable_order_balance_filter: bool,
262262

263-
// Filter out orders that have not been presigned even if disable_order_filtering is turned on.
263+
// Configures whether the autopilot filters out EIP-1271 orders even if their signatures are
264+
// invalid. This is useful as a workaround to let flashloan orders go through as they rely
265+
// on preHooks behing executed to make the signatures valid.
264266
#[clap(long, env, default_value = "false", action = clap::ArgAction::Set)]
265-
pub force_presign_order_filtering: bool,
267+
pub disable_1271_order_sig_filter: bool,
266268

267269
/// Enables the usage of leader lock in the database
268270
/// The second instance of autopilot will act as a follower
@@ -399,9 +401,9 @@ impl std::fmt::Display for Arguments {
399401
archive_node_url,
400402
max_solutions_per_solver,
401403
db_based_solver_participation_guard,
402-
disable_order_filtering,
404+
disable_order_balance_filter,
405+
disable_1271_order_sig_filter,
403406
enable_leader_lock,
404-
force_presign_order_filtering,
405407
} = self;
406408

407409
write!(f, "{shared}")?;
@@ -476,10 +478,13 @@ impl std::fmt::Display for Arguments {
476478
f,
477479
"db_based_solver_participation_guard: {db_based_solver_participation_guard:?}"
478480
)?;
479-
writeln!(f, "disable_order_filtering: {disable_order_filtering}")?;
480481
writeln!(
481482
f,
482-
"force_presign_order_filtering: {force_presign_order_filtering}"
483+
"disable_order_balance_filter: {disable_order_balance_filter}"
484+
)?;
485+
writeln!(
486+
f,
487+
"disable_1271_order_sig_filter: {disable_1271_order_sig_filter}"
483488
)?;
484489
writeln!(f, "enable_leader_lock: {enable_leader_lock}")?;
485490
Ok(())

crates/autopilot/src/run.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,8 @@ pub async fn run(args: Arguments, shutdown_controller: ShutdownController) {
542542
cow_amm_registry.clone(),
543543
args.run_loop_native_price_timeout,
544544
eth.contracts().settlement().address().into_legacy(),
545-
args.disable_order_filtering,
546-
args.force_presign_order_filtering,
545+
args.disable_order_balance_filter,
546+
args.disable_1271_order_sig_filter,
547547
);
548548

549549
let liveness = Arc::new(Liveness::new(args.max_auction_age));

crates/autopilot/src/solvable_orders.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ pub struct SolvableOrdersCache {
101101
cow_amm_registry: cow_amm::Registry,
102102
native_price_timeout: Duration,
103103
settlement_contract: H160,
104-
disable_order_filters: bool,
105-
force_presign_order_filtering: bool,
104+
disable_order_balance_filter: bool,
105+
disable_1271_order_sig_filter: bool,
106106
}
107107

108108
type Balances = HashMap<Query, U256>;
@@ -128,8 +128,8 @@ impl SolvableOrdersCache {
128128
cow_amm_registry: cow_amm::Registry,
129129
native_price_timeout: Duration,
130130
settlement_contract: H160,
131-
disable_order_filters: bool,
132-
force_presign_order_filtering: bool,
131+
disable_order_balance_filter: bool,
132+
disable_1271_order_sig_filter: bool,
133133
) -> Arc<Self> {
134134
Arc::new(Self {
135135
min_order_validity_period,
@@ -147,8 +147,8 @@ impl SolvableOrdersCache {
147147
cow_amm_registry,
148148
native_price_timeout,
149149
settlement_contract,
150-
disable_order_filters,
151-
force_presign_order_filtering,
150+
disable_order_balance_filter,
151+
disable_1271_order_sig_filter,
152152
})
153153
}
154154

@@ -194,7 +194,7 @@ impl SolvableOrdersCache {
194194
)
195195
};
196196

197-
let orders = if self.disable_order_filters {
197+
let orders = if self.disable_order_balance_filter {
198198
orders
199199
} else {
200200
let orders = orders_with_balance(orders, &balances, self.settlement_contract);
@@ -326,7 +326,7 @@ impl SolvableOrdersCache {
326326
self.balance_fetcher.get_balances(&queries),
327327
)
328328
.await;
329-
if self.disable_order_filters {
329+
if self.disable_order_balance_filter {
330330
return Default::default();
331331
}
332332

@@ -392,12 +392,11 @@ impl SolvableOrdersCache {
392392
counter: &mut OrderFilterCounter,
393393
invalid_order_uids: &mut HashSet<OrderUid>,
394394
) -> Vec<Order> {
395-
let filter_invalid_signatures = async {
396-
if self.disable_order_filters && !self.force_presign_order_filtering {
397-
return Default::default();
398-
}
399-
find_invalid_signature_orders(&orders, self.signature_validator.as_ref()).await
400-
};
395+
let filter_invalid_signatures = find_invalid_signature_orders(
396+
&orders,
397+
self.signature_validator.as_ref(),
398+
self.disable_1271_order_sig_filter,
399+
);
401400

402401
let (banned_user_orders, invalid_signature_orders, unsupported_token_orders) = tokio::join!(
403402
self.timed_future(
@@ -484,11 +483,17 @@ async fn get_native_prices(
484483
async fn find_invalid_signature_orders(
485484
orders: &[Order],
486485
signature_validator: &dyn SignatureValidating,
486+
disable_1271_order_sig_filter: bool,
487487
) -> Vec<OrderUid> {
488488
let mut invalid_orders = vec![];
489489
let mut signature_check_futures = FuturesUnordered::new();
490490

491491
for order in orders {
492+
if let Signature::Eip1271(_) = &order.signature
493+
&& disable_1271_order_sig_filter
494+
{
495+
continue;
496+
}
492497
if matches!(
493498
order.metadata.status,
494499
model::order::OrderStatus::PresignaturePending
@@ -1304,11 +1309,16 @@ mod tests {
13041309
.returning(|_| Ok(()));
13051310

13061311
let invalid_signature_orders =
1307-
find_invalid_signature_orders(&orders, &signature_validator).await;
1312+
find_invalid_signature_orders(&orders, &signature_validator, false).await;
13081313
assert_eq!(
13091314
invalid_signature_orders,
13101315
vec![OrderUid::from_parts(H256([4; 32]), H160([44; 20]), 4)]
13111316
);
1317+
let invalid_signature_orders_with_1271_filter_disabled =
1318+
find_invalid_signature_orders(&orders, &signature_validator, true).await;
1319+
// if we switch off the 1271 filter no orders should be returned as containing
1320+
// invalid signatures
1321+
assert_eq!(invalid_signature_orders_with_1271_filter_disabled, vec![]);
13121322
}
13131323

13141324
#[test]

0 commit comments

Comments
 (0)