From a40bd8b1da53e73dc2029e12aa38e2d944814529 Mon Sep 17 00:00:00 2001 From: Frederic Kettelhoit Date: Wed, 24 Apr 2024 18:14:32 +0100 Subject: [PATCH] Use shorter strings for Postgres db example --- .github/workflows/test.yml | 2 +- examples/postgres-integration/.example.garble.rs | 8 ++++---- examples/postgres-integration/policies0.json | 1 + examples/postgres-integration/policies1.json | 3 ++- .../postgres-integration/seeds/db0/residents.csv | 4 ++-- .../postgres-integration/seeds/db1/insurance.csv | 4 ++-- examples/postgres-integration/src/main.rs | 15 +++++++++++---- examples/postgres-integration/tests/cli.rs | 2 +- 8 files changed, 24 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6c0183e..7d55414 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,5 +20,5 @@ jobs: working-directory: ./examples/http-single-server-channels - run: cargo test -- --nocapture working-directory: ./examples/iroh-p2p-channels - - run: docker compose -f docker-compose.yml up -d && cargo test -- --nocapture + - run: docker compose -f docker-compose.yml up -d && cargo test --release -- --nocapture working-directory: ./examples/postgres-integration diff --git a/examples/postgres-integration/.example.garble.rs b/examples/postgres-integration/.example.garble.rs index adc25bd..3bfc81d 100644 --- a/examples/postgres-integration/.example.garble.rs +++ b/examples/postgres-integration/.example.garble.rs @@ -1,15 +1,15 @@ enum Row0 { None, - Some(i32, [u8; 16], i32), + Some(i32, [u8; 6], i32), } enum Row1 { None, - Some(i32, [u8; 16], bool), + Some(i32, [u8; 6], bool), } -pub fn main(residents: [Row0; 4], insurance: [Row1; 4], age_threshold: u32) -> [[u8; 16]; 4] { - let mut result = [[0u8; 16]; 4]; +pub fn main(residents: [Row0; 4], insurance: [Row1; 4], age_threshold: u32) -> [[u8; 6]; 4] { + let mut result = [[0u8; 6]; 4]; let mut i = 0usize; for resident in residents { for insurance in insurance { diff --git a/examples/postgres-integration/policies0.json b/examples/postgres-integration/policies0.json index 0eaad77..72a9ec4 100644 --- a/examples/postgres-integration/policies0.json +++ b/examples/postgres-integration/policies0.json @@ -13,6 +13,7 @@ "input": "SELECT id, name, age FROM residents", "input_db": "postgres://postgres:test@localhost:5550/postgres", "max_rows": 4, + "max_str_bytes": 6, "setup": "TRUNCATE results", "output": "INSERT INTO results (name) VALUES ($1)", "output_db": "postgres://postgres:test@localhost:5555/postgres" diff --git a/examples/postgres-integration/policies1.json b/examples/postgres-integration/policies1.json index b1d99d9..5ec8f4a 100644 --- a/examples/postgres-integration/policies1.json +++ b/examples/postgres-integration/policies1.json @@ -12,7 +12,8 @@ "party": 1, "input": "SELECT id, name, disabled FROM insurance", "input_db": "postgres://postgres:test@localhost:5551/postgres", - "max_rows": 4 + "max_rows": 4, + "max_str_bytes": 6 } ] } diff --git a/examples/postgres-integration/seeds/db0/residents.csv b/examples/postgres-integration/seeds/db0/residents.csv index 0d6996a..eabf47c 100644 --- a/examples/postgres-integration/seeds/db0/residents.csv +++ b/examples/postgres-integration/seeds/db0/residents.csv @@ -1,5 +1,5 @@ Id,Name,Age,Address 0,"John Doe",22,"Parkstraße 1, 12345 Berlin" 1,"Jane Doe",33,"Schlossallee 2, 12345 Berlin" -2,"Max Mustermann",66,"Parkstraße 1, 12345 Berlin" -3,"Erika Musterfrau",77,"Schlossallee 2, 12345 Berlin" +2,"Max Doe",66,"Parkstraße 1, 12345 Berlin" +3,"Bob Doe",77,"Schlossallee 2, 12345 Berlin" diff --git a/examples/postgres-integration/seeds/db1/insurance.csv b/examples/postgres-integration/seeds/db1/insurance.csv index 21f0512..7a98cc8 100644 --- a/examples/postgres-integration/seeds/db1/insurance.csv +++ b/examples/postgres-integration/seeds/db1/insurance.csv @@ -1,3 +1,3 @@ Id,Name,Disabled,Address -0,"Max Mustermann",true,"Parkstraße 1, 12345 Berlin" -1,"Erika Musterfrau",false,"Schlossallee 2, 12345 Berlin" +0,"Max Doe",true,"Parkstraße 1, 12345 Berlin" +1,"Bob Doe",false,"Schlossallee 2, 12345 Berlin" diff --git a/examples/postgres-integration/src/main.rs b/examples/postgres-integration/src/main.rs index ad75859..799ec4c 100644 --- a/examples/postgres-integration/src/main.rs +++ b/examples/postgres-integration/src/main.rs @@ -40,7 +40,7 @@ use url::Url; const TIME_BETWEEN_EXECUTIONS: Duration = Duration::from_secs(30); const DEFAULT_MAX_ROWS: usize = 10; -const STR_LEN_BYTES: usize = 16; +const DEFAULT_MAX_STR_BYTES: usize = 8; /// A CLI for Multi-Party Computation using the Parlay engine. #[derive(Debug, Parser)] @@ -68,6 +68,7 @@ struct Policy { input: String, input_db: Option, max_rows: Option, + max_str_bytes: Option, setup: Option, output: Option, output_db: Option, @@ -304,6 +305,7 @@ async fn execute_mpc( input, input_db: db, max_rows, + max_str_bytes, setup: _setup, output: _output, output_db: _output_db, @@ -320,6 +322,7 @@ async fn execute_mpc( let rows = sqlx::query(input).fetch_all(&pool).await?; info!("'{input}' returned {} rows from {db}", rows.len()); let max_rows = max_rows.unwrap_or(DEFAULT_MAX_ROWS); + let max_str_bytes = max_str_bytes.unwrap_or(DEFAULT_MAX_STR_BYTES); let mut rows_as_literals = vec![ Literal::Enum( format!("Row{party}"), @@ -333,12 +336,16 @@ async fn execute_mpc( for c in 0..row.len() { let field = if let Ok(s) = row.try_get::(c) { let mut fixed_str = - vec![Literal::NumUnsigned(0, UnsignedNumType::U8); STR_LEN_BYTES]; + vec![Literal::NumUnsigned(0, UnsignedNumType::U8); max_str_bytes]; for (i, b) in s.as_bytes().iter().enumerate() { - if i < STR_LEN_BYTES { + if i < max_str_bytes { fixed_str[i] = Literal::NumUnsigned(*b as u64, UnsignedNumType::U8); } else { - bail!("String is longer than {STR_LEN_BYTES} bytes: '{s}'"); + warn!( + "String is longer than {max_str_bytes} bytes: '{s}', dropping '{}'", + &s[i..] + ); + break; } } Literal::Array(fixed_str) diff --git a/examples/postgres-integration/tests/cli.rs b/examples/postgres-integration/tests/cli.rs index a4aff2a..fd24032 100644 --- a/examples/postgres-integration/tests/cli.rs +++ b/examples/postgres-integration/tests/cli.rs @@ -8,7 +8,7 @@ use std::{ #[test] fn simulate() { - let millis = 1000; + let millis = 2000; println!("\n\n--- {millis}ms ---\n\n"); let mut children = vec![]; let mut cmd = Command::new("cargo")