Skip to content

Commit

Permalink
Merge pull request #5475 from stacks-network/fix/better-signerdb-erro…
Browse files Browse the repository at this point in the history
…r-logging

fix: better error logging with signerdb insert error
  • Loading branch information
hstove authored Nov 18, 2024
2 parents bac1b07 + 1117c3d commit dbfd363
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions stacks-signer/src/v0/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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}");
}
}

0 comments on commit dbfd363

Please sign in to comment.