Skip to content

Commit b32df68

Browse files
committed
Cleanup comments and remove unnecessary clone
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 3927998 commit b32df68

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

stacks-signer/src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub struct GlobalConfig {
161161
pub block_proposal_timeout: Duration,
162162
/// An optional custom Chain ID
163163
pub chain_id: Option<u32>,
164-
/// How long to wait for a response from a block proposal validation response from the node
164+
/// How long to wait in for a response from a block proposal validation response from the node
165165
/// before marking that block as invalid and rejecting it
166166
pub block_proposal_validation_timeout: Duration,
167167
}
@@ -193,8 +193,8 @@ struct RawConfigFile {
193193
pub block_proposal_timeout_ms: Option<u64>,
194194
/// An optional custom Chain ID
195195
pub chain_id: Option<u32>,
196-
/// How long to wait for a response from a block proposal validation response from the node
197-
/// before marking that block as invalid and rejecting it in milliseconds.
196+
/// How long to wait n milliseconds for a response from a block proposal validation response from the node
197+
/// before marking that block as invalid and rejecting it
198198
pub block_proposal_validation_timeout_ms: Option<u64>,
199199
}
200200

stacks-signer/src/v0/signer.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -670,17 +670,15 @@ impl Signer {
670670
/// Check the current tracked submitted block proposal to see if it has timed out.
671671
/// Broadcasts a rejection and marks the block locally rejected if it has.
672672
fn check_submitted_block_proposal(&mut self) {
673-
let Some((block_proposal, block_submission)) = self.submitted_block_proposal.clone() else {
673+
let Some((block_proposal, block_submission)) = self.submitted_block_proposal.take() else {
674674
// Nothing to check.
675675
return;
676676
};
677677
if block_submission.elapsed() < self.block_proposal_validation_timeout {
678-
// Not expired yet.
678+
// Not expired yet. Put it back!
679+
self.submitted_block_proposal = Some((block_proposal, block_submission));
679680
return;
680681
}
681-
// Let us immediately flush, even if we later encounter an error broadcasting our responses.
682-
// We should still attempt to handle a new proposal at this point.
683-
self.submitted_block_proposal = None;
684682
let signature_sighash = block_proposal.block.header.signer_signature_hash();
685683
// For mutability reasons, we need to take the block_info out of the map and add it back after processing
686684
let mut block_info = match self
@@ -710,6 +708,8 @@ impl Signer {
710708
return;
711709
}
712710
};
711+
// We cannot determine the validity of the block, but we have not reached consensus on it yet.
712+
// Reject it so we aren't holding up the network because of our inaction.
713713
warn!(
714714
"{self}: Failed to receive block validation response within {} ms. Rejecting block.", self.block_proposal_validation_timeout.as_millis();
715715
"signer_sighash" => %signature_sighash,
@@ -721,7 +721,6 @@ impl Signer {
721721
&self.private_key,
722722
self.mainnet,
723723
);
724-
// We know proposal is invalid. Send rejection message, do not do further validation
725724
if let Err(e) = block_info.mark_locally_rejected() {
726725
warn!("{self}: Failed to mark block as locally rejected: {e:?}",);
727726
};
@@ -855,6 +854,7 @@ impl Signer {
855854
.map(|(proposal, _)| &proposal.block.header.signer_signature_hash() == block_hash)
856855
.unwrap_or(false)
857856
{
857+
// Consensus reached! No longer bother tracking its validation submission to the node as we are too late to participate in the decision anyway.
858858
self.submitted_block_proposal = None;
859859
}
860860
}
@@ -1005,6 +1005,7 @@ impl Signer {
10051005
.map(|(proposal, _)| &proposal.block.header.signer_signature_hash() == block_hash)
10061006
.unwrap_or(false)
10071007
{
1008+
// Consensus reached! No longer bother tracking its validation submission to the node as we are too late to participate in the decision anyway.
10081009
self.submitted_block_proposal = None;
10091010
}
10101011
}

testnet/stacks-node/src/tests/signer/v0.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5608,7 +5608,9 @@ fn multiple_miners_with_custom_chain_id() {
56085608
signer_test.shutdown();
56095609
}
56105610

5611-
// Teimout a block validation response
5611+
// Ensures that a signer will issue ConnectivityIssues rejections if a block submission
5612+
// times out. Also ensures that no other proposal gets submitted for validation if we
5613+
// are already waiting for a block submission response.
56125614
#[test]
56135615
#[ignore]
56145616
fn block_validation_response_timeout() {
@@ -5732,11 +5734,12 @@ fn block_validation_response_timeout() {
57325734
};
57335735
// We are waiting for the original block proposal which will have a diff signature to our
57345736
// second proposed block.
5735-
if signer_signature_hash != block_signer_signature_hash_1 {
5737+
assert_ne!(
5738+
signer_signature_hash, block_signer_signature_hash_1,
5739+
"Received a rejection for the wrong block"
5740+
);
5741+
if matches!(reason_code, RejectCode::ConnectivityIssues) {
57365742
rejected_signers.push(signature);
5737-
if matches!(reason_code, RejectCode::ConnectivityIssues) {
5738-
break;
5739-
}
57405743
}
57415744
}
57425745
assert!(

0 commit comments

Comments
 (0)