From 11a8e754aeb035c06c48bf818ed6b31c74e8e1c1 Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 21 Feb 2025 13:54:12 +0000 Subject: [PATCH 1/5] Do not store start/end blocks --- crates/autopilot/src/domain/settlement/mod.rs | 2 -- crates/autopilot/src/infra/persistence/mod.rs | 4 --- crates/autopilot/src/run_loop.rs | 3 --- crates/database/src/settlement_executions.rs | 25 ++----------------- database/README.md | 2 -- ...80__create_settlement_executions_table.sql | 2 -- 6 files changed, 2 insertions(+), 36 deletions(-) diff --git a/crates/autopilot/src/domain/settlement/mod.rs b/crates/autopilot/src/domain/settlement/mod.rs index b444638e4e..efc8562f3a 100644 --- a/crates/autopilot/src/domain/settlement/mod.rs +++ b/crates/autopilot/src/domain/settlement/mod.rs @@ -217,14 +217,12 @@ pub enum Execution { auction_id: AuctionId, solver: eth::Address, start_timestamp: DateTime, - start_block: u64, deadline_block: u64, }, Ended { auction_id: AuctionId, solver: eth::Address, end_timestamp: DateTime, - end_block: u64, outcome: String, }, } diff --git a/crates/autopilot/src/infra/persistence/mod.rs b/crates/autopilot/src/infra/persistence/mod.rs index e9f2ca5bd8..60a05e1e88 100644 --- a/crates/autopilot/src/infra/persistence/mod.rs +++ b/crates/autopilot/src/infra/persistence/mod.rs @@ -808,7 +808,6 @@ impl Persistence { auction_id, solver, start_timestamp, - start_block, deadline_block, } => { let _timer = Metrics::get() @@ -821,7 +820,6 @@ impl Persistence { auction_id, ByteArray(solver.0 .0), start_timestamp, - start_block.try_into().context("start block overflow")?, deadline_block .try_into() .context("deadline block overflow")?, @@ -832,7 +830,6 @@ impl Persistence { auction_id, solver, end_timestamp, - end_block, outcome, } => { let _timer = Metrics::get() @@ -845,7 +842,6 @@ impl Persistence { auction_id, ByteArray(solver.0 .0), end_timestamp, - end_block.try_into().context("end block overflow")?, outcome, ) .await? diff --git a/crates/autopilot/src/run_loop.rs b/crates/autopilot/src/run_loop.rs index d227e771cd..a5c98aaa9d 100644 --- a/crates/autopilot/src/run_loop.rs +++ b/crates/autopilot/src/run_loop.rs @@ -777,7 +777,6 @@ impl RunLoop { auction_id, solver, start_timestamp: chrono::Utc::now(), - start_block: current_block, deadline_block: submission_deadline_latest_block, }; let settle_event_store_fut = self @@ -838,7 +837,6 @@ impl RunLoop { auction_id: i64, result: &Result, ) { - let current_block = self.eth.current_block().borrow().number; let persistence = self.persistence.clone(); let outcome = match result { Ok(_) => "success".to_string(), @@ -851,7 +849,6 @@ impl RunLoop { auction_id, solver, end_timestamp: chrono::Utc::now(), - end_block: current_block, outcome, }; if let Err(err) = persistence diff --git a/crates/database/src/settlement_executions.rs b/crates/database/src/settlement_executions.rs index fc51551065..00b9754a2e 100644 --- a/crates/database/src/settlement_executions.rs +++ b/crates/database/src/settlement_executions.rs @@ -9,11 +9,10 @@ pub async fn insert( auction_id: AuctionId, solver: Address, start_timestamp: DateTime, - start_block: i64, deadline_block: i64, ) -> Result<(), sqlx::Error> { const QUERY: &str = r#" -INSERT INTO settlement_executions (auction_id, solver, start_timestamp, start_block, deadline_block) +INSERT INTO settlement_executions (auction_id, solver, start_timestamp, deadline_block) VALUES ($1, $2, $3, $4, $5) ;"#; @@ -21,7 +20,6 @@ VALUES ($1, $2, $3, $4, $5) .bind(auction_id) .bind(solver) .bind(start_timestamp) - .bind(start_block) .bind(deadline_block) .execute(ex) .await?; @@ -34,12 +32,11 @@ pub async fn update( auction_id: AuctionId, solver: Address, end_timestamp: DateTime, - end_block: i64, outcome: String, ) -> Result<(), sqlx::Error> { const QUERY: &str = r#" UPDATE settlement_executions -SET end_timestamp = $3, end_block = $4, outcome = $5 +SET end_timestamp = $3, outcome = $5 WHERE auction_id = $1 AND solver = $2 ;"#; @@ -47,7 +44,6 @@ WHERE auction_id = $1 AND solver = $2 .bind(auction_id) .bind(solver) .bind(end_timestamp) - .bind(end_block) .bind(outcome) .execute(ex) .await?; @@ -75,7 +71,6 @@ mod tests { let solver_a = ByteArray([1u8; 20]); let solver_b = ByteArray([2u8; 20]); let start_timestamp = now_truncated_to_microseconds(); - let start_block = 1; let deadline_block = 10; insert( @@ -83,7 +78,6 @@ mod tests { auction_id, solver_a, start_timestamp, - start_block, deadline_block, ) .await @@ -93,7 +87,6 @@ mod tests { auction_id, solver_b, start_timestamp, - start_block, deadline_block, ) .await @@ -106,8 +99,6 @@ mod tests { solver: solver_a, start_timestamp, end_timestamp: None, - start_block, - end_block: None, deadline_block, outcome: None, }; @@ -116,8 +107,6 @@ mod tests { solver: solver_b, start_timestamp, end_timestamp: None, - start_block, - end_block: None, deadline_block, outcome: None, }; @@ -125,28 +114,24 @@ mod tests { assert!(output.contains(&expected_b)); let end_timestamp_a = now_truncated_to_microseconds(); - let end_block_a = 8; let outcome_a = "success".to_string(); update( &mut db, auction_id, solver_a, end_timestamp_a, - end_block_a, outcome_a.clone(), ) .await .unwrap(); let end_timestamp_b = now_truncated_to_microseconds(); - let end_block_b = 10; let outcome_b = "failure".to_string(); update( &mut db, auction_id, solver_b, end_timestamp_b, - end_block_b, outcome_b.clone(), ) .await @@ -159,8 +144,6 @@ mod tests { solver: solver_a, start_timestamp, end_timestamp: Some(end_timestamp_a), - start_block, - end_block: Some(end_block_a), deadline_block, outcome: Some(outcome_a), }; @@ -169,8 +152,6 @@ mod tests { solver: solver_b, start_timestamp, end_timestamp: Some(end_timestamp_b), - start_block, - end_block: Some(end_block_b), deadline_block, outcome: Some(outcome_b), }; @@ -184,8 +165,6 @@ mod tests { pub solver: Address, pub start_timestamp: DateTime, pub end_timestamp: Option>, - pub start_block: i64, - pub end_block: Option, pub deadline_block: i64, pub outcome: Option, } diff --git a/database/README.md b/database/README.md index fafc4f070a..2a9908f2f8 100644 --- a/database/README.md +++ b/database/README.md @@ -461,8 +461,6 @@ auction\_id | bigint | not null | id of the auction the settlement exe solver | bytea | not null | public address of the winning solver that executed the settlement start\_timestamp | timestamptz | not null | when the settlement execution started end\_timestamp | timestamptz | nullable | when the settlement execution ended -start\_block | bigint | not null | block in which the settlement execution started -end\_block | bigint | nullable | block in which the settlement execution ended deadline\_block | bigint | not null | latest block at which the settlement execution should have ended outcome | text | nullable | outcome of the settlement execution diff --git a/database/sql/V080__create_settlement_executions_table.sql b/database/sql/V080__create_settlement_executions_table.sql index f04a6606f1..1c7d8a45f4 100644 --- a/database/sql/V080__create_settlement_executions_table.sql +++ b/database/sql/V080__create_settlement_executions_table.sql @@ -5,8 +5,6 @@ CREATE TABLE settlement_executions solver bytea NOT NULL, start_timestamp timestamptz NOT NULL, end_timestamp timestamptz, - start_block bigint NOT NULL, - end_block bigint, deadline_block bigint NOT NULL, outcome text, PRIMARY KEY (auction_id, solver) From c6d8c9b02d94c267094e045d3fbabc0146acdf16 Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 21 Feb 2025 14:08:50 +0000 Subject: [PATCH 2/5] Fix --- crates/database/src/settlement_executions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/database/src/settlement_executions.rs b/crates/database/src/settlement_executions.rs index 00b9754a2e..a33ebbf23e 100644 --- a/crates/database/src/settlement_executions.rs +++ b/crates/database/src/settlement_executions.rs @@ -13,7 +13,7 @@ pub async fn insert( ) -> Result<(), sqlx::Error> { const QUERY: &str = r#" INSERT INTO settlement_executions (auction_id, solver, start_timestamp, deadline_block) -VALUES ($1, $2, $3, $4, $5) +VALUES ($1, $2, $3, $4) ;"#; sqlx::query(QUERY) @@ -36,7 +36,7 @@ pub async fn update( ) -> Result<(), sqlx::Error> { const QUERY: &str = r#" UPDATE settlement_executions -SET end_timestamp = $3, outcome = $5 +SET end_timestamp = $3, outcome = $4 WHERE auction_id = $1 AND solver = $2 ;"#; From 87d5c51586ff279d8d0e0fea5a9b1e955b6753aa Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 21 Feb 2025 14:12:04 +0000 Subject: [PATCH 3/5] Tables list --- crates/database/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/database/src/lib.rs b/crates/database/src/lib.rs index 7078135bf6..da1a4626de 100644 --- a/crates/database/src/lib.rs +++ b/crates/database/src/lib.rs @@ -71,6 +71,7 @@ pub const TABLES: &[&str] = &[ "proposed_jit_orders", "proposed_solutions", "quotes", + "settlement_executions", "settlement_observations", "settlement_scores", "settlements", From 5425fdb7ea996e21b363783e0de3578248438508 Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 21 Feb 2025 18:15:44 +0000 Subject: [PATCH 4/5] Revert "Fix" This reverts commit c6d8c9b02d94c267094e045d3fbabc0146acdf16. --- crates/database/src/settlement_executions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/database/src/settlement_executions.rs b/crates/database/src/settlement_executions.rs index a33ebbf23e..00b9754a2e 100644 --- a/crates/database/src/settlement_executions.rs +++ b/crates/database/src/settlement_executions.rs @@ -13,7 +13,7 @@ pub async fn insert( ) -> Result<(), sqlx::Error> { const QUERY: &str = r#" INSERT INTO settlement_executions (auction_id, solver, start_timestamp, deadline_block) -VALUES ($1, $2, $3, $4) +VALUES ($1, $2, $3, $4, $5) ;"#; sqlx::query(QUERY) @@ -36,7 +36,7 @@ pub async fn update( ) -> Result<(), sqlx::Error> { const QUERY: &str = r#" UPDATE settlement_executions -SET end_timestamp = $3, outcome = $4 +SET end_timestamp = $3, outcome = $5 WHERE auction_id = $1 AND solver = $2 ;"#; From f114a20616f30bfa01bd16d670c7da71ca5b3d22 Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 21 Feb 2025 18:15:46 +0000 Subject: [PATCH 5/5] Revert "Do not store start/end blocks" This reverts commit 11a8e754aeb035c06c48bf818ed6b31c74e8e1c1. --- crates/autopilot/src/domain/settlement/mod.rs | 2 ++ crates/autopilot/src/infra/persistence/mod.rs | 4 +++ crates/autopilot/src/run_loop.rs | 3 +++ crates/database/src/settlement_executions.rs | 25 +++++++++++++++++-- database/README.md | 2 ++ ...80__create_settlement_executions_table.sql | 2 ++ 6 files changed, 36 insertions(+), 2 deletions(-) diff --git a/crates/autopilot/src/domain/settlement/mod.rs b/crates/autopilot/src/domain/settlement/mod.rs index efc8562f3a..b444638e4e 100644 --- a/crates/autopilot/src/domain/settlement/mod.rs +++ b/crates/autopilot/src/domain/settlement/mod.rs @@ -217,12 +217,14 @@ pub enum Execution { auction_id: AuctionId, solver: eth::Address, start_timestamp: DateTime, + start_block: u64, deadline_block: u64, }, Ended { auction_id: AuctionId, solver: eth::Address, end_timestamp: DateTime, + end_block: u64, outcome: String, }, } diff --git a/crates/autopilot/src/infra/persistence/mod.rs b/crates/autopilot/src/infra/persistence/mod.rs index 60a05e1e88..e9f2ca5bd8 100644 --- a/crates/autopilot/src/infra/persistence/mod.rs +++ b/crates/autopilot/src/infra/persistence/mod.rs @@ -808,6 +808,7 @@ impl Persistence { auction_id, solver, start_timestamp, + start_block, deadline_block, } => { let _timer = Metrics::get() @@ -820,6 +821,7 @@ impl Persistence { auction_id, ByteArray(solver.0 .0), start_timestamp, + start_block.try_into().context("start block overflow")?, deadline_block .try_into() .context("deadline block overflow")?, @@ -830,6 +832,7 @@ impl Persistence { auction_id, solver, end_timestamp, + end_block, outcome, } => { let _timer = Metrics::get() @@ -842,6 +845,7 @@ impl Persistence { auction_id, ByteArray(solver.0 .0), end_timestamp, + end_block.try_into().context("end block overflow")?, outcome, ) .await? diff --git a/crates/autopilot/src/run_loop.rs b/crates/autopilot/src/run_loop.rs index a5c98aaa9d..d227e771cd 100644 --- a/crates/autopilot/src/run_loop.rs +++ b/crates/autopilot/src/run_loop.rs @@ -777,6 +777,7 @@ impl RunLoop { auction_id, solver, start_timestamp: chrono::Utc::now(), + start_block: current_block, deadline_block: submission_deadline_latest_block, }; let settle_event_store_fut = self @@ -837,6 +838,7 @@ impl RunLoop { auction_id: i64, result: &Result, ) { + let current_block = self.eth.current_block().borrow().number; let persistence = self.persistence.clone(); let outcome = match result { Ok(_) => "success".to_string(), @@ -849,6 +851,7 @@ impl RunLoop { auction_id, solver, end_timestamp: chrono::Utc::now(), + end_block: current_block, outcome, }; if let Err(err) = persistence diff --git a/crates/database/src/settlement_executions.rs b/crates/database/src/settlement_executions.rs index 00b9754a2e..fc51551065 100644 --- a/crates/database/src/settlement_executions.rs +++ b/crates/database/src/settlement_executions.rs @@ -9,10 +9,11 @@ pub async fn insert( auction_id: AuctionId, solver: Address, start_timestamp: DateTime, + start_block: i64, deadline_block: i64, ) -> Result<(), sqlx::Error> { const QUERY: &str = r#" -INSERT INTO settlement_executions (auction_id, solver, start_timestamp, deadline_block) +INSERT INTO settlement_executions (auction_id, solver, start_timestamp, start_block, deadline_block) VALUES ($1, $2, $3, $4, $5) ;"#; @@ -20,6 +21,7 @@ VALUES ($1, $2, $3, $4, $5) .bind(auction_id) .bind(solver) .bind(start_timestamp) + .bind(start_block) .bind(deadline_block) .execute(ex) .await?; @@ -32,11 +34,12 @@ pub async fn update( auction_id: AuctionId, solver: Address, end_timestamp: DateTime, + end_block: i64, outcome: String, ) -> Result<(), sqlx::Error> { const QUERY: &str = r#" UPDATE settlement_executions -SET end_timestamp = $3, outcome = $5 +SET end_timestamp = $3, end_block = $4, outcome = $5 WHERE auction_id = $1 AND solver = $2 ;"#; @@ -44,6 +47,7 @@ WHERE auction_id = $1 AND solver = $2 .bind(auction_id) .bind(solver) .bind(end_timestamp) + .bind(end_block) .bind(outcome) .execute(ex) .await?; @@ -71,6 +75,7 @@ mod tests { let solver_a = ByteArray([1u8; 20]); let solver_b = ByteArray([2u8; 20]); let start_timestamp = now_truncated_to_microseconds(); + let start_block = 1; let deadline_block = 10; insert( @@ -78,6 +83,7 @@ mod tests { auction_id, solver_a, start_timestamp, + start_block, deadline_block, ) .await @@ -87,6 +93,7 @@ mod tests { auction_id, solver_b, start_timestamp, + start_block, deadline_block, ) .await @@ -99,6 +106,8 @@ mod tests { solver: solver_a, start_timestamp, end_timestamp: None, + start_block, + end_block: None, deadline_block, outcome: None, }; @@ -107,6 +116,8 @@ mod tests { solver: solver_b, start_timestamp, end_timestamp: None, + start_block, + end_block: None, deadline_block, outcome: None, }; @@ -114,24 +125,28 @@ mod tests { assert!(output.contains(&expected_b)); let end_timestamp_a = now_truncated_to_microseconds(); + let end_block_a = 8; let outcome_a = "success".to_string(); update( &mut db, auction_id, solver_a, end_timestamp_a, + end_block_a, outcome_a.clone(), ) .await .unwrap(); let end_timestamp_b = now_truncated_to_microseconds(); + let end_block_b = 10; let outcome_b = "failure".to_string(); update( &mut db, auction_id, solver_b, end_timestamp_b, + end_block_b, outcome_b.clone(), ) .await @@ -144,6 +159,8 @@ mod tests { solver: solver_a, start_timestamp, end_timestamp: Some(end_timestamp_a), + start_block, + end_block: Some(end_block_a), deadline_block, outcome: Some(outcome_a), }; @@ -152,6 +169,8 @@ mod tests { solver: solver_b, start_timestamp, end_timestamp: Some(end_timestamp_b), + start_block, + end_block: Some(end_block_b), deadline_block, outcome: Some(outcome_b), }; @@ -165,6 +184,8 @@ mod tests { pub solver: Address, pub start_timestamp: DateTime, pub end_timestamp: Option>, + pub start_block: i64, + pub end_block: Option, pub deadline_block: i64, pub outcome: Option, } diff --git a/database/README.md b/database/README.md index 2a9908f2f8..fafc4f070a 100644 --- a/database/README.md +++ b/database/README.md @@ -461,6 +461,8 @@ auction\_id | bigint | not null | id of the auction the settlement exe solver | bytea | not null | public address of the winning solver that executed the settlement start\_timestamp | timestamptz | not null | when the settlement execution started end\_timestamp | timestamptz | nullable | when the settlement execution ended +start\_block | bigint | not null | block in which the settlement execution started +end\_block | bigint | nullable | block in which the settlement execution ended deadline\_block | bigint | not null | latest block at which the settlement execution should have ended outcome | text | nullable | outcome of the settlement execution diff --git a/database/sql/V080__create_settlement_executions_table.sql b/database/sql/V080__create_settlement_executions_table.sql index 1c7d8a45f4..f04a6606f1 100644 --- a/database/sql/V080__create_settlement_executions_table.sql +++ b/database/sql/V080__create_settlement_executions_table.sql @@ -5,6 +5,8 @@ CREATE TABLE settlement_executions solver bytea NOT NULL, start_timestamp timestamptz NOT NULL, end_timestamp timestamptz, + start_block bigint NOT NULL, + end_block bigint, deadline_block bigint NOT NULL, outcome text, PRIMARY KEY (auction_id, solver)