From b61b2be0d4d4633cba9a01640b0d82dc8571955d Mon Sep 17 00:00:00 2001 From: Aaron Blankstein Date: Fri, 8 Mar 2024 21:58:00 -0600 Subject: [PATCH] logs: signer block responses to info. display formatting for block response --- libsigner/src/messages.rs | 21 +++++++++++++++++++++ stacks-signer/src/signer.rs | 11 +++++++---- stackslib/src/chainstate/stacks/mod.rs | 6 ++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/libsigner/src/messages.rs b/libsigner/src/messages.rs index 6135312a8..debb43218 100644 --- a/libsigner/src/messages.rs +++ b/libsigner/src/messages.rs @@ -823,6 +823,27 @@ pub enum BlockResponse { Rejected(BlockRejection), } +impl std::fmt::Display for BlockResponse { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + BlockResponse::Accepted(a) => { + write!( + f, + "BlockAccepted: signer_sighash = {}, signature = {}", + a.0, a.1 + ) + } + BlockResponse::Rejected(r) => { + write!( + f, + "BlockRejected: signer_sighash = {}, code = {}, reason = {}", + r.reason_code, r.reason, r.signer_signature_hash + ) + } + } + } +} + impl BlockResponse { /// Create a new accepted BlockResponse for the provided block signer signature hash and signature pub fn accepted(hash: Sha512Trunc256Sum, sig: Signature) -> Self { diff --git a/stacks-signer/src/signer.rs b/stacks-signer/src/signer.rs index 4159eedf3..e7d78637d 100644 --- a/stacks-signer/src/signer.rs +++ b/stacks-signer/src/signer.rs @@ -989,15 +989,18 @@ impl Signer { let block_submission = if block_vote.rejected { // We signed a rejection message. Return a rejection message - BlockResponse::rejected(block_vote.signer_signature_hash, signature.clone()).into() + BlockResponse::rejected(block_vote.signer_signature_hash, signature.clone()) } else { // we agreed to sign the block hash. Return an approval message - BlockResponse::accepted(block_vote.signer_signature_hash, signature.clone()).into() + BlockResponse::accepted(block_vote.signer_signature_hash, signature.clone()) }; // Submit signature result to miners to observe - debug!("{self}: submit block response {block_submission:?}"); - if let Err(e) = self.stackerdb.send_message_with_retry(block_submission) { + info!("{self}: Submit block response: {block_submission}"); + if let Err(e) = self + .stackerdb + .send_message_with_retry(block_submission.into()) + { warn!("{self}: Failed to send block submission to stacker-db: {e:?}"); } } diff --git a/stackslib/src/chainstate/stacks/mod.rs b/stackslib/src/chainstate/stacks/mod.rs index 7247a28f7..f9ad4fff3 100644 --- a/stackslib/src/chainstate/stacks/mod.rs +++ b/stackslib/src/chainstate/stacks/mod.rs @@ -693,6 +693,12 @@ impl FromSql for ThresholdSignature { } } +impl fmt::Display for ThresholdSignature { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + to_hex(&self.serialize_to_vec()).fmt(f) + } +} + impl ToSql for ThresholdSignature { fn to_sql(&self) -> rusqlite::Result { let bytes = self.serialize_to_vec();