Skip to content

Commit

Permalink
Merge pull request #127 from exfinen/expose-range-of-ports
Browse files Browse the repository at this point in the history
Expose port 8000 to 9000
  • Loading branch information
exfinen authored Dec 27, 2024
2 parents c1a9b42 + 76ef297 commit a6cb8ee
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 56 deletions.
4 changes: 1 addition & 3 deletions mpc_demo_infra/computation_party_server/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ FROM ubuntu:24.04

SHELL ["/bin/bash", "-c"]
ENV PATH="/root/.cargo/bin:/root/.local/bin:${PATH}"
ARG PORT=8006
ARG PARTY_ID=0
ENV PORT=${PORT}
ENV PARTY_ID=${PARTY_ID}

WORKDIR /root
Expand Down Expand Up @@ -45,7 +43,7 @@ COPY ssl_certs/ /root/mpc-demo-infra/ssl_certs/

ENV LD_LIBRARY_PATH="/root/MP-SPDZ"
WORKDIR /root/mpc-demo-infra
EXPOSE ${PORT}
EXPOSE 8000-9000

ENTRYPOINT ["poetry", "run"]
CMD ["party-run"]
Expand Down
64 changes: 38 additions & 26 deletions mpc_demo_infra/computation_party_server/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,54 @@ This document assumes that:

## Configuring server
### Common configuration
1. Edit `mpc_demo_infra/computation_party_server/docker/.env.party` as follows:
```
PARTY_HOSTS=["prod-party-0.mpcstats.org","prod-party-1.mpcstats.org","prod-party-2.mpcstats.org"]
PARTY_PORTS=["8006","8007","8008"]
```
Edit `mpc_demo_infra/computation_party_server/docker/.env.party` as follows:
```
PARTY_HOSTS=["prod-party-0.mpcstats.org","prod-party-1.mpcstats.org","prod-party-2.mpcstats.org"]
PARTY_PORTS=["8006","8007","8008"]
```

```
COORDINATION_SERVER_URL=https://prod-coord.mpcstats.org:8005
```
```
COORDINATION_SERVER_URL=https://prod-coord.mpcstats.org:8005
```

### Per-server configuration
For each computation party server, do the following replacing %PORT% and %PARTY_ID% with those of the server to be configured.

1. If you're to use:
- `https`:
1. Add `pem` files for your https domain to `mpc_demo_infra/computation_party_server/docker/ssl_certs` directory.
2. Update the `PRIVKEY_PEM_PATH` and `FULLCHAIN_PEM_PATH` in `mpc_demo_infra/data_consumer_api/docker/.env.party`. The paths should be relative to the repository root.
- `http`
1. Update the `PARTY_WEB_PROTOCL` in `mpc_demo_infra/computation_party_server/docker/.env.party` as follows:
```
PARTY_WEB_PROTOCOL=http
```
2. In order to use a different MPC scheme, replace `malicious-rep-ring-party.x` in the following line in `mpc_demo_infra/computation_party_server/docker/Dockerfile` with the name of the virtual machine that implements the desired scheme:

- Transport Protocol
If `PARTY_WEB_PROTOCOL` is set to `https`, the following configuration will be necessary:
1. Add the .pem files for your HTTPS domain to the `mpc_demo_infra/computation_party_server/docker/ssl_certs directory`.
2. Update the following variables in the `mpc_demo_infra/data_consumer_api/docker/.env.party file`:
- `PRIVKEY_PEM_PATH`: Path to your private key PEM file.
- `FULLCHAIN_PEM_PATH`: Path to your full chain PEM file.
Ensure the paths are relative to the repository root.

- MPC Scheme
Different MPC schemes can be used for the computation party server.

To use a different MPC scheme:
1. Modify the following line in `mpc_demo_infra/computation_party_server/docker/Dockerfile`:
```
&& make -j$(nproc) malicious-rep-ring-party.x \
```
For the available schemes, refer to the Protocols section in the [README](https://github.com/exfinen/MP-SPDZ?tab=readme-ov-file) file of MP-SPDZ.
2. Add the following line to `mpc_demo_infra/computation_party_server/docker/.env.party`:
```
MPSPDZ_PROTOCOL=<Protocol Name>
```
The protocol name should be the name of the `.x` file generated in the previous step with `-party.x` suffix removed. i.e. `malicious-rep-ring` for `malicious-rep-ring-party.x`.

For the list of available schemes, refer to the `Protocols` section in the [MP-SPDZ README](https://github.com/exfinen/MP-SPDZ?tab=readme-ov-file).

## Running the servers
On each party server host, move to `mpc-demo-infra/mpc_demo_infra/computation_party_server/docker` and run the following commands replacing %PORT% and %PARTY_ID% with the port and party ID for the server:
To run the servers on each party’s host, follow these steps:

1. Navigate to the `mpc-demo-infra/mpc_demo_infra/computation_party_server/docker` directory:
```bash
cd mpc-demo-infra/mpc_demo_infra/computation_party_server/docker
```

2. Run the following commands, replacing %PARTY_ID% with the party ID for the server:
```bash
export PORT=%PORT%
export PARTY_ID=%PARTY_ID%
docker build --build-arg PORT=${PORT} --build-arg PARTY_ID=${PARTY_ID} -t party .
docker run --init -it -p ${PORT}:${PORT} -e PORT=${PORT} -e PARTY_ID=${PARTY_ID} party
docker build --build-arg PARTY_ID=${PARTY_ID} -t party .
docker run --init -it -p 8000-9000:8000:9000 -e PARTY_ID=${PARTY_ID} party
```

12 changes: 8 additions & 4 deletions mpc_demo_infra/computation_party_server/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def generate_data_sharing_program(
program_content = '\n'.join([line for line in program_content.split('\n') if "# NOTE: Skipped if it's the first run" not in line])

logger.info(f"Generated data sharing program from the template with parameters: {secret_index=}, {client_port_base=}, {max_data_providers=}, {is_first_run=}, {input_bytes=}, {tlsn_delta=}, {tlsn_zero_encodings=}")
logger.info(f"Generated program: {program_content}")
logger.debug(f"Generated program: {program_content}")
with open(target_program_path, "w") as program_file:
program_file.write(program_content)
return circuit_name, target_program_path
Expand All @@ -313,6 +313,8 @@ def generate_computation_query_program(
program_content = program_content.replace("{client_port_base}", str(client_port_base))
program_content = program_content.replace("{max_data_providers}", str(max_data_providers))
program_content = program_content.replace("{num_data_providers}", str(num_data_providers))
logger.info(f"Generated query computation program from the template with parameters: {circuit_name=}, {client_port_base=}, {max_data_providers=}, {num_data_providers=}")
logger.debug(f"Generated program: {program_content}")
with open(target_program_path, "w") as program_file:
program_file.write(program_content)
return circuit_name, target_program_path
Expand All @@ -321,7 +323,8 @@ def generate_computation_query_program(
def compile_program(circuit_name: str):
# Compile share_data_<client_id>.mpc
subprocess.run(
f"cd {settings.mpspdz_project_root} && {CMD_COMPILE_MPC} {circuit_name}",
f"{CMD_COMPILE_MPC} {circuit_name}",
cwd=settings.mpspdz_project_root,
check=True,
shell=True,
)
Expand All @@ -336,11 +339,12 @@ def run_program(circuit_name: str, ip_file_path: str):
# cmd_run_mpc = f"./{MPC_VM_BINARY} -N {settings.num_parties} -p {settings.party_id} -OF . {circuit_name} -ip {str(ip_file_path)}"
# ./replicated-ring-party.x -ip ip_rep -p 0 tutorial
cmd_run_mpc = f"./{MPC_VM_BINARY} -ip {str(ip_file_path)} -p {settings.party_id} -OF . {circuit_name}"
logger.info(f"Executing a program on {MPC_VM_BINARY} vm")
logger.info(f"Executing a program on {MPC_VM_BINARY} vm: {cmd_run_mpc}")
# Run the MPC program
try:
process = subprocess.run(
f"cd {settings.mpspdz_project_root} && {cmd_run_mpc}",
f"{cmd_run_mpc}",
cwd=settings.mpspdz_project_root,
shell=True,
capture_output=True,
text=True
Expand Down
2 changes: 1 addition & 1 deletion mpc_demo_infra/coordination_server/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ COPY ssl_certs/ /root/mpc-demo-infra/ssl_certs/
COPY notary.key /root/tlsn/notary/server/fixture/notary/

WORKDIR /root/mpc-demo-infra
EXPOSE 8005
EXPOSE 8000-9000

ENTRYPOINT ["poetry", "run"]
CMD ["coord-run"]
30 changes: 9 additions & 21 deletions mpc_demo_infra/coordination_server/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,20 @@
| 1 | prod-party-1.mpcstats.org | 8007 |
| 2 | prod-party-2.mpcstats.org | 8008 |

## Conguring server
1. Edit `mpc_demo_infra/coordination_server/docker/.env.coord` according to your server configuraiton.
2. If you're to use:
- `https`:
1. Add `pem` files for your https domain to `mpc_demo_infra/coordination_server/docker/ssl_certs` directory.
2. Update the `PRIVKEY_PEM_PATH` and `FULLCHAIN_PEM_PATH` in `mpc_demo_infra/data_consumer_api/docker/.env.coord`. The paths should be relative to the repository root.
- `http`
1. Update the `PARTY_WEB_PROTOCL` in `mpc_demo_infra/coordination_server/docker/.env.coord` as follows:
```
PARTY_WEB_PROTOCOL=http
```
## Configuring the server
Edit `mpc_demo_infra/coordination_server/docker/.env.coord` as needed.

3. In order to change the port Coordination server listens to:
1. Update the following line in `mpc_demo_infra/coordination_server/docker/Dockerfile`
```
EXPOSE 8005
```
2. Update the following line in `mpc_demo_infra/coordination_server/docker/.env.coord`
```
PORT=8004
```
If `PARTY_WEB_PROTOCOL` is set to `https`, the following configuration will be necessary:
1. Add the .pem files for your HTTPS domain to the `mpc_demo_infra/computation_party_server/docker/ssl_certs directory`.
2. Update the following variables in the `mpc_demo_infra/data_consumer_api/docker/.env.party file`:
- `PRIVKEY_PEM_PATH`: Path to your private key PEM file.
- `FULLCHAIN_PEM_PATH`: Path to your full chain PEM file.
Ensure the paths are relative to the repository root.

## Running the server
```bash
docker build -t coord .
docker run --init -it -p 8005:8005 coord
docker run --init -it -p 8000-9000:8000-9000 coord
```


3 changes: 2 additions & 1 deletion mpc_demo_infra/coordination_server/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ async def request_sharing_data_all_parties():
}, headers=headers)
tasks.append(task)
# l.set()
logger.info(f"Sending all requests concurrently")
logger.info(f"Concurrently sent sharing data request to all parties")

# Send all requests concurrently
responses = await asyncio.gather(*tasks)
logger.info(f"Received responses for sharing data MPC for {eth_address=}")
Expand Down

0 comments on commit a6cb8ee

Please sign in to comment.