Skip to content

Commit

Permalink
Merge branch 'main' into remove_full_fee_amount_and_solver_fee
Browse files Browse the repository at this point in the history
  • Loading branch information
sunce86 committed Jan 8, 2025
2 parents 26d1c3a + 672b30f commit b25cc5b
Show file tree
Hide file tree
Showing 44 changed files with 312 additions and 214 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ jobs:

test-forked-node:
# Do not run this job on forks since some secrets are required for it.
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
if: |
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) ||
(github.event_name == 'push' && github.ref == 'refs/heads/main')
timeout-minutes: 60
runs-on: ubuntu-latest
env:
Expand Down
51 changes: 14 additions & 37 deletions Cargo.lock

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

9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ clap = { version = "4.5.6", features = ["derive", "env"] }
dashmap = "6.1.0"
derivative = "2.2.0"
derive_more = { version = "1.0.0", features = ["full"] }
ethcontract = { version = "0.25.7", default-features = false, features = ["aws-kms"] }
ethcontract = { version = "0.25.8", default-features = false, features = ["aws-kms"] }
mimalloc = "0.1.43"
ethcontract-generate = { version = "0.25.7", default-features = false }
ethcontract-mock = { version = "0.25.7", default-features = false }
ethcontract-generate = { version = "0.25.8", default-features = false }
ethcontract-mock = { version = "0.25.8", default-features = false }
ethereum-types = "0.14.1"
flate2 = "1.0.30"
futures = "0.3.30"
Expand All @@ -28,11 +28,9 @@ humantime-serde = "1.1.1"
hyper = "0.14.29"
indexmap = "2.2.6"
itertools = "0.12.1"
lazy_static = "1.4.0"
maplit = "1.0.2"
mockall = "0.12.1"
num = "0.4.3"
once_cell = "1.19.0"
primitive-types = "0.12"
prometheus = "0.13.4"
prometheus-metric-storage = "0.5.0"
Expand All @@ -46,7 +44,6 @@ serde_with = "3.8.1"
sqlx = { version = "0.7", default-features = false, features = ["runtime-tokio", "tls-native-tls", "bigdecimal", "chrono", "postgres", "macros"] }
strum = { version = "0.26.2", features = ["derive"] }
tempfile = "3.10.1"
time = { version = "0.3.36", features = ["macros"] }
thiserror = "1.0.61"
toml = "0.8.14"
tokio = { version = "1.38.0", features = ["tracing"] }
Expand Down
4 changes: 2 additions & 2 deletions crates/autopilot/src/infra/solvers/dto/reveal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pub struct Request {
/// Unique ID of the solution (per driver competition), to reveal.
pub solution_id: u64,
/// Auction ID in which the specified solution ID is competing.
#[serde_as(as = "Option<serde_with::DisplayFromStr>")]
pub auction_id: Option<i64>,
#[serde_as(as = "serde_with::DisplayFromStr")]
pub auction_id: i64,
}

#[serde_as]
Expand Down
4 changes: 2 additions & 2 deletions crates/autopilot/src/infra/solvers/dto/settle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ pub struct Request {
/// The last block number in which the solution TX can be included
pub submission_deadline_latest_block: u64,
/// Auction ID in which the specified solution ID is competing.
#[serde_as(as = "Option<serde_with::DisplayFromStr>")]
pub auction_id: Option<i64>,
#[serde_as(as = "serde_with::DisplayFromStr")]
pub auction_id: i64,
}
2 changes: 1 addition & 1 deletion crates/autopilot/src/run_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ impl RunLoop {
let request = settle::Request {
solution_id,
submission_deadline_latest_block,
auction_id: None, // Requires 2-stage release for API-break change
auction_id,
};
driver
.settle(&request, self.config.max_settlement_transaction_wait)
Expand Down
2 changes: 1 addition & 1 deletion crates/autopilot/src/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl RunLoop {
let revealed = driver
.reveal(&reveal::Request {
solution_id,
auction_id: None, // Requires 2-stage release for API-break change
auction_id: request.id,
})
.await
.map_err(Error::Reveal)?;
Expand Down
52 changes: 52 additions & 0 deletions crates/database/src/trades.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,31 @@ AND t.log_index BETWEEN (SELECT * from previous_settlement) AND $2
.await
}

pub async fn token_first_trade_block(
ex: &mut PgConnection,
token: Address,
) -> Result<Option<i64>, sqlx::Error> {
const QUERY: &str = r#"
SELECT MIN(sub.block_number) AS earliest_block
FROM (
SELECT MIN(t.block_number) AS block_number
FROM trades t
JOIN orders o ON t.order_uid = o.uid
WHERE o.sell_token = $1 OR o.buy_token = $1
UNION ALL
SELECT MIN(t.block_number) AS block_number
FROM trades t
JOIN jit_orders j ON t.order_uid = j.uid
WHERE j.sell_token = $1 OR j.buy_token = $1
) AS sub
"#;

let (block_number,) = sqlx::query_as(QUERY).bind(token).fetch_one(ex).await?;
Ok(block_number)
}

#[cfg(test)]
mod tests {
use {
Expand Down Expand Up @@ -579,4 +604,31 @@ mod tests {
}]
);
}

#[tokio::test]
#[ignore]
async fn postgres_token_first_trade_block() {
let mut db = PgConnection::connect("postgresql://").await.unwrap();
let mut db = db.begin().await.unwrap();
crate::clear_DANGER_(&mut db).await.unwrap();

let token = Default::default();
assert_eq!(token_first_trade_block(&mut db, token).await.unwrap(), None);

let (owners, order_ids) = generate_owners_and_order_ids(2, 2).await;
let event_index_a = EventIndex {
block_number: 123,
log_index: 0,
};
let event_index_b = EventIndex {
block_number: 124,
log_index: 0,
};
add_order_and_trade(&mut db, owners[0], order_ids[0], event_index_a, None, None).await;
add_order_and_trade(&mut db, owners[1], order_ids[1], event_index_b, None, None).await;
assert_eq!(
token_first_trade_block(&mut db, token).await.unwrap(),
Some(123)
);
}
}
1 change: 0 additions & 1 deletion crates/driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ hex-literal = { workspace = true }
humantime = { workspace = true }
humantime-serde = { workspace = true }
hyper = { workspace = true }
lazy_static = { workspace = true }
indexmap = { workspace = true, features = ["serde"] }
itertools = { workspace = true }
mimalloc = { workspace = true }
Expand Down
22 changes: 7 additions & 15 deletions crates/driver/src/domain/competition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,17 +318,14 @@ impl Competition {
pub async fn reveal(
&self,
solution_id: u64,
auction_id: Option<i64>,
auction_id: auction::Id,
) -> Result<Revealed, Error> {
let settlement = self
.settlements
.lock()
.unwrap()
.iter()
.find(|s| {
s.solution().get() == solution_id
&& auction_id.is_none_or(|id| s.auction_id.0 == id)
})
.find(|s| s.solution().get() == solution_id && s.auction_id == auction_id)
.cloned()
.ok_or(Error::SolutionNotAvailable)?;
Ok(Revealed {
Expand All @@ -347,7 +344,7 @@ impl Competition {
/// [`Competition::solve`] to generate the solution.
pub async fn settle(
&self,
auction_id: Option<auction::Id>,
auction_id: auction::Id,
solution_id: u64,
submission_deadline: BlockNo,
) -> Result<Settled, Error> {
Expand Down Expand Up @@ -413,27 +410,22 @@ impl Competition {
tracing::error!(?err, "Failed to send /settle response");
}
}
.instrument(
tracing::info_span!("/settle", solver, auction_id = ?auction_id.map(|id| id.0)),
)
.instrument(tracing::info_span!("/settle", solver, %auction_id))
.await
}
}

async fn process_settle_request(
&self,
auction_id: Option<auction::Id>,
auction_id: auction::Id,
solution_id: u64,
submission_deadline: BlockNo,
) -> Result<Settled, Error> {
let settlement = {
let mut lock = self.settlements.lock().unwrap();
let index = lock
.iter()
.position(|s| {
s.solution().get() == solution_id
&& auction_id.is_none_or(|id| s.auction_id == id)
})
.position(|s| s.solution().get() == solution_id && s.auction_id == auction_id)
.ok_or(Error::SolutionNotAvailable)?;
// remove settlement to ensure we can't settle it twice by accident
lock.swap_remove_front(index)
Expand Down Expand Up @@ -537,7 +529,7 @@ fn merge(solutions: impl Iterator<Item = Solution>, auction: &Auction) -> Vec<So
}

struct SettleRequest {
auction_id: Option<auction::Id>,
auction_id: auction::Id,
solution_id: u64,
submission_deadline: BlockNo,
response_sender: oneshot::Sender<Result<Settled, Error>>,
Expand Down
Loading

0 comments on commit b25cc5b

Please sign in to comment.