Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better error logging with signerdb insert error #5475

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}");
}
}