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 logging #143

Merged
merged 6 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 9 additions & 0 deletions packages/ciphernode/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/ciphernode/aggregator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ bincode = { workspace = true }
enclave-core = { path = "../core" }
fhe = { path = "../fhe" }
sortition = { path = "../sortition" }
tracing = { workspace = true }
7 changes: 4 additions & 3 deletions packages/ciphernode/aggregator/src/plaintext_aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use enclave_core::{
use fhe::{Fhe, GetAggregatePlaintext};
use sortition::{GetHasNode, Sortition};
use std::sync::Arc;
use tracing::error;

#[derive(Debug, Clone)]
pub enum PlaintextAggregatorState {
Expand Down Expand Up @@ -124,7 +125,7 @@ impl Handler<DecryptionshareCreated> for PlaintextAggregator {
threshold_m, seed, ..
} = self.state
else {
println!("Aggregator has been closed for collecting.");
error!(state=?self.state, "Aggregator has been closed for collecting.");
return Box::pin(fut::ready(Ok(())));
};

Expand All @@ -144,12 +145,12 @@ impl Handler<DecryptionshareCreated> for PlaintextAggregator {
.map(move |res, act, ctx| {
let has_node = res?;
if !has_node {
println!("Node not found in committee"); // TODO: log properly
error!("Node not found in committee");
return Ok(());
}

if e3_id != act.e3_id {
println!("Wrong e3_id sent to aggregator. This should not happen.");
error!("Wrong e3_id sent to aggregator. This should not happen.");
return Ok(());
}

Expand Down
8 changes: 4 additions & 4 deletions packages/ciphernode/aggregator/src/publickey_aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use enclave_core::{
use fhe::{Fhe, GetAggregatePublicKey};
use sortition::{GetHasNode, GetNodes, Sortition};
use std::sync::Arc;
use tracing::error;

#[derive(Debug, Clone)]
pub enum PublicKeyAggregatorState {
Expand Down Expand Up @@ -132,8 +133,7 @@ impl Handler<KeyshareCreated> for PublicKeyAggregator {
threshold_m, seed, ..
} = self.state.clone()
else {
println!("Aggregator has been closed for collecting keyshares."); // TODO: log properly

error!(state=?self.state, "Aggregator has been closed for collecting keyshares.");
return Box::pin(fut::ready(Ok(())));
};

Expand All @@ -155,12 +155,12 @@ impl Handler<KeyshareCreated> for PublicKeyAggregator {
// we will not be doing a send
let has_node = res?;
if !has_node {
println!("Node not found in committee"); // TODO: log properly
error!("Node not found in committee");
return Ok(());
}

if e3_id != act.e3_id {
println!("Wrong e3_id sent to aggregator. This should not happen.");
error!("Wrong e3_id sent to aggregator. This should not happen.");
return Ok(());
}

Expand Down
124 changes: 116 additions & 8 deletions packages/ciphernode/core/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use actix::{Actor, Addr, Message};
use actix::Message;
use alloy::{
hex,
primitives::{Uint, U256},
Expand Down Expand Up @@ -69,7 +69,7 @@ impl EventId {
impl fmt::Display for EventId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let base58_string = bs58::encode(&self.0).into_string();
write!(f, "eid_{}", base58_string)
write!(f, "evt:{}", &base58_string[0..8])
}
}

Expand Down Expand Up @@ -183,6 +183,22 @@ impl EnclaveEvent {
_ => None,
}
}
pub fn get_data(&self) -> String {
match self.clone() {
EnclaveEvent::KeyshareCreated { data, .. } => format!("{}", data),
EnclaveEvent::E3Requested { data, .. } => format!("{}", data),
EnclaveEvent::PublicKeyAggregated { data, .. } => format!("{}", data),
EnclaveEvent::CiphertextOutputPublished { data, .. } => format!("{}", data),
EnclaveEvent::DecryptionshareCreated { data, .. } => format!("{}", data),
EnclaveEvent::PlaintextAggregated { data, .. } => format!("{}", data),
EnclaveEvent::CiphernodeSelected { data, .. } => format!("{}", data),
EnclaveEvent::CiphernodeAdded { data, .. } => format!("{}", data),
EnclaveEvent::CiphernodeRemoved { data, .. } => format!("{}", data),
EnclaveEvent::E3RequestComplete { data, .. } => format!("{}", data),
EnclaveEvent::EnclaveError { data, .. } => format!("{:?}", data),
// _ => "<omitted>".to_string(),
}
}
}

pub trait FromError {
Expand Down Expand Up @@ -299,7 +315,7 @@ impl FromError for EnclaveEvent {

impl fmt::Display for EnclaveEvent {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&format!("{}({})", self.event_type(), self.get_id()))
f.write_str(&format!("{}({})", self.event_type(), self.get_data()))
}
}

Expand All @@ -311,6 +327,12 @@ pub struct KeyshareCreated {
pub node: String,
}

impl Display for KeyshareCreated {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "e3_id: {}, node: {}", self.e3_id, self.node,)
}
}

#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[rtype(result = "anyhow::Result<()>")]
pub struct DecryptionshareCreated {
Expand All @@ -319,6 +341,12 @@ pub struct DecryptionshareCreated {
pub node: String,
}

impl Display for DecryptionshareCreated {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "e3_id: {}, node: {}", self.e3_id, self.node,)
}
}

#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[rtype(result = "()")]
pub struct PublicKeyAggregated {
Expand All @@ -328,18 +356,34 @@ pub struct PublicKeyAggregated {
pub src_chain_id: u64,
}

impl Display for PublicKeyAggregated {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"e3_id: {}, src_chain_id: {}, nodes: <omitted>, pubkey: <omitted>",
self.e3_id, self.src_chain_id,
)
}
}

#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[rtype(result = "()")]
pub struct E3Requested {
pub e3_id: E3id,
pub threshold_m: usize,
pub seed: Seed,
pub params: Vec<u8>,
pub src_chain_id: u64, // threshold: usize, // TODO:
// computation_type: ??, // TODO:
// execution_model_type: ??, // TODO:
// input_deadline: ??, // TODO:
// availability_duration: ??, // TODO:
pub src_chain_id: u64,
}

impl Display for E3Requested {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"e3_id: {}, threshold_m: {}, src_chain_id: {}, seed: {}, params: <omitted>",
self.e3_id, self.threshold_m, self.src_chain_id, self.seed
)
}
}

#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
Expand All @@ -349,13 +393,29 @@ pub struct CiphernodeSelected {
pub threshold_m: usize,
}

impl Display for CiphernodeSelected {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"e3_id: {}, threshold_m: {}",
self.e3_id, self.threshold_m,
)
}
}

#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[rtype(result = "()")]
pub struct CiphertextOutputPublished {
pub e3_id: E3id,
pub ciphertext_output: Vec<u8>,
}

impl Display for CiphertextOutputPublished {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "e3_id: {}", self.e3_id,)
}
}

#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[rtype(result = "()")]
pub struct PlaintextAggregated {
Expand All @@ -364,13 +424,29 @@ pub struct PlaintextAggregated {
pub src_chain_id: u64,
}

impl Display for PlaintextAggregated {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"e3_id: {}, src_chain_id: {}",
self.e3_id, self.src_chain_id
)
}
}

/// E3RequestComplete event is a local only event
#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[rtype(result = "()")]
pub struct E3RequestComplete {
pub e3_id: E3id,
}

impl Display for E3RequestComplete {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "e3_id: {}", self.e3_id)
}
}

#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[rtype(result = "()")]
pub struct CiphernodeAdded {
Expand All @@ -379,6 +455,16 @@ pub struct CiphernodeAdded {
pub num_nodes: usize,
}

impl Display for CiphernodeAdded {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"address: {}, index: {}, num_nodes: {}",
self.address, self.index, self.num_nodes
)
}
}

#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[rtype(result = "()")]
pub struct CiphernodeRemoved {
Expand All @@ -387,16 +473,37 @@ pub struct CiphernodeRemoved {
pub num_nodes: usize,
}

impl Display for CiphernodeRemoved {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"address: {}, index: {}, num_nodes: {}",
self.address, self.index, self.num_nodes
)
}
}

#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[rtype(result = "()")]
pub struct EnclaveError {
pub err_type: EnclaveErrorType,
pub message: String,
}

impl Display for EnclaveError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}

#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[rtype(result = "()")]
pub struct Die;
impl Display for Die {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Die",)
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Seed(pub [u8; 32]);
Expand Down Expand Up @@ -432,6 +539,7 @@ pub enum EnclaveErrorType {
IO,
PlaintextAggregation,
Decryption,
Sortition,
}

impl EnclaveError {
Expand Down
2 changes: 2 additions & 0 deletions packages/ciphernode/enclave/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ clap = { workspace = true }
actix-rt = { workspace = true }
tokio = { workspace = true }
config = "0.14.0"
tracing-subscriber = { workspace = true }
tracing = { workspace = true }
4 changes: 3 additions & 1 deletion packages/ciphernode/enclave/src/bin/aggregator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clap::Parser;
use enclave::load_config;
use enclave_node::MainAggregator;
use tracing::info;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
Expand All @@ -18,8 +19,9 @@ struct Args {

#[actix_rt::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();
let args = Args::parse();
println!("LAUNCHING AGGREGATOR");
info!("LAUNCHING AGGREGATOR");
let config = load_config(&args.config)?;
let (_, handle) = MainAggregator::attach(
config,
Expand Down
Loading
Loading