@@ -21,6 +21,7 @@ use blockstack_lib::chainstate::nakamoto::{NakamotoBlock, NakamotoBlockHeader};
21
21
use blockstack_lib:: net:: api:: postblock_proposal:: {
22
22
BlockValidateOk , BlockValidateReject , BlockValidateResponse ,
23
23
} ;
24
+ use blockstack_lib:: util_lib:: db:: Error as DBError ;
24
25
use clarity:: types:: chainstate:: StacksPrivateKey ;
25
26
use clarity:: types:: { PrivateKey , StacksEpochId } ;
26
27
use clarity:: util:: hash:: MerkleHashFunc ;
@@ -496,7 +497,7 @@ impl Signer {
496
497
// Do not store KNOWN invalid blocks as this could DOS the signer. We only store blocks that are valid or unknown.
497
498
self . signer_db
498
499
. insert_block ( & block_info)
499
- . unwrap_or_else ( |_| panic ! ( "{ self}: Failed to insert block in DB" ) ) ;
500
+ . unwrap_or_else ( |e| self . handle_insert_block_error ( e ) ) ;
500
501
}
501
502
}
502
503
@@ -568,7 +569,7 @@ impl Signer {
568
569
569
570
self . signer_db
570
571
. insert_block ( & block_info)
571
- . unwrap_or_else ( |_| panic ! ( "{ self}: Failed to insert block in DB" ) ) ;
572
+ . unwrap_or_else ( |e| self . handle_insert_block_error ( e ) ) ;
572
573
let accepted = BlockAccepted :: new ( block_info. signer_signature_hash ( ) , signature) ;
573
574
// have to save the signature _after_ the block info
574
575
self . handle_block_signature ( stacks_client, & accepted) ;
@@ -626,7 +627,7 @@ impl Signer {
626
627
) ;
627
628
self . signer_db
628
629
. insert_block ( & block_info)
629
- . unwrap_or_else ( |_| panic ! ( "{ self}: Failed to insert block in DB" ) ) ;
630
+ . unwrap_or_else ( |e| self . handle_insert_block_error ( e ) ) ;
630
631
self . handle_block_rejection ( & block_rejection) ;
631
632
Some ( BlockResponse :: Rejected ( block_rejection) )
632
633
}
@@ -739,7 +740,7 @@ impl Signer {
739
740
}
740
741
self . signer_db
741
742
. insert_block ( & block_info)
742
- . unwrap_or_else ( |_| panic ! ( "{ self}: Failed to insert block in DB" ) ) ;
743
+ . unwrap_or_else ( |e| self . handle_insert_block_error ( e ) ) ;
743
744
}
744
745
745
746
/// Compute the signing weight, given a list of signatures
@@ -1095,7 +1096,7 @@ impl Signer {
1095
1096
// in case this is the first time we saw this block. Safe to do since this is testing case only.
1096
1097
self . signer_db
1097
1098
. insert_block ( block_info)
1098
- . unwrap_or_else ( |_| panic ! ( "{ self}: Failed to insert block in DB" ) ) ;
1099
+ . unwrap_or_else ( |e| self . handle_insert_block_error ( e ) ) ;
1099
1100
Some ( BlockResponse :: rejected (
1100
1101
block_proposal. block . header . signer_signature_hash ( ) ,
1101
1102
RejectCode :: TestingDirective ,
@@ -1119,4 +1120,10 @@ impl Signer {
1119
1120
warn ! ( "{self}: Failed to send mock signature to stacker-db: {e:?}" , ) ;
1120
1121
}
1121
1122
}
1123
+
1124
+ /// Helper for logging insert_block error
1125
+ fn handle_insert_block_error ( & self , e : DBError ) {
1126
+ error ! ( "{self}: Failed to insert block into signer-db: {e:?}" ) ;
1127
+ panic ! ( "{self} Failed to write block to signerdb: {e}" ) ;
1128
+ }
1122
1129
}
0 commit comments