fix(relay): pin the sweep's conditional publish and label skipped publications

- The stale-candidate test now waits into a later second before the sweep,
  so an unconditional republish would sign a new event id and be written
  instead of being deduplicated; the test now fails if the sweep stops
  passing only_if_drifted.
- buzz_nip43_membership_publications_total labels a publication that the
  locked re-check skipped as result="skipped" rather than "succeeded", so
  overlapping passes do not inflate the success count.

Signed-off-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
This commit is contained in:
Elrond
2026-10-07 06:33:14 -04:00
parent 12604c67f5
commit 4f1f2a5f46

View File

@@ -3250,7 +3250,11 @@ async fn publish_nip43_membership_snapshot(
.record(started_at.elapsed().as_secs_f64());
metrics::counter!(
"buzz_nip43_membership_publications_total",
"result" => if result.is_ok() { "succeeded" } else { "failed" }
"result" => match &result {
Ok(false) if only_if_drifted => "skipped",
Ok(_) => "succeeded",
Err(_) => "failed",
}
)
.increment(1);
result
@@ -4253,6 +4257,10 @@ mod tests {
assert!(publish_nip43_membership_snapshot(&tenant, &state, false)
.await
.expect("publish current snapshot"));
// Move to a later second: an unconditional republish in the same
// second signs the same event id and is deduplicated, which would
// hide a pass that skipped the locked re-check.
tokio::time::sleep(std::time::Duration::from_millis(1_100)).await;
let recorder = DebuggingRecorder::new();
let summary = {
@@ -4267,6 +4275,28 @@ mod tests {
assert_eq!((summary.repaired, summary.failed), (0, 0));
assert_eq!(reconciliation_failures(&recorder), 0);
assert_eq!(relay_signed_snapshots(&pool, id, &state).await, 1);
assert_eq!(publications(&recorder, "skipped"), 1);
assert_eq!(publications(&recorder, "succeeded"), 0);
}
fn publications(recorder: &DebuggingRecorder, result: &str) -> u64 {
recorder
.snapshotter()
.snapshot()
.into_vec()
.into_iter()
.filter(|(key, _, _, _)| {
key.key().name() == "buzz_nip43_membership_publications_total"
&& key
.key()
.labels()
.any(|label| label.key() == "result" && label.value() == result)
})
.map(|(_, _, _, value)| match value {
DebugValue::Counter(value) => value,
other => panic!("publications_total must be a counter: {other:?}"),
})
.sum()
}
}
}