From 1117c3d2a9adf578342bbde60336129d0201c417 Mon Sep 17 00:00:00 2001 From: Hank Stoever Date: Mon, 18 Nov 2024 08:23:50 -0800 Subject: [PATCH] fix: better error logging with signerdb insert error --- stacks-signer/src/v0/signer.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/stacks-signer/src/v0/signer.rs b/stacks-signer/src/v0/signer.rs index 081d8b6a6b..0867b4d5a7 100644 --- a/stacks-signer/src/v0/signer.rs +++ b/stacks-signer/src/v0/signer.rs @@ -21,6 +21,7 @@ use blockstack_lib::chainstate::nakamoto::{NakamotoBlock, NakamotoBlockHeader}; use blockstack_lib::net::api::postblock_proposal::{ BlockValidateOk, BlockValidateReject, BlockValidateResponse, }; +use blockstack_lib::util_lib::db::Error as DBError; use clarity::types::chainstate::StacksPrivateKey; use clarity::types::{PrivateKey, StacksEpochId}; use clarity::util::hash::MerkleHashFunc; @@ -496,7 +497,7 @@ impl Signer { // Do not store KNOWN invalid blocks as this could DOS the signer. We only store blocks that are valid or unknown. self.signer_db .insert_block(&block_info) - .unwrap_or_else(|_| panic!("{self}: Failed to insert block in DB")); + .unwrap_or_else(|e| self.handle_insert_block_error(e)); } } @@ -568,7 +569,7 @@ impl Signer { self.signer_db .insert_block(&block_info) - .unwrap_or_else(|_| panic!("{self}: Failed to insert block in DB")); + .unwrap_or_else(|e| self.handle_insert_block_error(e)); let accepted = BlockAccepted::new(block_info.signer_signature_hash(), signature); // have to save the signature _after_ the block info self.handle_block_signature(stacks_client, &accepted); @@ -626,7 +627,7 @@ impl Signer { ); self.signer_db .insert_block(&block_info) - .unwrap_or_else(|_| panic!("{self}: Failed to insert block in DB")); + .unwrap_or_else(|e| self.handle_insert_block_error(e)); self.handle_block_rejection(&block_rejection); Some(BlockResponse::Rejected(block_rejection)) } @@ -739,7 +740,7 @@ impl Signer { } self.signer_db .insert_block(&block_info) - .unwrap_or_else(|_| panic!("{self}: Failed to insert block in DB")); + .unwrap_or_else(|e| self.handle_insert_block_error(e)); } /// Compute the signing weight, given a list of signatures @@ -1095,7 +1096,7 @@ impl Signer { // in case this is the first time we saw this block. Safe to do since this is testing case only. self.signer_db .insert_block(block_info) - .unwrap_or_else(|_| panic!("{self}: Failed to insert block in DB")); + .unwrap_or_else(|e| self.handle_insert_block_error(e)); Some(BlockResponse::rejected( block_proposal.block.header.signer_signature_hash(), RejectCode::TestingDirective, @@ -1119,4 +1120,10 @@ impl Signer { warn!("{self}: Failed to send mock signature to stacker-db: {e:?}",); } } + + /// Helper for logging insert_block error + fn handle_insert_block_error(&self, e: DBError) { + error!("{self}: Failed to insert block into signer-db: {e:?}"); + panic!("{self} Failed to write block to signerdb: {e}"); + } }