From fe99739879a2c3ffddda88f6071117bc12c97cc1 Mon Sep 17 00:00:00 2001 From: Dusan Stanivukovic Date: Thu, 19 Dec 2024 09:57:01 +0100 Subject: [PATCH] Remove "latest_settlement_block" from API (#3151) # Description Recently we introduced a new database table to store all auction objects -> `competition_auctions` table. Note that this table does not contain field `latest_settlement_block`. The reason is that this field is actually deductible from other data in the database -> it's even deductible from blockchain. For a given block X, you can always know what is the latest block before block X where the last settlement was settled. Moreover, `latest_settlement_block` is now only used internally in solvable orders cache component of autopilot, so it's not actually a core autopilot information. This change opens the door to unify `auction` and `competition_auctions` table with final goal of removing `auction` table completely. Removes tech debt. # Changes - [ ] Remove `latest_settlement_block` field from api and autopilot ## How to test All tests passing. If you are worried about a transition period, removing a field shouldn't be problematic for deserializing old object containing `latest_settlement_block`. The only concern is that solvers needs to adjust their deserialize logic so it doesn't break. Will be notified in advance once approvals are collected. --- crates/autopilot/src/domain/auction/mod.rs | 3 --- crates/autopilot/src/infra/persistence/dto/auction.rs | 3 --- crates/autopilot/src/run_loop.rs | 1 - crates/autopilot/src/solvable_orders.rs | 1 - crates/model/src/auction.rs | 11 ----------- crates/model/src/lib.rs | 7 ------- crates/orderbook/openapi.yml | 8 -------- crates/orderbook/src/database/orders.rs | 5 ----- crates/orderbook/src/dto/auction.rs | 1 - 9 files changed, 40 deletions(-) diff --git a/crates/autopilot/src/domain/auction/mod.rs b/crates/autopilot/src/domain/auction/mod.rs index 3b0bd587c3..8906bad418 100644 --- a/crates/autopilot/src/domain/auction/mod.rs +++ b/crates/autopilot/src/domain/auction/mod.rs @@ -13,7 +13,6 @@ pub mod order; #[derive(Clone, Debug, PartialEq)] pub struct RawAuctionData { pub block: u64, - pub latest_settlement_block: u64, pub orders: Vec, pub prices: Prices, pub surplus_capturing_jit_order_owners: Vec, @@ -25,7 +24,6 @@ pub type Id = i64; pub struct Auction { pub id: Id, pub block: u64, - pub latest_settlement_block: u64, pub orders: Vec, pub prices: Prices, pub surplus_capturing_jit_order_owners: Vec, @@ -34,7 +32,6 @@ pub struct Auction { impl PartialEq for Auction { fn eq(&self, other: &Self) -> bool { self.block == other.block - && self.latest_settlement_block == other.latest_settlement_block && self.orders == other.orders && self.prices == other.prices && self.surplus_capturing_jit_order_owners == other.surplus_capturing_jit_order_owners diff --git a/crates/autopilot/src/infra/persistence/dto/auction.rs b/crates/autopilot/src/infra/persistence/dto/auction.rs index 0ed2f3588a..3c576a74fc 100644 --- a/crates/autopilot/src/infra/persistence/dto/auction.rs +++ b/crates/autopilot/src/infra/persistence/dto/auction.rs @@ -14,7 +14,6 @@ use { pub fn from_domain(auction: domain::RawAuctionData) -> RawAuctionData { RawAuctionData { block: auction.block, - latest_settlement_block: auction.latest_settlement_block, orders: auction .orders .into_iter() @@ -38,7 +37,6 @@ pub fn from_domain(auction: domain::RawAuctionData) -> RawAuctionData { #[serde(rename_all = "camelCase")] pub struct RawAuctionData { pub block: u64, - pub latest_settlement_block: u64, pub orders: Vec, #[serde_as(as = "BTreeMap<_, HexOrDecimalU256>")] pub prices: BTreeMap, @@ -62,7 +60,6 @@ impl Auction { Ok(domain::Auction { id: self.id, block: self.auction.block, - latest_settlement_block: self.auction.latest_settlement_block, orders: self .auction .orders diff --git a/crates/autopilot/src/run_loop.rs b/crates/autopilot/src/run_loop.rs index e86692ff4e..99b35f3a09 100644 --- a/crates/autopilot/src/run_loop.rs +++ b/crates/autopilot/src/run_loop.rs @@ -214,7 +214,6 @@ impl RunLoop { Some(domain::Auction { id, block: auction.block, - latest_settlement_block: auction.latest_settlement_block, orders: auction.orders, prices: auction.prices, surplus_capturing_jit_order_owners: auction.surplus_capturing_jit_order_owners, diff --git a/crates/autopilot/src/solvable_orders.rs b/crates/autopilot/src/solvable_orders.rs index 9c23b39868..25155833cd 100644 --- a/crates/autopilot/src/solvable_orders.rs +++ b/crates/autopilot/src/solvable_orders.rs @@ -267,7 +267,6 @@ impl SolvableOrdersCache { .collect::>(); let auction = domain::RawAuctionData { block, - latest_settlement_block: db_solvable_orders.latest_settlement_block, orders: orders .into_iter() .map(|order| { diff --git a/crates/model/src/auction.rs b/crates/model/src/auction.rs index 94cd04aa44..f0dd8a434a 100644 --- a/crates/model/src/auction.rs +++ b/crates/model/src/auction.rs @@ -34,15 +34,6 @@ pub struct Auction { /// The block number for the auction. Orders and prices are guaranteed to be /// valid on this block. pub block: u64, - - /// The latest block on which a settlement has been processed. This field is - /// used to tell which orders are still in-flight. See - /// [`InFlightOrders`]. - /// - /// Note that under certain conditions it is possible for a settlement to - /// have been mined as part of [`block`] but not have yet been processed. - pub latest_settlement_block: u64, - /// The solvable orders included in the auction. pub orders: Vec, @@ -72,7 +63,6 @@ mod tests { }; let auction = Auction { block: 42, - latest_settlement_block: 40, orders: vec![order(1), order(2)], prices: btreemap! { H160([2; 20]) => U256::from(2), @@ -86,7 +76,6 @@ mod tests { json!({ "id": 0, "block": 42, - "latestSettlementBlock": 40, "orders": [ order(1), order(2), diff --git a/crates/model/src/lib.rs b/crates/model/src/lib.rs index 23a13d7729..044bb67bf5 100644 --- a/crates/model/src/lib.rs +++ b/crates/model/src/lib.rs @@ -139,13 +139,6 @@ impl DomainSeparator { } } -#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)] -#[serde(rename_all = "camelCase")] -pub struct SolvableOrders { - pub orders: Vec, - pub latest_settlement_block: u64, -} - #[cfg(test)] mod tests { use { diff --git a/crates/orderbook/openapi.yml b/crates/orderbook/openapi.yml index d470a9f24b..18e48c405f 100644 --- a/crates/orderbook/openapi.yml +++ b/crates/orderbook/openapi.yml @@ -1103,14 +1103,6 @@ components: The block number for the auction. Orders and prices are guaranteed to be valid on this block. Proposed settlements should be valid for this block as well. - latestSettlementBlock: - type: integer - description: > - The latest block on which a settlement has been processed. - - **NOTE**: Under certain conditions it is possible for a settlement - to have been mined as part of `block` but not have yet been - processed. orders: type: array items: diff --git a/crates/orderbook/src/database/orders.rs b/crates/orderbook/src/database/orders.rs index a21884f9c1..64bde48916 100644 --- a/crates/orderbook/src/database/orders.rs +++ b/crates/orderbook/src/database/orders.rs @@ -80,11 +80,6 @@ pub trait OrderStoring: Send + Sync { async fn single_order_with_quote(&self, uid: &OrderUid) -> Result>; } -pub struct SolvableOrders { - pub orders: Vec, - pub latest_settlement_block: u64, -} - pub struct OrderWithQuote { pub order: Order, pub quote: Option, diff --git a/crates/orderbook/src/dto/auction.rs b/crates/orderbook/src/dto/auction.rs index a132bbf747..fe3d237fbf 100644 --- a/crates/orderbook/src/dto/auction.rs +++ b/crates/orderbook/src/dto/auction.rs @@ -13,7 +13,6 @@ use { #[serde(rename_all = "camelCase")] pub struct Auction { pub block: u64, - pub latest_settlement_block: u64, pub orders: Vec, #[serde_as(as = "BTreeMap<_, HexOrDecimalU256>")] pub prices: BTreeMap,