Skip to content

Commit

Permalink
Remove "latest_settlement_block" from API (#3151)
Browse files Browse the repository at this point in the history
# 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
<!-- List of detailed changes (how the change is accomplished) -->

- [ ] 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.

<!--
## Related Issues

Fixes #
-->
  • Loading branch information
sunce86 authored Dec 19, 2024
1 parent bf213b9 commit fe99739
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 40 deletions.
3 changes: 0 additions & 3 deletions crates/autopilot/src/domain/auction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Order>,
pub prices: Prices,
pub surplus_capturing_jit_order_owners: Vec<eth::Address>,
Expand All @@ -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<Order>,
pub prices: Prices,
pub surplus_capturing_jit_order_owners: Vec<eth::Address>,
Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions crates/autopilot/src/infra/persistence/dto/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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<Order>,
#[serde_as(as = "BTreeMap<_, HexOrDecimalU256>")]
pub prices: BTreeMap<H160, U256>,
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion crates/autopilot/src/run_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion crates/autopilot/src/solvable_orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ impl SolvableOrdersCache {
.collect::<Vec<_>>();
let auction = domain::RawAuctionData {
block,
latest_settlement_block: db_solvable_orders.latest_settlement_block,
orders: orders
.into_iter()
.map(|order| {
Expand Down
11 changes: 0 additions & 11 deletions crates/model/src/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Order>,

Expand Down Expand Up @@ -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),
Expand All @@ -86,7 +76,6 @@ mod tests {
json!({
"id": 0,
"block": 42,
"latestSettlementBlock": 40,
"orders": [
order(1),
order(2),
Expand Down
7 changes: 0 additions & 7 deletions crates/model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,6 @@ impl DomainSeparator {
}
}

#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SolvableOrders {
pub orders: Vec<order::Order>,
pub latest_settlement_block: u64,
}

#[cfg(test)]
mod tests {
use {
Expand Down
8 changes: 0 additions & 8 deletions crates/orderbook/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 0 additions & 5 deletions crates/orderbook/src/database/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ pub trait OrderStoring: Send + Sync {
async fn single_order_with_quote(&self, uid: &OrderUid) -> Result<Option<OrderWithQuote>>;
}

pub struct SolvableOrders {
pub orders: Vec<Order>,
pub latest_settlement_block: u64,
}

pub struct OrderWithQuote {
pub order: Order,
pub quote: Option<orders::Quote>,
Expand Down
1 change: 0 additions & 1 deletion crates/orderbook/src/dto/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use {
#[serde(rename_all = "camelCase")]
pub struct Auction {
pub block: u64,
pub latest_settlement_block: u64,
pub orders: Vec<Order>,
#[serde_as(as = "BTreeMap<_, HexOrDecimalU256>")]
pub prices: BTreeMap<H160, U256>,
Expand Down

0 comments on commit fe99739

Please sign in to comment.