Skip to content

Commit bf1cc79

Browse files
authored
Merge pull request #5747 from stacks-network/chore/signer-coordinator-logging
chore: improve logging in `StackerDBListener`
2 parents 075f40d + 1523e6a commit bf1cc79

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
1919
- Logging improvements:
2020
- P2P logs now includes a reason for dropping a peer or neighbor
2121
- Improvements to how a PeerAddress is logged (human readable format vs hex)
22+
- Add weight threshold and percentages to `StackerDBListener` logs
2223

2324
### Fixed
2425

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,11 @@ impl SignerCoordinator {
341341
return false;
342342
}
343343
// number or rejections changed?
344-
if status.total_reject_weight != rejections {
344+
if status.total_weight_rejected != rejections {
345345
return false;
346346
}
347347
// enough signatures?
348-
return status.total_weight_signed < self.weight_threshold;
348+
return status.total_weight_approved < self.weight_threshold;
349349
},
350350
)? {
351351
Some(status) => status,
@@ -407,8 +407,8 @@ impl SignerCoordinator {
407407
}
408408
};
409409

410-
if rejections != block_status.total_reject_weight {
411-
rejections = block_status.total_reject_weight;
410+
if rejections != block_status.total_weight_rejected {
411+
rejections = block_status.total_weight_rejected;
412412
let (rejections_step, new_rejections_timeout) = self
413413
.block_rejection_timeout_steps
414414
.range((Included(0), Included(rejections)))
@@ -430,18 +430,18 @@ impl SignerCoordinator {
430430
}
431431

432432
if block_status
433-
.total_reject_weight
433+
.total_weight_rejected
434434
.saturating_add(self.weight_threshold)
435435
> self.total_weight
436436
{
437437
info!(
438438
"{}/{} signers vote to reject block",
439-
block_status.total_reject_weight, self.total_weight;
439+
block_status.total_weight_rejected, self.total_weight;
440440
"block_signer_sighash" => %block_signer_sighash,
441441
);
442442
counters.bump_naka_rejected_blocks();
443443
return Err(NakamotoNodeError::SignersRejected);
444-
} else if block_status.total_weight_signed >= self.weight_threshold {
444+
} else if block_status.total_weight_approved >= self.weight_threshold {
445445
info!("Received enough signatures, block accepted";
446446
"block_signer_sighash" => %block_signer_sighash,
447447
);

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ pub static EVENT_RECEIVER_POLL: Duration = Duration::from_millis(500);
5454
pub struct BlockStatus {
5555
pub responded_signers: HashSet<StacksPublicKey>,
5656
pub gathered_signatures: BTreeMap<u32, MessageSignature>,
57-
pub total_weight_signed: u32,
58-
pub total_reject_weight: u32,
57+
pub total_weight_approved: u32,
58+
pub total_weight_rejected: u32,
5959
}
6060

6161
#[derive(Debug, Clone)]
@@ -312,14 +312,17 @@ impl StackerDBListener {
312312
"signer_slot_id" => slot_id,
313313
"signature" => %signature,
314314
"signer_weight" => signer_entry.weight,
315-
"total_weight_signed" => block.total_weight_signed,
315+
"total_weight_approved" => block.total_weight_approved,
316+
"percent_approved" => block.total_weight_approved as f64 / self.total_weight as f64 * 100.0,
317+
"total_weight_rejected" => block.total_weight_rejected,
318+
"percent_rejected" => block.total_weight_rejected as f64 / self.total_weight as f64 * 100.0,
316319
);
317320
continue;
318321
}
319322

320323
if !block.gathered_signatures.contains_key(&slot_id) {
321-
block.total_weight_signed = block
322-
.total_weight_signed
324+
block.total_weight_approved = block
325+
.total_weight_approved
323326
.checked_add(signer_entry.weight)
324327
.expect("FATAL: total weight signed exceeds u32::MAX");
325328
}
@@ -330,14 +333,18 @@ impl StackerDBListener {
330333
"signer_slot_id" => slot_id,
331334
"signature" => %signature,
332335
"signer_weight" => signer_entry.weight,
333-
"total_weight_signed" => block.total_weight_signed,
336+
"total_weight_approved" => block.total_weight_approved,
337+
"percent_approved" => block.total_weight_approved as f64 / self.total_weight as f64 * 100.0,
338+
"total_weight_rejected" => block.total_weight_rejected,
339+
"percent_rejected" => block.total_weight_rejected as f64 / self.total_weight as f64 * 100.0,
340+
"weight_threshold" => self.weight_threshold,
334341
"tenure_extend_timestamp" => tenure_extend_timestamp,
335342
"server_version" => metadata.server_version,
336343
);
337344
block.gathered_signatures.insert(slot_id, signature);
338345
block.responded_signers.insert(signer_pubkey);
339346

340-
if block.total_weight_signed >= self.weight_threshold {
347+
if block.total_weight_approved >= self.weight_threshold {
341348
// Signal to anyone waiting on this block that we have enough signatures
342349
cvar.notify_all();
343350
}
@@ -378,8 +385,8 @@ impl StackerDBListener {
378385
}
379386
};
380387
block.responded_signers.insert(rejected_pubkey);
381-
block.total_reject_weight = block
382-
.total_reject_weight
388+
block.total_weight_rejected = block
389+
.total_weight_rejected
383390
.checked_add(signer_entry.weight)
384391
.expect("FATAL: total weight rejected exceeds u32::MAX");
385392

@@ -389,15 +396,19 @@ impl StackerDBListener {
389396
"signer_slot_id" => slot_id,
390397
"signature" => %rejected_data.signature,
391398
"signer_weight" => signer_entry.weight,
392-
"total_weight_signed" => block.total_weight_signed,
399+
"total_weight_approved" => block.total_weight_approved,
400+
"percent_approved" => block.total_weight_approved as f64 / self.total_weight as f64 * 100.0,
401+
"total_weight_rejected" => block.total_weight_rejected,
402+
"percent_rejected" => block.total_weight_rejected as f64 / self.total_weight as f64 * 100.0,
403+
"weight_threshold" => self.weight_threshold,
393404
"reason" => rejected_data.reason,
394405
"reason_code" => ?rejected_data.reason_code,
395406
"tenure_extend_timestamp" => rejected_data.response_data.tenure_extend_timestamp,
396407
"server_version" => rejected_data.metadata.server_version,
397408
);
398409

399410
if block
400-
.total_reject_weight
411+
.total_weight_rejected
401412
.saturating_add(self.weight_threshold)
402413
> self.total_weight
403414
{
@@ -479,8 +490,8 @@ impl StackerDBListenerComms {
479490
let block_status = BlockStatus {
480491
responded_signers: HashSet::new(),
481492
gathered_signatures: BTreeMap::new(),
482-
total_weight_signed: 0,
483-
total_reject_weight: 0,
493+
total_weight_approved: 0,
494+
total_weight_rejected: 0,
484495
};
485496
blocks.insert(block.signer_signature_hash(), block_status);
486497
}

0 commit comments

Comments
 (0)