From d1458fae2d3130536d9076f1d6edb24c54535811 Mon Sep 17 00:00:00 2001 From: m-lord-renkse <160488334+m-lord-renkse@users.noreply.github.com> Date: Thu, 12 Sep 2024 14:57:11 +0200 Subject: [PATCH] Drop settlement_call_data table (#2968) # Description Since we don't need to store then uninternalised and internalised calldata, so the table `settlement_call_data` can be dropped. PR rebased on top of https://github.com/cowprotocol/services/pull/2964 as a continuation of it. # Changes - Drop the table `settlement_call_data` ## How to test 1. Regression tests ## Related Issues Fixes #2939 --------- Co-authored-by: Martin Magnus --- crates/database/src/lib.rs | 1 - crates/database/src/settlement_call_data.rs | 53 ------------------- database/README.md | 13 ----- .../sql/V071__drop_settlement_call_data.sql | 5 ++ 4 files changed, 5 insertions(+), 67 deletions(-) delete mode 100644 crates/database/src/settlement_call_data.rs create mode 100644 database/sql/V071__drop_settlement_call_data.sql diff --git a/crates/database/src/lib.rs b/crates/database/src/lib.rs index bf04fed11f..6eb40c08ac 100644 --- a/crates/database/src/lib.rs +++ b/crates/database/src/lib.rs @@ -15,7 +15,6 @@ pub mod order_execution; pub mod order_history; pub mod orders; pub mod quotes; -pub mod settlement_call_data; pub mod settlement_observations; pub mod settlement_scores; pub mod settlements; diff --git a/crates/database/src/settlement_call_data.rs b/crates/database/src/settlement_call_data.rs deleted file mode 100644 index 4b581c86aa..0000000000 --- a/crates/database/src/settlement_call_data.rs +++ /dev/null @@ -1,53 +0,0 @@ -use {crate::auction::AuctionId, sqlx::PgConnection}; - -#[derive(Debug, Clone, PartialEq, sqlx::FromRow)] -pub struct SettlementCallData { - pub auction_id: AuctionId, - pub call_data: Vec, - pub uninternalized_call_data: Vec, -} - -pub async fn insert(ex: &mut PgConnection, row: SettlementCallData) -> Result<(), sqlx::Error> { - const QUERY: &str = r#"INSERT INTO settlement_call_data (auction_id, call_data, uninternalized_call_data) VALUES ($1, $2, $3);"#; - sqlx::query(QUERY) - .bind(row.auction_id) - .bind(row.call_data.as_slice()) - .bind(row.uninternalized_call_data.as_slice()) - .execute(ex) - .await?; - Ok(()) -} - -pub async fn fetch( - ex: &mut PgConnection, - auction_id: AuctionId, -) -> Result, sqlx::Error> { - const QUERY: &str = r#"SELECT * FROM settlement_call_data WHERE auction_id = $1"#; - sqlx::query_as(QUERY) - .bind(auction_id) - .fetch_optional(ex) - .await -} - -#[cfg(test)] -mod tests { - use {super::*, sqlx::Connection}; - - #[tokio::test] - #[ignore] - async fn postgres_roundtrip() { - let mut db = PgConnection::connect("postgresql://").await.unwrap(); - let mut db = db.begin().await.unwrap(); - crate::clear_DANGER_(&mut db).await.unwrap(); - - let input = SettlementCallData { - auction_id: 1, - call_data: vec![2; 20], - uninternalized_call_data: vec![3; 20], - }; - insert(&mut db, input.clone()).await.unwrap(); - - let output = fetch(&mut db, 1).await.unwrap().unwrap(); - assert_eq!(input, output); - } -} diff --git a/database/README.md b/database/README.md index 20f6469c43..ae938215dc 100644 --- a/database/README.md +++ b/database/README.md @@ -343,19 +343,6 @@ Stores the best and second best solution quality (score) of every auction promis Indexes: - PRIMARY KEY: btree(`auction_id`) -### settlement\_call\_data - -Stores the final calldata and uninternalized calldata of the winning solution for each auction - - Column | Type | Nullable | Details -------------------------------|----------|----------|-------- - auction\_id | bigint | not null | id of the auction the winning transaction calldata belongs to - call_data | bytea | not null | final calldata as it appears on the blockchain - uninternalized\_call\_data | numeric | not null | uninternalized calldata, different from final calldata if solution contains interactions that can be internalized against gpv2 settlement contract internal buffers. - -Indexes: -- PRIMARY KEY: btree(`auction_id`) - ### settlements Stores data and metadata of [`Settlement`](https://github.com/cowprotocol/contracts/blob/main/src/contracts/GPv2Settlement.sol#L67-L68) events emitted from the settlement contract. diff --git a/database/sql/V071__drop_settlement_call_data.sql b/database/sql/V071__drop_settlement_call_data.sql new file mode 100644 index 0000000000..e6c89b0573 --- /dev/null +++ b/database/sql/V071__drop_settlement_call_data.sql @@ -0,0 +1,5 @@ +--- We don't need to store the uninternalised and internalised calldata, so this table can be dropped +--- This is because we don't need to show/return the calldata from the competition endpoints for safety reasons +--- The calldata can be recovered using any full node given the transaction hash which is later recovered when observing the settlement +--- See more: https://github.com/cowprotocol/services/issues/2942 +DROP TABLE settlement_call_data;