Skip to content

Commit

Permalink
tss crate structured logs (#977)
Browse files Browse the repository at this point in the history
  • Loading branch information
4meta5 authored Jul 11, 2024
1 parent 2ce1751 commit 9622ae2
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions tss/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use frost_evm::Scalar;
use rand_core::OsRng;
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet};
use tracing::field;

pub use frost_evm::frost_core::keys::sum_commitments;
pub use frost_evm::frost_secp256k1::Signature as ProofOfKnowledge;
Expand Down Expand Up @@ -122,12 +123,12 @@ where
let coordinators: BTreeSet<_> =
members.iter().copied().take(members.len() - threshold as usize + 1).collect();
let is_coordinator = coordinators.contains(&frost_id);
tracing::debug!(
"{} initialize {}/{} coordinator = {}",
peer_id,
tracing::info!(
peer_id = field::display(peer_id.clone()),
"initialize {}/{} coordinator = {}",
threshold,
members.len(),
is_coordinator
is_coordinator,
);
let committed = recover.is_some();
Self {
Expand Down Expand Up @@ -174,7 +175,10 @@ where
}

pub fn on_message(&mut self, peer_id: P, msg: TssMessage<I>) -> Result<()> {
tracing::debug!("{} on_message {} {}", self.peer_id, peer_id, msg);
tracing::info!(
peer_id = field::display(self.peer_id.clone()),
"on_message from peer_id={peer_id} msg={msg}",
);
if self.peer_id == peer_id {
anyhow::bail!("{} received message from self", self.peer_id);
}
Expand All @@ -201,7 +205,7 @@ where
}

pub fn on_commit(&mut self, commitment: VerifiableSecretSharingCommitment) {
tracing::debug!("{} commit", self.peer_id);
tracing::info!(peer_id = field::display(self.peer_id.clone()), "commit",);
match &mut self.state {
TssState::Dkg(dkg) => {
dkg.on_commit(commitment);
Expand Down Expand Up @@ -232,14 +236,14 @@ where
}

pub fn on_start(&mut self, id: I) {
tracing::info!("{} start {}", self.peer_id, id);
tracing::info!(peer_id = field::display(self.peer_id.clone()), "start {}", id);
if self.get_or_insert_session(id).is_none() {
tracing::error!("not ready to sign");
}
}

pub fn on_sign(&mut self, id: I, data: Vec<u8>) {
tracing::debug!("{} sign {}", self.peer_id, id);
tracing::info!(peer_id = field::display(self.peer_id.clone()), "sign {}", id);
if let Some(session) = self.get_or_insert_session(id) {
session.set_data(data)
} else {
Expand All @@ -248,7 +252,7 @@ where
}

pub fn on_complete(&mut self, id: I) {
tracing::debug!("{} complete {}", self.peer_id, id);
tracing::info!(peer_id = field::display(self.peer_id.clone()), "complete {}", id);
match &mut self.state {
TssState::Roast { signing_sessions, .. } => {
signing_sessions.remove(&id);
Expand Down

0 comments on commit 9622ae2

Please sign in to comment.