Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Network Peer actor #231

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
node-version: 20

- name: Cache node modules
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
override: true

- name: Cache node modules
uses: actions/cache@v2
uses: actions/cache@v4
hmzakhalid marked this conversation as resolved.
Show resolved Hide resolved
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
node-version: 20

- name: Cache node modules
uses: actions/cache@v2
uses: actions/cache@v4
hmzakhalid marked this conversation as resolved.
Show resolved Hide resolved
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
Expand Down
1 change: 0 additions & 1 deletion deploy/agg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ peers:
- "/dns4/cn1/udp/9091/quic-v1"
- "/dns4/cn2/udp/9092/quic-v1"
- "/dns4/cn3/udp/9093/quic-v1"
- "/dns4/aggregator/udp/9094/quic-v1"
hmzakhalid marked this conversation as resolved.
Show resolved Hide resolved
chains:
- name: "sepolia"
rpc_url: "${RPC_URL}"
Expand Down
7 changes: 3 additions & 4 deletions deploy/cn1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ address: "${ADDRESS}"
quic_port: ${QUIC_PORT}
enable_mdns: false
peers:
- "/dns4/cn1/udp/9091/quic-v1"
- "/dns4/cn1/udp/9092/quic-v1"
- "/dns4/cn1/udp/9093/quic-v1"
- "/dns4/cn1/udp/9094/quic-v1"
- "/dns4/cn2/udp/9092/quic-v1"
- "/dns4/cn3/udp/9093/quic-v1"
- "/dns4/aggregator/udp/9094/quic-v1"
hmzakhalid marked this conversation as resolved.
Show resolved Hide resolved
chains:
- name: "sepolia"
rpc_url: "${RPC_URL}"
Expand Down
1 change: 0 additions & 1 deletion deploy/cn2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ quic_port: ${QUIC_PORT}
enable_mdns: false
peers:
- "/dns4/cn1/udp/9091/quic-v1"
- "/dns4/cn2/udp/9092/quic-v1"
- "/dns4/cn3/udp/9093/quic-v1"
- "/dns4/aggregator/udp/9094/quic-v1"
chains:
Expand Down
1 change: 0 additions & 1 deletion deploy/cn3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ enable_mdns: false
peers:
- "/dns4/cn1/udp/9091/quic-v1"
- "/dns4/cn2/udp/9092/quic-v1"
- "/dns4/cn3/udp/9093/quic-v1"
- "/dns4/aggregator/udp/9094/quic-v1"
chains:
- name: "sepolia"
Expand Down
3 changes: 3 additions & 0 deletions packages/ciphernode/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ COPY ./packages/ciphernode/data/Cargo.toml ./data/Cargo.toml
COPY ./packages/ciphernode/e3_request/Cargo.toml ./e3_request/Cargo.toml
COPY ./packages/ciphernode/enclave/Cargo.toml ./enclave/Cargo.toml
COPY ./packages/ciphernode/enclave_core/Cargo.toml ./enclave_core/Cargo.toml
COPY ./packages/ciphernode/enclave_core/build.rs ./enclave_core/build.rs
COPY ./packages/ciphernode/events/Cargo.toml ./events/Cargo.toml
COPY ./packages/ciphernode/evm/Cargo.toml ./evm/Cargo.toml
COPY ./packages/ciphernode/fhe/Cargo.toml ./fhe/Cargo.toml
COPY ./packages/ciphernode/keyshare/Cargo.toml ./keyshare/Cargo.toml
COPY ./packages/ciphernode/logger/Cargo.toml ./logger/Cargo.toml
COPY ./packages/ciphernode/net/Cargo.toml ./net/Cargo.toml
COPY ./packages/ciphernode/sortition/Cargo.toml ./sortition/Cargo.toml
COPY ./packages/ciphernode/test_helpers/Cargo.toml ./test_helpers/Cargo.toml
COPY ./packages/ciphernode/tests/Cargo.toml ./tests/Cargo.toml

# Build all dependencies and add them to the build cache
RUN mkdir -p src && \
Expand Down
4 changes: 2 additions & 2 deletions packages/ciphernode/enclave/src/aggregator_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ pub async fn execute(
) -> Result<()> {
owo();

let (bus, handle, peer_id) =
let (bus, peer_id) =
aggregator_start::execute(config, pubkey_write_path, plaintext_write_path).await?;

info!("LAUNCHING AGGREGATOR {}", peer_id);
tokio::spawn(listen_for_shutdown(bus.into(), handle));
tokio::spawn(listen_for_shutdown(bus.into()));

std::future::pending::<()>().await;

Expand Down
4 changes: 2 additions & 2 deletions packages/ciphernode/enclave/src/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ pub async fn execute(config: AppConfig) -> Result<()> {
return Err(anyhow!("You must provide an address"));
};

let (bus, handle, peer_id) = start::execute(config, address).await?;
let (bus, peer_id) = start::execute(config, address).await?;
info!("LAUNCHING CIPHERNODE: ({}/{})", address, peer_id);

tokio::spawn(listen_for_shutdown(bus.into(), handle));
tokio::spawn(listen_for_shutdown(bus.into()));

std::future::pending::<()>().await;

Expand Down
7 changes: 3 additions & 4 deletions packages/ciphernode/enclave_core/src/aggregator_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ use sortition::Sortition;
use sortition::SortitionRepositoryFactory;
use std::sync::{Arc, Mutex};
use test_helpers::{PlaintextWriter, PublicKeyWriter};
use tokio::task::JoinHandle;

use crate::helpers::datastore::setup_datastore;

pub async fn execute(
config: AppConfig,
pubkey_write_path: Option<&str>,
plaintext_write_path: Option<&str>,
) -> Result<(Addr<EventBus>, JoinHandle<Result<()>>, String)> {
) -> Result<(Addr<EventBus>, String)> {
let bus = EventBus::new(true).start();
let rng = Arc::new(Mutex::new(ChaCha20Rng::from_rng(OsRng)?));
let store = setup_datastore(&config, &bus)?;
Expand Down Expand Up @@ -79,7 +78,7 @@ pub async fn execute(
.build()
.await?;

let (_, join_handle, peer_id) = NetworkManager::setup_with_peer(
let (_, peer_id) = NetworkManager::setup_with_peer(
bus.clone(),
config.peers(),
&cipher,
Expand All @@ -99,5 +98,5 @@ pub async fn execute(

SimpleLogger::attach("AGG", bus.clone());

Ok((bus, join_handle, peer_id))
Ok((bus, peer_id))
}
13 changes: 2 additions & 11 deletions packages/ciphernode/enclave_core/src/helpers/shutdown.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
use actix::Recipient;
use anyhow::Result;
use events::{EnclaveEvent, Shutdown};
use std::time::Duration;
use tokio::{
signal::unix::{signal, SignalKind},
task::JoinHandle,
};
use tokio::signal::unix::{signal, SignalKind};
use tracing::info;

pub async fn listen_for_shutdown(bus: Recipient<EnclaveEvent>, handle: JoinHandle<Result<()>>) {
pub async fn listen_for_shutdown(bus: Recipient<EnclaveEvent>) {
let mut sigterm =
signal(SignalKind::terminate()).expect("Failed to create SIGTERM signal stream");

Expand All @@ -18,14 +14,9 @@ pub async fn listen_for_shutdown(bus: Recipient<EnclaveEvent>, handle: JoinHandl
// Stop the actor system
let _ = bus.send(EnclaveEvent::from(Shutdown)).await;

// Abort the spawned task
handle.abort();

// Wait for all actor processes to disconnect
tokio::time::sleep(Duration::from_secs(2)).await;

// Wait for the task to finish
let _ = handle.await;

info!("Graceful shutdown complete");
}
7 changes: 3 additions & 4 deletions packages/ciphernode/enclave_core/src/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use sortition::CiphernodeSelector;
use sortition::Sortition;
use sortition::SortitionRepositoryFactory;
use std::sync::{Arc, Mutex};
use tokio::task::JoinHandle;
use tracing::instrument;

use crate::helpers::datastore::setup_datastore;
Expand All @@ -29,7 +28,7 @@ use crate::helpers::datastore::setup_datastore;
pub async fn execute(
config: AppConfig,
address: Address,
) -> Result<(Addr<EventBus>, JoinHandle<Result<()>>, String)> {
) -> Result<(Addr<EventBus>, String)> {
let rng = Arc::new(Mutex::new(rand_chacha::ChaCha20Rng::from_rng(OsRng)?));
let bus = EventBus::new(true).start();
let cipher = Arc::new(Cipher::from_config(&config).await?);
Expand Down Expand Up @@ -72,7 +71,7 @@ pub async fn execute(
.build()
.await?;

let (_, join_handle, peer_id) = NetworkManager::setup_with_peer(
let (_, peer_id) = NetworkManager::setup_with_peer(
bus.clone(),
config.peers(),
&cipher,
Expand All @@ -85,5 +84,5 @@ pub async fn execute(
let nm = format!("CIPHER({})", &address.to_string()[0..5]);
SimpleLogger::attach(&nm, bus.clone());

Ok((bus, join_handle, peer_id))
Ok((bus, peer_id))
}
4 changes: 2 additions & 2 deletions packages/ciphernode/net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ repository = "https://github.com/gnosisguild/enclave/packages/ciphernode"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = { workspace = true }
actix = { workspace = true }
async-std = { workspace = true, features = ["attributes"] }
async-trait = { workspace = true }
futures = { workspace = true }
Expand All @@ -29,6 +31,4 @@ tokio = { workspace = true, features = ["full"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
events = { workspace = true }
anyhow = { workspace = true }
actix = { workspace = true }
zeroize = { workspace = true }
Loading