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

Rename registry to orchestrator #83

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use actix::prelude::*;
use alloy_primitives::Address;
use std::collections::HashMap;

pub struct CiphernodeRegistry {
pub struct CiphernodeOrchestrator {
bus: Addr<EventBus>,
data: Addr<Data>,
address: Address,
ciphernodes: HashMap<E3id, Addr<Ciphernode>>,
buffers: HashMap<E3id, Vec<EnclaveEvent>>,
}

impl CiphernodeRegistry {
impl CiphernodeOrchestrator {
pub fn new(bus: Addr<EventBus>, data: Addr<Data>, address: Address) -> Self {
Self {
bus,
Expand All @@ -24,15 +24,15 @@ impl CiphernodeRegistry {
}

pub fn attach(bus: Addr<EventBus>, data: Addr<Data>, address: Address) -> Addr<Self> {
CiphernodeRegistry::new(bus, data, address).start()
CiphernodeOrchestrator::new(bus, data, address).start()
}
}

impl Actor for CiphernodeRegistry {
impl Actor for CiphernodeOrchestrator {
type Context = Context<Self>;
}

impl Handler<InitializeWithEnclaveEvent> for CiphernodeRegistry {
impl Handler<InitializeWithEnclaveEvent> for CiphernodeOrchestrator {
type Result = ();
fn handle(&mut self, msg: InitializeWithEnclaveEvent, _: &mut Self::Context) -> Self::Result {
let InitializeWithEnclaveEvent { fhe, event, .. } = msg;
Expand All @@ -46,7 +46,7 @@ impl Handler<InitializeWithEnclaveEvent> for CiphernodeRegistry {
}
}

impl Handler<EnclaveEvent> for CiphernodeRegistry {
impl Handler<EnclaveEvent> for CiphernodeOrchestrator {
type Result = ();

fn handle(&mut self, msg: EnclaveEvent, _ctx: &mut Self::Context) -> Self::Result {
Expand All @@ -57,7 +57,7 @@ impl Handler<EnclaveEvent> for CiphernodeRegistry {
}
}

impl CiphernodeRegistry {
impl CiphernodeOrchestrator {
fn ciphernode_factory(&self, fhe: Addr<Fhe>) -> impl FnOnce() -> Addr<Ciphernode> {
let data = self.data.clone();
let bus = self.bus.clone();
Expand Down
42 changes: 23 additions & 19 deletions packages/ciphernode/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// #![warn(missing_docs, unused_imports)]

mod ciphernode;
mod ciphernode_registry;
mod ciphernode_orchestrator;
mod ciphernode_selector;
mod data;
mod enclave_contract;
Expand All @@ -13,20 +13,20 @@ mod fhe;
mod logger;
mod main_aggregator;
mod main_ciphernode;
mod orchestrator;
mod ordered_set;
mod p2p;
mod plaintext_aggregator;
mod plaintext_registry;
mod plaintext_orchestrator;
mod publickey_aggregator;
mod publickey_registry;
mod registry;
mod publickey_orchestrator;
mod serializers;
mod sortition;

// TODO: this is too permissive
pub use actix::prelude::*;
pub use ciphernode::*;
pub use ciphernode_registry::*;
pub use ciphernode_orchestrator::*;
pub use ciphernode_selector::*;
pub use data::*;
pub use eventbus::*;
Expand All @@ -35,12 +35,12 @@ pub use fhe::*;
pub use logger::*;
pub use main_aggregator::*;
pub use main_ciphernode::*;
pub use orchestrator::*;
pub use p2p::*;
pub use plaintext_aggregator::*;
pub use plaintext_registry::*;
pub use plaintext_orchestrator::*;
pub use publickey_aggregator::*;
pub use publickey_registry::*;
pub use registry::*;
pub use publickey_orchestrator::*;
pub use sortition::*;

// TODO: move these out to a test folder
Expand All @@ -56,9 +56,9 @@ mod tests {
CiphertextSerializer, DecryptionShareSerializer, PublicKeySerializer,
PublicKeyShareSerializer,
},
CiphernodeAdded, CiphernodeRegistry, CiphernodeSelected, CiphertextOutputPublished,
DecryptionshareCreated, PlaintextAggregated, PlaintextRegistry, PublicKeyRegistry,
Registry, ResetHistory, SharedRng, Sortition,
CiphernodeAdded, CiphernodeOrchestrator, CiphernodeSelected, CiphertextOutputPublished,
DecryptionshareCreated, Orchestrator, PlaintextAggregated, PlaintextOrchestrator,
PublicKeyOrchestrator, ResetHistory, SharedRng, Sortition,
};
use actix::prelude::*;
use alloy_primitives::Address;
Expand Down Expand Up @@ -88,14 +88,18 @@ mod tests {
// create ciphernode actor for managing ciphernode flow
let sortition = Sortition::attach(bus.clone());
CiphernodeSelector::attach(bus.clone(), sortition.clone(), addr);
Registry::attach(
bus.clone(),
rng,
Some(PublicKeyRegistry::attach(bus.clone(), sortition.clone())),
Some(PlaintextRegistry::attach(bus.clone(), sortition.clone())),
Some(CiphernodeRegistry::attach(bus.clone(), data, addr)),
)
.await;
Orchestrator::builder(bus.clone(), rng)
.public_key(PublicKeyOrchestrator::attach(
bus.clone(),
sortition.clone(),
))
.plaintext(PlaintextOrchestrator::attach(
bus.clone(),
sortition.clone(),
))
.ciphernode(CiphernodeOrchestrator::attach(bus.clone(), data, addr))
.build()
.await;
}

fn setup_bfv_params(
Expand Down
29 changes: 16 additions & 13 deletions packages/ciphernode/core/src/main_aggregator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::{Arc, Mutex};

use crate::{EventBus, P2p, PlaintextRegistry, PublicKeyRegistry, Registry, Sortition};
use crate::{EventBus, Orchestrator, P2p, PlaintextOrchestrator, PublicKeyOrchestrator, Sortition};
use actix::{Actor, Addr, Context};
use rand::SeedableRng;
use rand_chacha::rand_core::OsRng;
Expand All @@ -12,21 +12,21 @@ use tokio::task::JoinHandle;
pub struct MainAggregator {
bus: Addr<EventBus>,
sortition: Addr<Sortition>,
registry: Addr<Registry>,
orchestrator: Addr<Orchestrator>,
p2p: Addr<P2p>,
}

impl MainAggregator {
pub fn new(
bus: Addr<EventBus>,
sortition: Addr<Sortition>,
registry: Addr<Registry>,
orchestrator: Addr<Orchestrator>,
p2p: Addr<P2p>,
) -> Self {
Self {
bus,
sortition,
registry,
orchestrator,
p2p,
}
}
Expand All @@ -37,17 +37,20 @@ impl MainAggregator {
));
let bus = EventBus::new(true).start();
let sortition = Sortition::attach(bus.clone());
let registry = Registry::attach(
bus.clone(),
rng,
Some(PublicKeyRegistry::attach(bus.clone(), sortition.clone())),
Some(PlaintextRegistry::attach(bus.clone(), sortition.clone())),
None,
)
.await;
let orchestrator = Orchestrator::builder(bus.clone(), rng)
.public_key(PublicKeyOrchestrator::attach(
bus.clone(),
sortition.clone(),
))
.plaintext(PlaintextOrchestrator::attach(
bus.clone(),
sortition.clone(),
))
.build()
.await;
let (p2p_addr, join_handle) =
P2p::spawn_libp2p(bus.clone()).expect("Failed to setup libp2p");
let main_addr = MainAggregator::new(bus, sortition, registry, p2p_addr).start();
let main_addr = MainAggregator::new(bus, sortition, orchestrator, p2p_addr).start();
(main_addr, join_handle)
}
}
Expand Down
40 changes: 25 additions & 15 deletions packages/ciphernode/core/src/main_ciphernode.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::sync::{Arc, Mutex};

use crate::{CiphernodeRegistry, CiphernodeSelector, Data, EventBus, P2p, Registry, Sortition};
use crate::{
CiphernodeOrchestrator, CiphernodeSelector, Data, EventBus, Orchestrator, P2p, Sortition,
};
use actix::{Actor, Addr, Context};
use alloy_primitives::Address;
use rand::SeedableRng;
Expand All @@ -16,7 +18,7 @@ pub struct MainCiphernode {
data: Addr<Data>,
sortition: Addr<Sortition>,
selector: Addr<CiphernodeSelector>,
registry: Addr<Registry>,
orchestrator: Addr<Orchestrator>,
p2p: Addr<P2p>,
}

Expand All @@ -27,7 +29,7 @@ impl MainCiphernode {
data: Addr<Data>,
sortition: Addr<Sortition>,
selector: Addr<CiphernodeSelector>,
registry: Addr<Registry>,
orchestrator: Addr<Orchestrator>,
p2p: Addr<P2p>,
) -> Self {
Self {
Expand All @@ -36,7 +38,7 @@ impl MainCiphernode {
data,
sortition,
selector,
registry,
orchestrator,
p2p,
}
}
Expand All @@ -49,19 +51,27 @@ impl MainCiphernode {
let data = Data::new(true).start(); // TODO: Use a sled backed Data Actor
let sortition = Sortition::attach(bus.clone());
let selector = CiphernodeSelector::attach(bus.clone(), sortition.clone(), address);
let registry = Registry::attach(
bus.clone(),
rng,
None,
None,
Some(CiphernodeRegistry::attach(bus.clone(), data.clone(), address)),
)
.await;
let orchestrator = Orchestrator::builder(bus.clone(), rng)
.ciphernode(CiphernodeOrchestrator::attach(
bus.clone(),
data.clone(),
address,
))
.build()
.await;

let (p2p_addr, join_handle) =
P2p::spawn_libp2p(bus.clone()).expect("Failed to setup libp2p");
let main_addr =
MainCiphernode::new(address, bus, data, sortition, selector, registry, p2p_addr)
.start();
let main_addr = MainCiphernode::new(
address,
bus,
data,
sortition,
selector,
orchestrator,
p2p_addr,
)
.start();
(main_addr, join_handle)
}
}
Expand Down
Loading
Loading