Skip to content

Commit 0af1ae7

Browse files
squadgazzzxdecentralix
authored andcommitted
Migrate from auction_participans to proposed_solutions table (cowprotocol#3766)
# Description The `auction_participans` table has become obsolete, since the same data is now stored in the `proposed_solutions`. This PR migrates usage to the latter table. The migration script will be a part of cowprotocol#3753, since this is a breaking change, which requires gradual deployment to avoid panics when running 2 auctions in parallel.
1 parent 572b607 commit 0af1ae7

File tree

7 files changed

+34
-106
lines changed

7 files changed

+34
-106
lines changed

crates/autopilot/src/database/competition.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use {
44
database::{
55
Address,
66
auction::AuctionId,
7-
auction_participants::Participant,
87
auction_prices::AuctionPrice,
98
byte_array::ByteArray,
109
surplus_capturing_jit_order_owners,
@@ -61,21 +60,6 @@ impl super::Postgres {
6160
.await
6261
.context("reference_scores::insert")?;
6362

64-
database::auction_participants::insert(
65-
&mut ex,
66-
competition
67-
.participants
68-
.into_iter()
69-
.map(|p| Participant {
70-
auction_id: competition.auction_id,
71-
participant: ByteArray(p.0),
72-
})
73-
.collect::<Vec<_>>()
74-
.as_slice(),
75-
)
76-
.await
77-
.context("auction_participants::insert")?;
78-
7963
database::auction_prices::insert(
8064
&mut ex,
8165
competition

crates/database/src/auction_participants.rs

Lines changed: 0 additions & 72 deletions
This file was deleted.

crates/database/src/auction_prices.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! This table is deprecated, since it contains duplicated data in the
2+
//! `competition_auctions` table. But it can't currently be removed, since the
3+
//! solver team is still using it.
14
use {
25
crate::{Address, PgTransaction, auction::AuctionId},
36
bigdecimal::BigDecimal,

crates/database/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
pub mod app_data;
22
pub mod auction;
3-
pub mod auction_participants;
43
pub mod auction_prices;
54
pub mod byte_array;
65
pub mod ethflow_orders;
@@ -75,7 +74,6 @@ pub const TABLES: &[&str] = &[
7574
/// The names of potentially big volume tables we use in the db.
7675
pub const LARGE_TABLES: &[&str] = &[
7776
"auction_prices",
78-
"auction_participants",
7977
"competition_auctions",
8078
"fee_policies",
8179
"orders",

crates/database/src/solver_competition_v2.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,26 @@ pub async fn load_by_id(
188188
}))
189189
}
190190

191+
/// Participant of a solver competition for a given auction.
192+
#[derive(Debug, Clone, PartialEq, sqlx::FromRow)]
193+
pub struct AuctionParticipant {
194+
pub auction_id: AuctionId,
195+
pub participant: Address,
196+
}
197+
198+
pub async fn fetch_auction_participants(
199+
ex: &mut PgConnection,
200+
auction_id: AuctionId,
201+
) -> Result<Vec<AuctionParticipant>, sqlx::Error> {
202+
const QUERY: &str = r#"
203+
SELECT DISTINCT ps.solver AS participant, ps.auction_id
204+
FROM proposed_solutions ps
205+
WHERE ps.auction_id = $1
206+
"#;
207+
208+
sqlx::query_as(QUERY).bind(auction_id).fetch_all(ex).await
209+
}
210+
191211
/// Identifies solvers that have consistently failed to settle solutions in
192212
/// recent N auctions.
193213
///
@@ -1213,5 +1233,11 @@ mod tests {
12131233
assert_eq!(solver_competition.reference_scores.len(), 1);
12141234
assert_eq!(solver_competition.solutions.len(), 1);
12151235
assert_eq!(solver_competition.solutions.first().unwrap().uid, 0);
1236+
1237+
let auction_participants = fetch_auction_participants(&mut db, auction_id)
1238+
.await
1239+
.unwrap();
1240+
assert_eq!(auction_participants.len(), 1);
1241+
assert_eq!(auction_participants[0].participant, solutions[0].solver);
12161242
}
12171243
}

crates/e2e/tests/e2e/database.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct AuctionTransaction {
4545
#[derive(Clone, Debug)]
4646
pub struct Cip20Data {
4747
pub txs: Vec<AuctionTransaction>,
48-
pub participants: Vec<database::auction_participants::Participant>,
48+
pub participants: Vec<database::solver_competition_v2::AuctionParticipant>,
4949
pub prices: Vec<database::auction_prices::AuctionPrice>,
5050
pub reference_scores: Vec<database::reference_scores::Score>,
5151
pub competition: serde_json::Value,
@@ -72,9 +72,10 @@ SELECT * FROM settlements WHERE auction_id = $1";
7272
.await
7373
.ok()?;
7474

75-
let participants = database::auction_participants::fetch(&mut db, auction_id)
76-
.await
77-
.unwrap();
75+
let participants =
76+
database::solver_competition_v2::fetch_auction_participants(&mut db, auction_id)
77+
.await
78+
.unwrap();
7879
let prices = database::auction_prices::fetch(&mut db, auction_id)
7980
.await
8081
.unwrap();

database/README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,6 @@ Column | Type | Nullable | Details
2323
Indexes:
2424
- "app\_data\_pkey" PRIMARY KEY, btree (`contract_app_data`)
2525

26-
### auction\_participants
27-
28-
This table is used for [CIP-20](https://snapshot.org/#/cow.eth/proposal/0x2d3f9bd1ea72dca84b03e97dda3efc1f4a42a772c54bd2037e8b62e7d09a491f). It stores which solvers (identified by ethereum address) participated in which auctions (identified by auction id). CIP-20 specifies that "solver teams which consistently provide solutions" get rewarded.
29-
30-
Column | Type | Nullable | Details
31-
--------------|--------|----------|--------
32-
auction\_id | bigint | not null | id of the auction
33-
participant | bytea | not null | solver that submitted a **valid** solution for the auction
34-
35-
Indexes:
36-
- PRIMARY KEY: btree(`auction_id`, `participant`)
37-
3826
### auction\_prices
3927

4028
Stores the native price of a token in a given auction. Used for computations related to CIP-20.

0 commit comments

Comments
 (0)