diff --git a/deploy/stage/common-values-upgrade-server-left.yaml b/deploy/stage/common-values-upgrade-server-left.yaml index cdf3046f0..92b95f5ca 100644 --- a/deploy/stage/common-values-upgrade-server-left.yaml +++ b/deploy/stage/common-values-upgrade-server-left.yaml @@ -60,6 +60,8 @@ env: secretKeyRef: key: DATABASE_URL name: application + - name: ENVIRONMENT + value: stage keelPolling: diff --git a/deploy/stage/common-values-upgrade-server-right.yaml b/deploy/stage/common-values-upgrade-server-right.yaml index 3a83563f7..e2654c3bb 100644 --- a/deploy/stage/common-values-upgrade-server-right.yaml +++ b/deploy/stage/common-values-upgrade-server-right.yaml @@ -60,7 +60,8 @@ env: secretKeyRef: key: DATABASE_URL name: application - + - name: ENVIRONMENT + value: stage keelPolling: # -- Specifies whether keel should poll for container updates diff --git a/deploy/stage/mpc1-stage/values-upgrade-server-left.yaml b/deploy/stage/mpc1-stage/values-upgrade-server-left.yaml index 915c71769..cf4f0db5c 100644 --- a/deploy/stage/mpc1-stage/values-upgrade-server-left.yaml +++ b/deploy/stage/mpc1-stage/values-upgrade-server-left.yaml @@ -7,3 +7,5 @@ args: - "0" - "--eye" - "left" + - "--environment" + - "$(ENVIRONMENT)" diff --git a/deploy/stage/mpc1-stage/values-upgrade-server-right.yaml b/deploy/stage/mpc1-stage/values-upgrade-server-right.yaml index 6071605c5..427535399 100644 --- a/deploy/stage/mpc1-stage/values-upgrade-server-right.yaml +++ b/deploy/stage/mpc1-stage/values-upgrade-server-right.yaml @@ -7,3 +7,5 @@ args: - "0" - "--eye" - "right" + - "--environment" + - "$(ENVIRONMENT)" diff --git a/deploy/stage/mpc2-stage/values-upgrade-server-left.yaml b/deploy/stage/mpc2-stage/values-upgrade-server-left.yaml index 453e1a4eb..5d72744a2 100644 --- a/deploy/stage/mpc2-stage/values-upgrade-server-left.yaml +++ b/deploy/stage/mpc2-stage/values-upgrade-server-left.yaml @@ -7,3 +7,5 @@ args: - "1" - "--eye" - "left" + - "--environment" + - "$(ENVIRONMENT)" diff --git a/deploy/stage/mpc2-stage/values-upgrade-server-right.yaml b/deploy/stage/mpc2-stage/values-upgrade-server-right.yaml index 654236bf4..3fe4e264d 100644 --- a/deploy/stage/mpc2-stage/values-upgrade-server-right.yaml +++ b/deploy/stage/mpc2-stage/values-upgrade-server-right.yaml @@ -6,4 +6,6 @@ args: - "--party-id" - "1" - "--eye" - - "right" \ No newline at end of file + - "right" + - "--environment" + - "$(ENVIRONMENT)" diff --git a/deploy/stage/mpc3-stage/values-upgrade-server-left.yaml b/deploy/stage/mpc3-stage/values-upgrade-server-left.yaml index 36367a936..f00cf093c 100644 --- a/deploy/stage/mpc3-stage/values-upgrade-server-left.yaml +++ b/deploy/stage/mpc3-stage/values-upgrade-server-left.yaml @@ -7,3 +7,5 @@ args: - "2" - "--eye" - "left" + - "--environment" + - "$(ENVIRONMENT)" \ No newline at end of file diff --git a/deploy/stage/mpc3-stage/values-upgrade-server-right.yaml b/deploy/stage/mpc3-stage/values-upgrade-server-right.yaml index 8b1d21e38..e522da51d 100644 --- a/deploy/stage/mpc3-stage/values-upgrade-server-right.yaml +++ b/deploy/stage/mpc3-stage/values-upgrade-server-right.yaml @@ -7,3 +7,5 @@ args: - "2" - "--eye" - "right" + - "--environment" + - "$(ENVIRONMENT)" \ No newline at end of file diff --git a/iris-mpc-upgrade/src/bin/README.md b/iris-mpc-upgrade/src/bin/README.md new file mode 100644 index 000000000..caa02666e --- /dev/null +++ b/iris-mpc-upgrade/src/bin/README.md @@ -0,0 +1,82 @@ +# Upgrade Protocol + +Quick local test setup of upgrade protocol: + +## Start some DBs + +```bash +docker compose up -d +``` + +will bring up two old dbs on ports 6200 and 6201, and 3 new dbs on ports 6100,6101,6102. + +## Fill DBs with test data + +```bash +cargo run --release --bin seed-v1-dbs -- --side right --shares-db-urls postgres://postgres:postgres@localhost:6100 --shares-db-urls postgres://postgres:postgres@localhost:6101 --masks-db-url postgres://postgres:postgres@localhost:6111 --num-elements 10000 +cargo run --release --bin seed-v1-dbs -- --side left --shares-db-urls postgres://postgres:postgres@localhost:6100 --shares-db-urls postgres://postgres:postgres@localhost:6101 --masks-db-url postgres://postgres:postgres@localhost:6111 --num-elements 10000 +``` + +## Upgrade for left eye + +### Run the 3 upgrade servers + +Concurrently run: + +```bash +cargo run --release --bin upgrade-server -- --bind-addr 127.0.0.1:8000 --db-url postgres://postgres:postgres@localhost:6200 --party-id 0 --eye left --environment dev +``` + +```bash +cargo run --release --bin upgrade-server -- --bind-addr 127.0.0.1:8001 --db-url postgres://postgres:postgres@localhost:6201 --party-id 1 --eye left --environment dev +``` + +```bash +cargo run --release --bin upgrade-server -- --bind-addr 127.0.0.1:8002 --db-url postgres://postgres:postgres@localhost:6202 --party-id 2 --eye left --environment dev +``` + +### Run the 2 upgrade clients + +Concurrently run: + +```bash +cargo run --release --bin upgrade-client -- --server1 127.0.0.1:8000 --server2 127.0.0.1:8001 --server3 127.0.0.1:8002 --db-start 0 --db-end 10000 --party-id 0 --eye left --shares-db-url postgres://postgres:postgres@localhost:6100 --masks-db-url postgres://postgres:postgres@localhost:6111 +cargo run --release --bin upgrade-client -- --server1 127.0.0.1:8000 --server2 127.0.0.1:8001 --server3 127.0.0.1:8002 --db-start 0 --db-end 10000 --party-id 1 --eye left --shares-db-url postgres://postgres:postgres@localhost:6101 --masks-db-url postgres://postgres:postgres@localhost:6111 +``` + +## Upgrade for right eye + +### Run the 3 upgrade servers + +Concurrently run: + +```bash +cargo run --release --bin upgrade-server -- --bind-addr 127.0.0.1:8000 --db-url postgres://postgres:postgres@localhost:6200 --party-id 0 --eye right --environment dev +``` + +```bash +cargo run --release --bin upgrade-server -- --bind-addr 127.0.0.1:8001 --db-url postgres://postgres:postgres@localhost:6201 --party-id 1 --eye right --environment dev +``` + +```bash +cargo run --release --bin upgrade-server -- --bind-addr 127.0.0.1:8002 --db-url postgres://postgres:postgres@localhost:6202 --party-id 2 --eye right --environment dev +``` + +### Run the 2 upgrade clients + +(In practice these DBs would point to different old DBs, we just use the same old DBs for left and right in this example ) + +Concurrently run: + +```bash +cargo run --release --bin upgrade-client -- --server1 127.0.0.1:8000 --server2 127.0.0.1:8001 --server3 127.0.0.1:8002 --db-start 0 --db-end 10000 --party-id 0 --eye right --shares-db-url postgres://postgres:postgres@localhost:6100 --masks-db-url postgres://postgres:postgres@localhost:6111 +``` +```bash +cargo run --release --bin upgrade-client -- --server1 127.0.0.1:8000 --server2 127.0.0.1:8001 --server3 127.0.0.1:8002 --db-start 0 --db-end 10000 --party-id 1 --eye right --shares-db-url postgres://postgres:postgres@localhost:6101 --masks-db-url postgres://postgres:postgres@localhost:6111 + +``` +## Check the upgrade was successful + +```bash +cargo run --release --bin upgrade-checker -- --environment dev --num-elements 10000 --db-urls postgres://postgres:postgres@localhost:6100 --db-urls postgres://postgres:postgres@localhost:6101 --db-urls postgres://postgres:postgres@localhost:6111 --db-urls postgres://postgres:postgres@localhost:6200 --db-urls postgres://postgres:postgres@localhost:6201 --db-urls postgres://postgres:postgres@localhost:6202 +``` diff --git a/iris-mpc-upgrade/src/bin/Readme.md b/iris-mpc-upgrade/src/bin/Readme.md deleted file mode 100644 index e6e9e1103..000000000 --- a/iris-mpc-upgrade/src/bin/Readme.md +++ /dev/null @@ -1,85 +0,0 @@ -# Upgrade Protocol - -Quick local test setup of upgrade protocol: - -## Start some DBs - -```bash -docker compose up -d -``` - -will bring up two old dbs on ports 6200 and 6201, and 3 new dbs on ports 6100,6101,6102. - -## Fill DBs with test data - -```bash -cargo run --release --bin seed-v1-dbs -- --shares-db-urls postgres://postgres:postgres@localhost:6100/shares --shares-db-urls postgres://postgres:postgres@localhost:6101/shares --masks-db-url postgres://postgres:postgres@localhost:6100/masks --num-elements 10000 -``` - -## Upgrade for left eye - -### Run the 3 upgrade servers - -Concurrently run: - -```bash -cargo run --release --bin upgrade-server -- --bind-addr 127.0.0.1:8000 --db-url postgres://postgres:postgres@localhost:6200/postgres --party-id 0 --eye left -``` - -```bash -cargo run --release --bin upgrade-server -- --bind-addr 127.0.0.1:8001 --db-url postgres://postgres:postgres@localhost:6201/postgres --party-id 1 --eye left -``` - -```bash -cargo run --release --bin upgrade-server -- --bind-addr 127.0.0.1:8002 --db-url postgres://postgres:postgres@localhost:6202/postgres --party-id 2 --eye left -``` - -### Run the 2 upgrade clients - -Concurrently run: - -```bash -cargo run --release --bin upgrade-client -- --server1 127.0.0.1:8000 --server2 127.0.0.1:8001 --server3 127.0.0.1:8002 --db-start 0 --db-end 10000 --party-id 0 --eye left --shares-db-url postgres://postgres:postgres@localhost:6100/shares --masks-db-url postgres://postgres:postgres@localhost:6100/masks -``` - -```bash -cargo run --release --bin upgrade-client -- --server1 127.0.0.1:8000 --server2 127.0.0.1:8001 --server3 127.0.0.1:8002 --db-start 0 --db-end 10000 --party-id 1 --eye left --shares-db-url postgres://postgres:postgres@localhost:6101/shares --masks-db-url postgres://postgres:postgres@localhost:6100/masks -``` - -## Upgrade for right eye - -### Run the 3 upgrade servers - -Concurrently run: - -```bash -cargo run --release --bin upgrade-server -- --bind-addr 127.0.0.1:8000 --db-url postgres://postgres:postgres@localhost:6200/postgres --party-id 0 --eye right -``` - -```bash -cargo run --release --bin upgrade-server -- --bind-addr 127.0.0.1:8001 --db-url postgres://postgres:postgres@localhost:6201/postgres --party-id 1 --eye right -``` - -```bash -cargo run --release --bin upgrade-server -- --bind-addr 127.0.0.1:8002 --db-url postgres://postgres:postgres@localhost:6202/postgres --party-id 2 --eye right -``` - -### Run the 2 upgrade clients - -(In practice these DBs would point to different old DBs, we just use the same old DBs for left and right in this example ) - -Concurrently run: - -```bash -cargo run --release --bin upgrade-client -- --server1 127.0.0.1:8000 --server2 127.0.0.1:8001 --server3 127.0.0.1:8002 --db-start 0 --db-end 10000 --party-id 0 --eye right --shares-db-url postgres://postgres:postgres@localhost:6100/shares --masks-db-url postgres://postgres:postgres@localhost:6100/masks -``` - -```bash -cargo run --release --bin upgrade-client -- --server1 127.0.0.1:8000 --server2 127.0.0.1:8001 --server3 127.0.0.1:8002 --db-start 0 --db-end 10000 --party-id 1 --eye right --shares-db-url postgres://postgres:postgres@localhost:6101/shares --masks-db-url postgres://postgres:postgres@localhost:6100/masks -``` - -## Check the upgrade was successful - -```bash -cargo run --release --bin upgrade-checker -- --num-elements 10000 --db-urls postgres://postgres:postgres@localhost:6100/postgres --db-urls postgres://postgres:postgres@localhost:6101/postgres --db-urls postgres://postgres:postgres@localhost:6100/postgres --db-urls postgres://postgres:postgres@localhost:6101/postgres --db-urls postgres://postgres:postgres@localhost:6200/postgres --db-urls postgres://postgres:postgres@localhost:6201/postgres --db-urls postgres://postgres:postgres@localhost:6202/postgres -``` diff --git a/iris-mpc-upgrade/src/bin/checker.rs b/iris-mpc-upgrade/src/bin/checker.rs index 87353ed3f..01e38a0b8 100644 --- a/iris-mpc-upgrade/src/bin/checker.rs +++ b/iris-mpc-upgrade/src/bin/checker.rs @@ -11,48 +11,73 @@ use iris_mpc_upgrade::db::V1Db; use itertools::izip; use mpc_uniqueness_check::{bits::Bits, distance::EncodedBits}; use std::collections::HashMap; - // quick checking script that recombines the shamir shares for a local server // setup and prints the iris code share +const APP_NAME: &str = "SMPC"; + #[derive(Debug, Clone, Parser)] struct Args { #[clap(long)] db_urls: Vec, #[clap(long)] num_elements: u64, + #[clap(long)] + environment: String, } #[tokio::main] async fn main() -> eyre::Result<()> { let args = Args::parse(); - if args.db_urls.len() != 7 { + if args.db_urls.len() != 6 { return Err(eyre::eyre!( - "Expect 5 db urls to be provided: old_left_db0, old_left_db1, old_right_db0, \ - old_right_db1, new_db0, new_db1, new_db2" + "Expect 5 db urls to be provided: old_participant_1, old_participant_2, \ + old_coordinator_1, new_db0, new_db1, new_db2" )); } - let old_left_db0 = V1Db::new(&args.db_urls[0]).await?; - let old_left_db1 = V1Db::new(&args.db_urls[1]).await?; - let old_right_db0 = V1Db::new(&args.db_urls[2]).await?; - let old_right_db1 = V1Db::new(&args.db_urls[3]).await?; - - let new_db0 = Store::new(&args.db_urls[4], "upgrade").await?; - let new_db1 = Store::new(&args.db_urls[5], "upgrade").await?; - let new_db2 = Store::new(&args.db_urls[6], "upgrade").await?; + let old_left_shares_db0 = + V1Db::new(format!("{}/{}", args.db_urls[0], "/participant1_left").as_str()).await?; + let old_left_shares_db1 = + V1Db::new(format!("{}/{}", args.db_urls[1], "/participant2_left").as_str()).await?; + let old_left_masks_db = + V1Db::new(format!("{}/{}", args.db_urls[2], "/coordinator_left").as_str()).await?; + + let old_right_shares_db0 = + V1Db::new(format!("{}/{}", args.db_urls[0], "/participant1_right").as_str()).await?; + let old_right_shares_db1 = + V1Db::new(format!("{}/{}", args.db_urls[1], "/participant2_right").as_str()).await?; + let old_right_masks_db1 = + V1Db::new(format!("{}/{}", args.db_urls[2], "/coordinator_right").as_str()).await?; + + let base_schema_name = format!("{}_{}", APP_NAME, args.environment); + let new_db0 = Store::new( + &args.db_urls[3], + format!("{}_{}", base_schema_name, "0").as_str(), + ) + .await?; + let new_db1 = Store::new( + &args.db_urls[4], + format!("{}_{}", base_schema_name, "1").as_str(), + ) + .await?; + let new_db2 = Store::new( + &args.db_urls[5], + format!("{}_{}", base_schema_name, "2").as_str(), + ) + .await?; // grab the old shares from the db and reconstruct them - let old_left_shares0 = old_left_db0 + let old_left_shares0 = old_left_shares_db0 .stream_shares(0..args.num_elements) .collect::>() .await; - let old_left_shares1 = old_left_db1 + let old_left_shares1 = old_left_shares_db1 .stream_shares(0..args.num_elements) .collect::>() .await; - let old_left_masks = old_left_db0 + let old_left_masks = old_left_masks_db .stream_masks(0..args.num_elements) .collect::>() .await; @@ -75,15 +100,15 @@ async fn main() -> eyre::Result<()> { }) .collect(); - let old_right_shares0 = old_right_db0 + let old_right_shares0 = old_right_shares_db0 .stream_shares(0..args.num_elements) .collect::>() .await; - let old_right_shares1 = old_right_db1 + let old_right_shares1 = old_right_shares_db1 .stream_shares(0..args.num_elements) .collect::>() .await; - let old_right_masks = old_right_db0 + let old_right_masks = old_right_masks_db1 .stream_masks(0..args.num_elements) .collect::>() .await; diff --git a/iris-mpc-upgrade/src/bin/docker-compose.yaml b/iris-mpc-upgrade/src/bin/docker-compose.yaml index c1386d2da..3bba89ea8 100644 --- a/iris-mpc-upgrade/src/bin/docker-compose.yaml +++ b/iris-mpc-upgrade/src/bin/docker-compose.yaml @@ -1,18 +1,25 @@ services: - old-db-1: + old-db-shares-1: image: postgres:16 ports: - "6100:5432" environment: POSTGRES_USER: "postgres" POSTGRES_PASSWORD: "postgres" - old-db-2: + old-db-shares-2: image: postgres:16 ports: - "6101:5432" environment: POSTGRES_USER: "postgres" POSTGRES_PASSWORD: "postgres" + old-db-masks-1: + image: postgres:16 + ports: + - "6111:5432" + environment: + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" new-db-1: image: postgres:16 ports: @@ -36,8 +43,9 @@ services: POSTGRES_PASSWORD: "postgres" db-ui: depends_on: - - old-db-1 - - old-db-2 + - old-db-shares-1 + - old-db-shares-2 + - old-db-masks-1 - new-db-1 - new-db-2 - new-db-3 diff --git a/iris-mpc-upgrade/src/bin/seed_v1_dbs.rs b/iris-mpc-upgrade/src/bin/seed_v1_dbs.rs index be665cd19..7e26b4210 100644 --- a/iris-mpc-upgrade/src/bin/seed_v1_dbs.rs +++ b/iris-mpc-upgrade/src/bin/seed_v1_dbs.rs @@ -12,6 +12,9 @@ struct Args { #[clap(long)] num_elements: u64, + + #[clap(long)] + side: String, } #[tokio::main] @@ -26,20 +29,38 @@ async fn main() -> eyre::Result<()> { return Err(eyre::eyre!("Expect 1 masks db urls to be provided")); } + if args.side != "left" && args.side != "right" { + return Err(eyre::eyre!("Expect side to be either 'left' or 'right'")); + } + + let participant_one_shares_db_name = format!("participant1_{}", args.side); + let participant_two_shares_db_name = format!("participant2_{}", args.side); + let participant_one_masks_db_name = format!("coordinator_{}", args.side); + let shares_db_config0 = DbConfig { - url: args.shares_db_urls[0].clone(), + url: format!( + "{}/{}", + args.shares_db_urls[0], participant_one_shares_db_name + ), migrate: true, create: true, }; let shares_db_config1 = DbConfig { - url: args.shares_db_urls[1].clone(), + url: format!( + "{}/{}", + args.shares_db_urls[1], participant_two_shares_db_name + ), migrate: true, create: true, }; let masks_db_config = DbConfig { - url: args.masks_db_url.clone(), + url: format!( + "{}/{}", + args.masks_db_url.clone(), + participant_one_masks_db_name + ), migrate: true, create: true, }; diff --git a/iris-mpc-upgrade/src/bin/tcp_upgrade_client.rs b/iris-mpc-upgrade/src/bin/tcp_upgrade_client.rs index 5bcc2fad4..289c1df62 100644 --- a/iris-mpc-upgrade/src/bin/tcp_upgrade_client.rs +++ b/iris-mpc-upgrade/src/bin/tcp_upgrade_client.rs @@ -100,12 +100,14 @@ async fn main() -> eyre::Result<()> { _ => unreachable!(), } } else { + let shares_db_name = format!("participant{}_{}", args.party_id + 1, args.eye,); maybe_shares_db = Some(V1Database { - db: V1Db::new(&args.shares_db_url).await?, + db: V1Db::new(format!("{}/{}", args.shares_db_url, shares_db_name).as_str()).await?, }); + let masks_db_name = format!("coordinator_{}", args.eye); maybe_masks_db = Some(V1Database { - db: V1Db::new(&args.masks_db_url).await?, + db: V1Db::new(format!("{}/{}", args.masks_db_url, masks_db_name).as_str()).await?, }); ( diff --git a/iris-mpc-upgrade/src/bin/tcp_upgrade_server.rs b/iris-mpc-upgrade/src/bin/tcp_upgrade_server.rs index 73b451695..bcec1fa67 100644 --- a/iris-mpc-upgrade/src/bin/tcp_upgrade_server.rs +++ b/iris-mpc-upgrade/src/bin/tcp_upgrade_server.rs @@ -19,6 +19,8 @@ use tokio::{ task::JoinSet, }; +const APP_NAME: &str = "SMPC"; + fn install_tracing() { use tracing_subscriber::{fmt, prelude::*, EnvFilter}; @@ -50,7 +52,8 @@ async fn main() -> eyre::Result<()> { let finished_counter = Arc::new(AtomicUsize::new(0)); let mut senders = Vec::with_capacity(args.threads); - let sink = IrisShareDbSink::new(Store::new(&args.db_url, "upgrade").await?, args.eye); + let schema_name = format!("{}_{}_{}", APP_NAME, args.environment, args.party_id); + let sink = IrisShareDbSink::new(Store::new(&args.db_url, &schema_name).await?, args.eye); tracing::info!("Starting healthcheck server."); diff --git a/iris-mpc-upgrade/src/config.rs b/iris-mpc-upgrade/src/config.rs index 5e8ab12f1..ef7ea3a3a 100644 --- a/iris-mpc-upgrade/src/config.rs +++ b/iris-mpc-upgrade/src/config.rs @@ -1,7 +1,7 @@ use clap::Parser; use iris_mpc_common::id::PartyID; use std::{ - fmt::{self, Formatter}, + fmt::{self, Display, Formatter}, io, net::{SocketAddr, ToSocketAddrs}, str::FromStr, @@ -14,6 +14,15 @@ pub enum Eye { Right = 1, } +impl Display for Eye { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + Eye::Left => write!(f, "left"), + Eye::Right => write!(f, "right"), + } + } +} + impl FromStr for Eye { type Err = String; @@ -42,6 +51,9 @@ pub struct UpgradeServerConfig { #[clap(long)] pub eye: Eye, + + #[clap(long)] + pub environment: String, } impl std::fmt::Debug for UpgradeServerConfig {