Skip to content

Commit

Permalink
Limit number of accepted proposed solutions (#3078)
Browse files Browse the repository at this point in the history
# Description
Fixes #3063

With full colocation, we need to have a limit on the number of solutions
a solver can propose per auction.

# Changes
<!-- List of detailed changes (how the change is accomplished) -->

- [ ] Added configuration parameter for limiting the number of proposed
solutions per solver
- [ ] Filter out solutions that don't satisfy the new condition.

## How to test
Existing tests.
  • Loading branch information
sunce86 authored Oct 24, 2024
1 parent fad84f1 commit 516a4e0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/autopilot/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ pub struct Arguments {
/// to settle their winning orders at the same time.
pub max_winners_per_auction: usize,

#[clap(long, env, default_value = "3")]
/// The maximum allowed number of solutions to be proposed from a single
/// solver, per auction.
pub max_solutions_per_solver: usize,

/// Archive node URL used to index CoW AMM
#[clap(long, env)]
pub archive_node_url: Option<Url>,
Expand Down Expand Up @@ -278,6 +283,7 @@ impl std::fmt::Display for Arguments {
run_loop_native_price_timeout,
max_winners_per_auction,
archive_node_url,
max_solutions_per_solver,
} = self;

write!(f, "{}", shared)?;
Expand Down Expand Up @@ -357,6 +363,11 @@ impl std::fmt::Display for Arguments {
)?;
writeln!(f, "max_winners_per_auction: {:?}", max_winners_per_auction)?;
writeln!(f, "archive_node_url: {:?}", archive_node_url)?;
writeln!(
f,
"max_solutions_per_solver: {:?}",
max_solutions_per_solver
)?;
Ok(())
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/autopilot/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ pub async fn run(args: Arguments) {
solve_deadline: args.solve_deadline,
max_run_loop_delay: args.max_run_loop_delay,
max_winners_per_auction: args.max_winners_per_auction,
max_solutions_per_solver: args.max_solutions_per_solver,
};

let run = RunLoop::new(
Expand Down
11 changes: 11 additions & 0 deletions crates/autopilot/src/run_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub struct Config {
/// by waiting for the next block to appear.
pub max_run_loop_delay: Duration,
pub max_winners_per_auction: usize,
pub max_solutions_per_solver: usize,
}

pub struct RunLoop {
Expand Down Expand Up @@ -550,6 +551,16 @@ impl RunLoop {
std::cmp::Reverse(participant.solution().score().get().0)
});

// Limit the number of accepted solutions per solver. Do not alter the ordering
// of solutions
let mut counter = HashMap::new();
solutions.retain(|participant| {
let driver = participant.driver().name.clone();
let count = counter.entry(driver).or_insert(0);
*count += 1;
*count <= self.config.max_solutions_per_solver
});

// Filter out solutions that are not fair
let solutions = solutions
.iter()
Expand Down

0 comments on commit 516a4e0

Please sign in to comment.