Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove auction_transaction #2283

Merged
merged 26 commits into from
Jan 26, 2024
Merged
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
1 change: 0 additions & 1 deletion crates/autopilot/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use {

mod auction;
pub mod auction_prices;
pub mod auction_transaction;
pub mod competition;
pub mod ethflow_events;
mod events;
Expand Down
50 changes: 0 additions & 50 deletions crates/autopilot/src/database/auction_transaction.rs

This file was deleted.

48 changes: 15 additions & 33 deletions crates/autopilot/src/database/on_settlement_event_updater.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use {
anyhow::{Context, Result},
database::{byte_array::ByteArray, settlement_observations::Observation},
ethcontract::{H160, U256},
ethcontract::U256,
model::order::OrderUid,
number::conversions::u256_to_big_decimal,
sqlx::PgConnection,
Expand All @@ -13,20 +13,19 @@ pub type AuctionId = i64;

#[derive(Debug, Default, Clone)]
pub struct AuctionData {
pub auction_id: AuctionId,
pub gas_used: U256,
pub effective_gas_price: U256,
pub surplus: U256,
pub fee: U256,
pub order_executions: Vec<(OrderUid, ExecutedFee)>,
}

#[derive(Debug, Default, Clone)]
#[derive(Debug, Clone)]
pub struct SettlementUpdate {
pub block_number: i64,
pub log_index: i64,
pub tx_from: H160,
pub tx_nonce: i64,
pub auction_id: AuctionId,
/// Only set if the auction is for this environment.
pub auction_data: Option<AuctionData>,
}

Expand All @@ -41,31 +40,16 @@ impl super::Postgres {
.start_timer();

// update settlements
database::auction_transaction::insert_settlement_tx_info(
database::settlements::update_settlement_auction(
ex,
settlement_update.block_number,
settlement_update.log_index,
&ByteArray(settlement_update.tx_from.0),
settlement_update.tx_nonce,
settlement_update.auction_id,
)
.await
.context("insert_settlement_tx_info")?;

if let Some(auction_data) = settlement_update.auction_data {
// Link the `auction_id` to the settlement tx. This is needed for
// colocated solutions and is a no-op for centralized
// solutions.
let insert_succesful = database::auction_transaction::try_insert_auction_transaction(
ex,
auction_data.auction_id,
&ByteArray(settlement_update.tx_from.0),
settlement_update.tx_nonce,
)
.await
.context("failed to insert auction_transaction")?;

// in case of deep reindexing we might already have the observation, so just
// overwrite it
database::settlement_observations::upsert(
ex,
Observation {
Expand All @@ -80,17 +64,15 @@ impl super::Postgres {
.await
.context("insert_settlement_observations")?;

if insert_succesful {
for (order, executed_fee) in auction_data.order_executions {
database::order_execution::save(
ex,
&ByteArray(order.0),
auction_data.auction_id,
&u256_to_big_decimal(&executed_fee),
)
.await
.context("save_order_executions")?;
}
for (order, executed_fee) in auction_data.order_executions {
database::order_execution::save(
ex,
&ByteArray(order.0),
settlement_update.auction_id,
&u256_to_big_decimal(&executed_fee),
)
.await
.context("save_order_executions")?;
}
}
Ok(())
Expand Down
Loading
Loading