Skip to content

Commit c436e0e

Browse files
committed
refactor: info/warn instead of debug, and short return for invalid sig
1 parent 3150d4c commit c436e0e

File tree

1 file changed

+41
-40
lines changed

1 file changed

+41
-40
lines changed

testnet/stacks-node/src/nakamoto_node/sign_coordinator.rs

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -738,22 +738,6 @@ impl SignCoordinator {
738738

739739
let start_ts = Instant::now();
740740
while start_ts.elapsed() <= self.signing_round_timeout {
741-
// one of two things can happen:
742-
// * we get enough signatures from stackerdb from the signers, OR
743-
// * we see our block get processed in our chainstate (meaning, the signers broadcasted
744-
// the block and our node got it and processed it)
745-
let event = match receiver.recv_timeout(EVENT_RECEIVER_POLL) {
746-
Ok(event) => event,
747-
Err(std::sync::mpsc::RecvTimeoutError::Timeout) => {
748-
continue;
749-
}
750-
Err(std::sync::mpsc::RecvTimeoutError::Disconnected) => {
751-
return Err(NakamotoNodeError::SigningCoordinatorFailure(
752-
"StackerDB event receiver disconnected".into(),
753-
))
754-
}
755-
};
756-
757741
// look in the nakamoto staging db -- a block can only get stored there if it has
758742
// enough signing weight to clear the threshold
759743
if let Ok(Some((stored_block, _sz))) = chain_state
@@ -773,6 +757,22 @@ impl SignCoordinator {
773757
return Ok(stored_block.header.signer_signature);
774758
}
775759

760+
// one of two things can happen:
761+
// * we get enough signatures from stackerdb from the signers, OR
762+
// * we see our block get processed in our chainstate (meaning, the signers broadcasted
763+
// the block and our node got it and processed it)
764+
let event = match receiver.recv_timeout(EVENT_RECEIVER_POLL) {
765+
Ok(event) => event,
766+
Err(std::sync::mpsc::RecvTimeoutError::Timeout) => {
767+
continue;
768+
}
769+
Err(std::sync::mpsc::RecvTimeoutError::Disconnected) => {
770+
return Err(NakamotoNodeError::SigningCoordinatorFailure(
771+
"StackerDB event receiver disconnected".into(),
772+
))
773+
}
774+
};
775+
776776
// check to see if this event we got is a signer event
777777
let is_signer_event =
778778
event.contract_id.name.starts_with(SIGNERS_NAME) && event.contract_id.is_boot();
@@ -821,33 +821,34 @@ impl SignCoordinator {
821821
));
822822
};
823823
if rejected_data.signer_signature_hash
824-
== block.header.signer_signature_hash()
824+
!= block.header.signer_signature_hash()
825+
{
826+
debug!("Received rejected block response for a block besides my own. Ignoring.");
827+
continue;
828+
}
829+
830+
debug!(
831+
"Signer {} rejected our block {}/{}",
832+
slot_id,
833+
&block.header.consensus_hash,
834+
&block.header.block_hash()
835+
);
836+
total_reject_weight = total_reject_weight
837+
.checked_add(signer_entry.weight)
838+
.expect("FATAL: total weight rejected exceeds u32::MAX");
839+
840+
if total_reject_weight.saturating_add(self.weight_threshold)
841+
> self.total_weight
825842
{
826843
debug!(
827-
"Signer {} rejected our block {}/{}",
828-
slot_id,
844+
"{}/{} signers vote to reject our block {}/{}",
845+
total_reject_weight,
846+
self.total_weight,
829847
&block.header.consensus_hash,
830848
&block.header.block_hash()
831849
);
832-
total_reject_weight = total_reject_weight
833-
.checked_add(signer_entry.weight)
834-
.expect("FATAL: total weight rejected exceeds u32::MAX");
835-
836-
if total_reject_weight.saturating_add(self.weight_threshold)
837-
> self.total_weight
838-
{
839-
debug!(
840-
"{}/{} signers vote to reject our block {}/{}",
841-
total_reject_weight,
842-
self.total_weight,
843-
&block.header.consensus_hash,
844-
&block.header.block_hash()
845-
);
846-
counters.bump_naka_rejected_blocks();
847-
return Err(NakamotoNodeError::SignersRejected);
848-
}
849-
} else {
850-
debug!("Received rejected block response for a block besides my own. Ignoring.");
850+
counters.bump_naka_rejected_blocks();
851+
return Err(NakamotoNodeError::SignersRejected);
851852
}
852853
continue;
853854
}
@@ -909,7 +910,7 @@ impl SignCoordinator {
909910
}
910911

911912
if Self::fault_injection_ignore_signatures() {
912-
debug!("SignCoordinator: fault injection: ignoring well-formed signature for block";
913+
warn!("SignCoordinator: fault injection: ignoring well-formed signature for block";
913914
"block_signer_sighash" => %block_sighash,
914915
"signer_pubkey" => signer_pubkey.to_hex(),
915916
"signer_slot_id" => slot_id,
@@ -922,7 +923,7 @@ impl SignCoordinator {
922923
continue;
923924
}
924925

925-
debug!("SignCoordinator: Signature Added to block";
926+
info!("SignCoordinator: Signature Added to block";
926927
"block_signer_sighash" => %block_sighash,
927928
"signer_pubkey" => signer_pubkey.to_hex(),
928929
"signer_slot_id" => slot_id,

0 commit comments

Comments
 (0)