Skip to content

Commit

Permalink
Extract router
Browse files Browse the repository at this point in the history
  • Loading branch information
ryardley committed Oct 3, 2024
1 parent 7b8ed9c commit 57e0777
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 32 deletions.
6 changes: 0 additions & 6 deletions packages/ciphernode/core/src/enclave_core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
mod events;
mod eventbus;
mod ordered_set;
mod e3_request_router;
mod committee_meta;
mod ciphernode_selector;

pub use events::*;
pub use eventbus::*;
pub use ordered_set::*;
pub use e3_request_router::*;
pub use committee_meta::*;
pub use ciphernode_selector::*;

6 changes: 3 additions & 3 deletions packages/ciphernode/core/src/enclave_node/main_aggregator.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::{
enclave_core::{EventBus,CommitteeMetaFactory, E3RequestRouter},
enclave_core::EventBus,
evm::{connect_evm_caller, connect_evm_ciphernode_registry, connect_evm_enclave},
fhe::FheFactory,
logger::SimpleLogger,
p2p::P2p,
plaintext_aggregator::PlaintextAggregatorFactory,
publickey_aggregator::PublicKeyAggregatorFactory,
router::{CommitteeMetaFactory, E3RequestRouter},
sortition::Sortition,
utils::PlaintextWriter,
utils::PublicKeyWriter,
utils::{PlaintextWriter, PublicKeyWriter},
};
use actix::{Actor, Addr, Context};
use alloy::primitives::Address;
Expand Down
9 changes: 1 addition & 8 deletions packages/ciphernode/core/src/enclave_node/main_ciphernode.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
use crate::{
data::Data,
enclave_core::{CiphernodeSelector, CommitteeMetaFactory, E3RequestRouter, EventBus},
evm::{connect_evm_ciphernode_registry, connect_evm_enclave},
fhe::FheFactory,
keyshare::KeyshareFactory,
logger::SimpleLogger,
p2p::P2p,
sortition::Sortition,
data::Data, enclave_core::EventBus, evm::{connect_evm_ciphernode_registry, connect_evm_enclave}, fhe::FheFactory, keyshare::KeyshareFactory, logger::SimpleLogger, p2p::P2p, router::{CiphernodeSelector, CommitteeMetaFactory, E3RequestRouter}, sortition::Sortition
};
use actix::{Actor, Addr, Context};
use alloy::primitives::Address;
Expand Down
2 changes: 1 addition & 1 deletion packages/ciphernode/core/src/fhe/fhe.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::set_up_crp;
use crate::enclave_core::{E3Requested, EnclaveEvent, EventHook, OrderedSet, Seed};
use crate::{enclave_core::{E3Requested, EnclaveEvent,OrderedSet, Seed}, router::EventHook};
use anyhow::*;
use fhe::{
bfv::{
Expand Down
4 changes: 1 addition & 3 deletions packages/ciphernode/core/src/fhe/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use fhe::{
mbfv::CommonRandomPoly,
};
use fhe_traits::{Deserialize, Serialize};
use std::{fs, io::Write, path::Path, sync::Arc};
use std::sync::Arc;

use super::SharedRng;

Expand Down Expand Up @@ -59,5 +59,3 @@ pub fn decode_params(bytes: &[u8]) -> Result<Arc<BfvParameters>> {
pub fn set_up_crp(params: Arc<BfvParameters>, rng: SharedRng) -> CommonRandomPoly {
CommonRandomPoly::new(&params, &mut *rng.lock().unwrap()).unwrap()
}


4 changes: 3 additions & 1 deletion packages/ciphernode/core/src/keyshare/keyshare.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::{
data::{Data, Get, Insert},
enclave_core::{
CiphernodeSelected, CiphertextOutputPublished, DecryptionshareCreated, EnclaveErrorType, EnclaveEvent, EventBus, EventHook, FromError, KeyshareCreated
CiphernodeSelected, CiphertextOutputPublished, DecryptionshareCreated, EnclaveErrorType,
EnclaveEvent, EventBus, FromError, KeyshareCreated,
},
fhe::{DecryptCiphertext, Fhe},
router::EventHook,
};
use actix::prelude::*;
use anyhow::{anyhow, Context, Result};
Expand Down
9 changes: 5 additions & 4 deletions packages/ciphernode/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod logger;
mod p2p;
mod plaintext_aggregator;
mod publickey_aggregator;
mod router;
mod sortition;
mod utils;

Expand All @@ -26,17 +27,17 @@ mod tests {
use crate::{
data::Data,
enclave_core::{
CiphernodeAdded, CiphernodeSelected, CiphernodeSelector, CiphertextOutputPublished,
CommitteeMetaFactory, DecryptionshareCreated, E3RequestRouter, E3Requested, E3id,
EnclaveEvent, EventBus, GetHistory, KeyshareCreated, PlaintextAggregated,
PublicKeyAggregated, ResetHistory, Seed,
CiphernodeAdded, CiphernodeSelected, CiphertextOutputPublished, DecryptionshareCreated,
E3Requested, E3id, EnclaveEvent, EventBus, GetHistory, KeyshareCreated,
PlaintextAggregated, PublicKeyAggregated, ResetHistory, Seed,
},
fhe::{setup_crp_params, FheFactory, ParamsWithCrp, SharedRng},
keyshare::KeyshareFactory,
logger::SimpleLogger,
p2p::P2p,
plaintext_aggregator::PlaintextAggregatorFactory,
publickey_aggregator::PublicKeyAggregatorFactory,
router::{CiphernodeSelector, CommitteeMetaFactory, E3RequestRouter},
sortition::Sortition,
};
use actix::prelude::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{
enclave_core::{
DecryptionshareCreated, E3id, EnclaveEvent, EventBus, EventHook, OrderedSet,
PlaintextAggregated, Seed,
DecryptionshareCreated, E3id, EnclaveEvent, EventBus, OrderedSet, PlaintextAggregated, Seed,
},
fhe::{Fhe, GetAggregatePlaintext},
router::EventHook,
sortition::{GetHasNode, Sortition},
};
use actix::prelude::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{
enclave_core::{
E3id, EnclaveEvent, EventBus, EventHook, KeyshareCreated, OrderedSet, PublicKeyAggregated,
Seed,
E3id, EnclaveEvent, EventBus, KeyshareCreated, OrderedSet, PublicKeyAggregated, Seed,
},
fhe::{Fhe, GetAggregatePublicKey},
router::EventHook,
sortition::{GetHasNode, Sortition},
};
use actix::prelude::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// CiphernodeSelector is an actor that determines if a ciphernode
/// CiphernodeSelector is an actor that determines if a ciphernode is part of a committee and if so
/// forwards a CiphernodeSelected event to the event bus
use actix::prelude::*;
use crate::{enclave_core::{CiphernodeSelected, EnclaveEvent, EventBus, Subscribe}, sortition::{GetHasNode, Sortition}};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use actix::{Actor, Addr, Context, Handler, Recipient};
use crate::{enclave_core::{E3id, EnclaveEvent, EventBus, Subscribe}, fhe::Fhe, keyshare::Keyshare, plaintext_aggregator::PlaintextAggregator, publickey_aggregator::PublicKeyAggregator};
use super::CommitteeMeta;


/// Helper class to buffer events for downstream instances incase events arrive in the wrong order
#[derive(Default)]
struct EventBuffer {
buffer: HashMap<String, Vec<EnclaveEvent>>,
Expand All @@ -22,6 +24,8 @@ impl EventBuffer {
}
}

/// Context that is set to each event hook. Hooks can use this context to gather dependencies if
/// they need to instantiate struct instances or actors.
#[derive(Default)]
pub struct E3RequestContext {
pub keyshare: Option<Addr<Keyshare>>,
Expand Down Expand Up @@ -109,7 +113,7 @@ impl Handler<EnclaveEvent> for E3RequestRouter {
}
}


/// Builder for E3RequestRouter
pub struct E3RequestRouterBuilder {
pub bus: Addr<EventBus>,
pub hooks: Vec<EventHook>,
Expand Down
7 changes: 7 additions & 0 deletions packages/ciphernode/core/src/router/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mod ciphernode_selector;
mod committee_meta;
mod e3_request_router;

pub use ciphernode_selector::*;
pub use committee_meta::*;
pub use e3_request_router::*;

0 comments on commit 57e0777

Please sign in to comment.