Skip to content
Draft
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
25 changes: 25 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry --mount=type=cache,targe
cp target/release/driver / && \
cp target/release/orderbook / && \
cp target/release/refunder / && \
cp target/release/solvers /
cp target/release/solvers / && \
cp target/release/euler-solver /

# Create an intermediate image to extract the binaries
FROM docker.io/debian:bookworm-slim AS intermediate
Expand Down Expand Up @@ -52,6 +53,10 @@ FROM intermediate AS solvers
COPY --from=cargo-build /solvers /usr/local/bin/solvers
ENTRYPOINT [ "solvers" ]

FROM intermediate AS euler-solver
COPY --from=cargo-build /euler-solver /usr/local/bin/euler-solver
ENTRYPOINT [ "euler-solver" ]

# Extract Binary
FROM intermediate
RUN apt-get update && \
Expand All @@ -68,6 +73,7 @@ COPY --from=cargo-build /driver /usr/local/bin/driver
COPY --from=cargo-build /orderbook /usr/local/bin/orderbook
COPY --from=cargo-build /refunder /usr/local/bin/refunder
COPY --from=cargo-build /solvers /usr/local/bin/solvers
COPY --from=cargo-build /euler-solver /usr/local/bin/euler-solver
COPY ./entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

Expand Down
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test-e2e-local: (test-e2e "local_node")
# Run End-to-end tests on forked node
#
# FORK_URL_MAINNET and FORK_URL_GNOSIS env variables have to be provided.
test-e2e-forked: (test-e2e "forked_node")
test-e2e-forked: (test-e2e "forked_node_trace_based")

# Run End-to-end tests with custom filters
test-e2e *filters:
Expand Down
7 changes: 5 additions & 2 deletions configs/local/driver.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ app-data-fetching-enabled = true
orderbook-url = "http://orderbook"
tx-gas-limit = "45000000"

[contracts]
gp-v2-settlement = "0x99B14b6C733a8E2196d5C561e6B5F6f083F4a7f9"

[[solver]]
name = "baseline" # Arbitrary name given to this solver, must be unique
endpoint = "http://baseline"
name = "euler-solver" # Euler minimalist solver
endpoint = "http://euler-solver"
absolute-slippage = "40000000000000000" # Denominated in wei, optional
relative-slippage = "0.1" # Percentage in the [0, 1] range
account = "0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6" # Known test private key
Expand Down
20 changes: 8 additions & 12 deletions crates/autopilot/src/run_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@ use {
crate::{
database::competition::Competition,
domain::{
self,
OrderUid,
self, OrderUid,
auction::Id,
competition::{
self,
Solution,
SolutionError,
SolverParticipationGuard,
Unranked,
self, Solution, SolutionError, SolverParticipationGuard, Unranked,
winner_selection::{self, Ranking},
},
eth::{self, TxId},
Expand All @@ -36,11 +31,7 @@ use {
futures::{FutureExt, TryFutureExt},
itertools::Itertools,
model::solver_competition::{
CompetitionAuction,
Order,
Score,
SolverCompetitionDB,
SolverSettlement,
CompetitionAuction, Order, Score, SolverCompetitionDB, SolverSettlement,
},
num::ToPrimitive,
primitive_types::H256,
Expand Down Expand Up @@ -128,6 +119,7 @@ impl RunLoop {
}

pub async fn run_forever(self, mut control: ShutdownController) {
println!("RUNNING FOREVER!");
Maintenance::spawn_cow_amm_indexing_task(
self.maintenance.clone(),
self.eth.current_block().clone(),
Expand All @@ -150,6 +142,9 @@ impl RunLoop {
let mut leader_lock_tracker = LeaderLockTracker::new(leader);

while !control.should_shutdown() {
// this loop should ideally run once per block (if a new order comes in, perhaps we want to initiate the loop late?)
ethrpc::block_stream::next_block(self_arc.eth.current_block()).await;

leader_lock_tracker.try_acquire().await;

let start_block = self_arc
Expand Down Expand Up @@ -182,6 +177,7 @@ impl RunLoop {
}

async fn update_caches(&self, prev_block: &mut Option<H256>, is_leader: bool) -> BlockInfo {
tracing::debug!("updating caches");
let current_block = *self.eth.current_block().borrow();
let time_since_last_block = current_block.observed_at.elapsed();
let auction_block = if time_since_last_block > self.config.max_run_loop_delay {
Expand Down
8 changes: 5 additions & 3 deletions crates/autopilot/src/solvable_orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,13 @@ impl SolvableOrdersCache {
surplus_capturing_jit_order_owners,
};

tracing::debug!(%block, valid_orders = db_solvable_orders.orders.len(), "updating current auction cache");

*self.cache.lock().await = Some(Inner {
auction,
solvable_orders: db_solvable_orders,
});

tracing::debug!(%block, "updated current auction cache");
self.metrics
.auction_update_total_time
.observe(start.elapsed().as_secs_f64());
Expand Down Expand Up @@ -553,6 +554,8 @@ fn orders_with_balance(
// Prefer newer orders over older ones.
orders.sort_by_key(|order| std::cmp::Reverse(order.metadata.creation_date));
orders.retain(|order| {
// TODO: if there is a wrapper it should be treated to 1271 order filter below
return true;
if disable_1271_order_balance_filter && matches!(order.signature, Signature::Eip1271(_)) {
return true;
}
Expand Down Expand Up @@ -914,8 +917,7 @@ mod tests {
shared::{
bad_token::list_based::ListBasedDetector,
price_estimation::{
HEALTHY_PRICE_ESTIMATION_TIME,
PriceEstimationError,
HEALTHY_PRICE_ESTIMATION_TIME, PriceEstimationError,
native::MockNativePriceEstimating,
},
signature_validator::{MockSignatureValidating, SignatureValidationError},
Expand Down
2 changes: 1 addition & 1 deletion crates/contracts/solidity/Trader.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ contract Trader layout at 0x02565dba7d68dcbed629110024b7b5e785bfc1a484602045eea5
// The trader does not have sufficient sell token balance, and the
// piggy bank pre-fund failed, as balance overrides are not available.
// Revert with a helpful message.
revert("trader does not have enough sell token");
revert("spardose could not fund trader with sell token; balance override failed");
}
}
}
Expand Down
25 changes: 16 additions & 9 deletions crates/driver/src/domain/competition/bad_tokens/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ impl Detector {
let now = Instant::now();

// reuse the original allocation
let supported_orders = std::mem::take(&mut auction.orders);
let mut token_quality_checks = FuturesUnordered::new();
let mut removed_uids = Vec::new();

let mut supported_orders: Vec<_> = supported_orders
let mut supported_orders: Vec<_> = auction
.orders
.clone()
.into_iter()
.filter_map(|order| {
let sell = self.get_token_quality(order.sell.token, now);
Expand All @@ -78,10 +78,7 @@ impl Detector {
// both tokens supported => keep order
(Quality::Supported, Quality::Supported) => Some(order),
// at least 1 token unsupported => drop order
(Quality::Unsupported, _) | (_, Quality::Unsupported) => {
removed_uids.push(order.uid);
None
}
(Quality::Unsupported, _) | (_, Quality::Unsupported) => None,
// sell token quality is unknown => keep order if token is supported
(Quality::Unknown, _) => {
let Some(detector) = &self.simulation_detector else {
Expand All @@ -105,11 +102,21 @@ impl Detector {
while let Some((order, quality)) = token_quality_checks.next().await {
if quality == Quality::Supported {
supported_orders.push(order);
} else {
removed_uids.push(order.uid);
}
}

// todo: not super efficient
let removed_uids = auction
.orders
.iter()
.filter(|order| {
!supported_orders
.iter()
.any(|supported_order| supported_order.uid == order.uid)
})
.map(|order| order.uid)
.collect::<Vec<_>>();

auction.orders = supported_orders;
if !removed_uids.is_empty() {
tracing::debug!(orders = ?removed_uids, "ignored orders with unsupported tokens");
Expand Down
14 changes: 12 additions & 2 deletions crates/driver/src/domain/competition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use {
time::DeadlineExceeded,
},
infra::{
self,
Simulator,
self, Simulator,
blockchain::Ethereum,
notify,
observe::{self, metrics},
Expand Down Expand Up @@ -127,6 +126,7 @@ impl Competition {
Error::MalformedRequest
})?;
let mut auction = Arc::unwrap_or_clone(tasks.auction.await);
tracing::debug!("retrieved auction orders count: {}", auction.orders.len());

let settlement_contract = self.eth.contracts().settlement().address();
let solver_address = self.solver.account().address();
Expand All @@ -152,6 +152,8 @@ impl Competition {
let (auction, balances, app_data) =
tokio::join!(sort_orders_future, tasks.balances, tasks.app_data);

tracing::debug!("auction orders count: {}", auction.orders.len());

let auction = Self::run_blocking_with_timer("update_orders", move || {
// Same as before with sort_orders, we use spawn_blocking() because a lot of CPU
// bound computations are happening and we want to avoid blocking
Expand All @@ -166,6 +168,11 @@ impl Competition {
})
.await;

tracing::debug!(
"auction orders count (post update): {}",
auction.orders.len()
);

// We can run bad token filtering and liquidity fetching in parallel
let (liquidity, auction) = tokio::join!(
async {
Expand Down Expand Up @@ -446,6 +453,9 @@ impl Competition {
return true;
}

// TODO: figure out some better way to do this. The wrappers kind of break the whole case of checking balances (like we do in like 5 other places)
return true;

// Update order app data if it was fetched.
if let Some(fetched_app_data) = app_data.get(&order.app_data.hash()) {
order.app_data = fetched_app_data.clone().into();
Expand Down
10 changes: 10 additions & 0 deletions crates/driver/src/domain/competition/solution/trade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ impl Fulfillment {
.checked_add(fee.0)
.ok_or(error::Trade::InvalidExecutedAmount)?,
);
println!(
"executed_with_fee: {}, matched target: {}",
executed_with_fee.0,
order.target().0
);
match order.partial {
order::Partial::Yes { available } => executed_with_fee <= available,
order::Partial::No => executed_with_fee == order.target(),
Expand All @@ -174,6 +179,11 @@ impl Fulfillment {
Fee::Dynamic(_) => order.solver_determines_fee(),
};

println!(
"the end! fee valid: {}, execution valid: {}",
valid_fee, valid_execution
);

if valid_execution && valid_fee {
Ok(Self {
order,
Expand Down
6 changes: 2 additions & 4 deletions crates/driver/src/infra/observe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use {
domain::{
Liquidity,
competition::{
self,
Solution,
Solved,
self, Solution, Solved,
solution::{self, Settlement},
},
eth::{self, Gas},
Expand Down Expand Up @@ -443,7 +441,7 @@ pub fn order_excluded_from_auction(
order: &competition::Order,
reason: OrderExcludedFromAuctionReason,
) {
tracing::trace!(uid=?order.uid, ?reason, "order excluded from auction");
tracing::debug!(uid=?order.uid, ?reason, "order excluded from auction");
}

/// Observe that a settlement was simulated
Expand Down
Loading
Loading