logs: signer block responses to info. display formatting for block response

This commit is contained in:
Aaron Blankstein
2024-03-08 21:58:00 -06:00
parent 18ad72429d
commit b61b2be0d4
3 changed files with 34 additions and 4 deletions

View File

@@ -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 {

View File

@@ -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:?}");
}
}

View File

@@ -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<ToSqlOutput> {
let bytes = self.serialize_to_vec();