Skip to content

Commit

Permalink
Feat/upgrade protocol refactor (#359)
Browse files Browse the repository at this point in the history
* refactor upgrade protocol to reflect stage and prod envs

* remove files

* fmt

* deploy values
  • Loading branch information
carlomazzaferro authored Sep 12, 2024
1 parent 0501452 commit 8a5a4d9
Show file tree
Hide file tree
Showing 16 changed files with 199 additions and 116 deletions.
2 changes: 2 additions & 0 deletions deploy/stage/common-values-upgrade-server-left.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ env:
secretKeyRef:
key: DATABASE_URL
name: application
- name: ENVIRONMENT
value: stage


keelPolling:
Expand Down
3 changes: 2 additions & 1 deletion deploy/stage/common-values-upgrade-server-right.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ env:
secretKeyRef:
key: DATABASE_URL
name: application

- name: ENVIRONMENT
value: stage

keelPolling:
# -- Specifies whether keel should poll for container updates
Expand Down
2 changes: 2 additions & 0 deletions deploy/stage/mpc1-stage/values-upgrade-server-left.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ args:
- "0"
- "--eye"
- "left"
- "--environment"
- "$(ENVIRONMENT)"
2 changes: 2 additions & 0 deletions deploy/stage/mpc1-stage/values-upgrade-server-right.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ args:
- "0"
- "--eye"
- "right"
- "--environment"
- "$(ENVIRONMENT)"
2 changes: 2 additions & 0 deletions deploy/stage/mpc2-stage/values-upgrade-server-left.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ args:
- "1"
- "--eye"
- "left"
- "--environment"
- "$(ENVIRONMENT)"
4 changes: 3 additions & 1 deletion deploy/stage/mpc2-stage/values-upgrade-server-right.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ args:
- "--party-id"
- "1"
- "--eye"
- "right"
- "right"
- "--environment"
- "$(ENVIRONMENT)"
2 changes: 2 additions & 0 deletions deploy/stage/mpc3-stage/values-upgrade-server-left.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ args:
- "2"
- "--eye"
- "left"
- "--environment"
- "$(ENVIRONMENT)"
2 changes: 2 additions & 0 deletions deploy/stage/mpc3-stage/values-upgrade-server-right.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ args:
- "2"
- "--eye"
- "right"
- "--environment"
- "$(ENVIRONMENT)"
82 changes: 82 additions & 0 deletions iris-mpc-upgrade/src/bin/README.md
Original file line number Diff line number Diff line change
@@ -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
```
85 changes: 0 additions & 85 deletions iris-mpc-upgrade/src/bin/Readme.md

This file was deleted.

61 changes: 43 additions & 18 deletions iris-mpc-upgrade/src/bin/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
#[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::<Vec<_>>()
.await;
let old_left_shares1 = old_left_db1
let old_left_shares1 = old_left_shares_db1
.stream_shares(0..args.num_elements)
.collect::<Vec<_>>()
.await;
let old_left_masks = old_left_db0
let old_left_masks = old_left_masks_db
.stream_masks(0..args.num_elements)
.collect::<Vec<_>>()
.await;
Expand All @@ -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::<Vec<_>>()
.await;
let old_right_shares1 = old_right_db1
let old_right_shares1 = old_right_shares_db1
.stream_shares(0..args.num_elements)
.collect::<Vec<_>>()
.await;
let old_right_masks = old_right_db0
let old_right_masks = old_right_masks_db1
.stream_masks(0..args.num_elements)
.collect::<Vec<_>>()
.await;
Expand Down
16 changes: 12 additions & 4 deletions iris-mpc-upgrade/src/bin/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down
Loading

0 comments on commit 8a5a4d9

Please sign in to comment.