Skip to content

Commit 7cd921e

Browse files
committed
CRC: pass block info as an optonal to send_block_response_impl
Signed-off-by: Jacinta Ferrant <jacinta.ferrant@gmail.com>
1 parent 3dde4d8 commit 7cd921e

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

stacks-signer/src/v0/signer.rs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -665,12 +665,15 @@ impl Signer {
665665

666666
/// The actual `send_block_response` implementation. Declared so that we do
667667
/// not need to duplicate in testing.
668-
fn impl_send_block_response(&mut self, block_response: BlockResponse) {
668+
fn impl_send_block_response(
669+
&mut self,
670+
block: Option<&NakamotoBlock>,
671+
block_response: BlockResponse,
672+
) {
669673
info!(
670674
"{self}: Broadcasting a block response to stacks node: {block_response:?}";
671675
);
672676
let accepted = matches!(block_response, BlockResponse::Accepted(..));
673-
let block_hash = block_response.get_signer_signature_hash();
674677
match self
675678
.stackerdb
676679
.send_message_with_retry::<SignerMessage>(block_response.into())
@@ -683,8 +686,8 @@ impl Signer {
683686
);
684687
}
685688
crate::monitoring::actions::increment_block_responses_sent(accepted);
686-
if let Ok(Some(block_info)) = self.signer_db.block_lookup(&block_hash) {
687-
crate::monitoring::actions::record_block_response_latency(&block_info.block);
689+
if let Some(block) = block {
690+
crate::monitoring::actions::record_block_response_latency(block);
688691
}
689692
}
690693
Err(e) => {
@@ -694,7 +697,11 @@ impl Signer {
694697
}
695698

696699
#[cfg(any(test, feature = "testing"))]
697-
fn send_block_response(&mut self, block_response: BlockResponse) {
700+
fn send_block_response(
701+
&mut self,
702+
block: Option<&NakamotoBlock>,
703+
block_response: BlockResponse,
704+
) {
698705
const NUM_REPEATS: usize = 1;
699706
let mut count = 0;
700707
let public_keys = TEST_REPEAT_PROPOSAL_RESPONSE.get();
@@ -704,16 +711,20 @@ impl Signer {
704711
count = NUM_REPEATS;
705712
}
706713
while count <= NUM_REPEATS {
707-
self.impl_send_block_response(block_response.clone());
714+
self.impl_send_block_response(block, block_response.clone());
708715

709716
count += 1;
710717
sleep_ms(1000);
711718
}
712719
}
713720

714721
#[cfg(not(any(test, feature = "testing")))]
715-
fn send_block_response(&mut self, block_response: BlockResponse) {
716-
self.impl_send_block_response(block_response)
722+
fn send_block_response(
723+
&mut self,
724+
block: &Option<NakamotoBlock>,
725+
block_response: BlockResponse,
726+
) {
727+
self.impl_send_block_response(block, block_response)
717728
}
718729

719730
/// Handle signer state update message
@@ -842,7 +853,7 @@ impl Signer {
842853

843854
if let Some(block_response) = block_response {
844855
// We know proposal is invalid. Send rejection message, do not do further validation and do not store it.
845-
self.send_block_response(block_response);
856+
self.send_block_response(Some(&block_info.block), block_response);
846857
} else {
847858
// Just in case check if the last block validation submission timed out.
848859
self.check_submitted_block_proposal();
@@ -896,7 +907,7 @@ impl Signer {
896907
return;
897908
};
898909

899-
self.impl_send_block_response(block_response);
910+
self.impl_send_block_response(Some(&block_info.block), block_response);
900911
}
901912

902913
/// Handle block response messages from a signer
@@ -1032,7 +1043,7 @@ impl Signer {
10321043
warn!("{self}: Failed to mark block as locally rejected: {e:?}");
10331044
}
10341045
};
1035-
self.impl_send_block_response(block_response);
1046+
self.impl_send_block_response(Some(&block_info.block), block_response);
10361047
self.signer_db
10371048
.insert_block(&block_info)
10381049
.unwrap_or_else(|e| self.handle_insert_block_error(e));
@@ -1139,7 +1150,12 @@ impl Signer {
11391150
.unwrap_or_else(|e| warn!("{self}: Failed to remove pending block validation: {e:?}"));
11401151

11411152
if let Some(response) = block_response {
1142-
self.impl_send_block_response(response);
1153+
let block = self
1154+
.signer_db
1155+
.block_lookup(&signer_sig_hash)
1156+
.unwrap_or_default()
1157+
.map(|info| info.block);
1158+
self.impl_send_block_response(block.as_ref(), response);
11431159
};
11441160

11451161
// Check if there is a pending block validation that we need to submit to the node
@@ -1232,7 +1248,7 @@ impl Signer {
12321248
warn!("{self}: Failed to mark block as locally rejected: {e:?}");
12331249
}
12341250
};
1235-
self.impl_send_block_response(rejection);
1251+
self.impl_send_block_response(Some(&block_info.block), rejection);
12361252

12371253
self.signer_db
12381254
.insert_block(&block_info)

0 commit comments

Comments
 (0)