Browse Source

Cleanup `awaiting_status` in case we don't have remaining subscriptions

We always replaced it with `remaining`, but when populating `awaiting_status` upon sync we only go by the keys, so we actually fill in the script status again.
We should remove the complete entry if we want to make sure that we don't want to process it anymore.

Note: Kept seeing monitoring logs for things that were already past Finality (...) so we looked into this.
refactor/no-log-handler
Daniel Karzel 3 years ago
committed by Lucas Soriano del Pino
parent
commit
179952ce5b
No known key found for this signature in database GPG Key ID: EE611E973A1530E7
  1. 37
      daemon/src/monitor.rs

37
daemon/src/monitor.rs

@ -383,7 +383,11 @@ where
tracing::trace!("{} subscriptions reached their monitoring target, {} remaining for this script", reached_monitoring_target.len(), remaining.len());
occupied.insert(remaining);
if remaining.is_empty() {
occupied.remove();
} else {
occupied.insert(remaining);
}
for (target_status, event) in reached_monitoring_target {
tracing::info!(%txid, target = %target_status, current = %status, "Bitcoin transaction reached monitoring target");
@ -722,6 +726,37 @@ mod tests {
assert!(!recorder.events.contains(&refund_finality));
}
#[tokio::test]
async fn stop_monitoring_after_target_reached() {
let _guard = tracing_subscriber::fmt()
.with_env_filter("trace")
.with_test_writer()
.set_default();
let (recorder_address, mut recorder_context) =
xtra::Context::<MessageRecordingActor>::new(None);
let mut recorder = MessageRecordingActor::default();
let cet_finality = Event::CetFinality(OrderId::default());
let mut monitor = Actor::for_test(
recorder_address,
[(
(txid1(), script1()),
vec![(ScriptStatus::finality(), cet_finality.clone())],
)],
);
monitor.client.include_tx(txid1(), 5);
recorder_context
.handle_while(&mut recorder, monitor.sync())
.await
.unwrap();
assert!(recorder.events.contains(&cet_finality));
assert!(monitor.awaiting_status.is_empty());
}
impl<A> Actor<A, stub::Client>
where
A: xtra::Actor + xtra::Handler<Event>,

Loading…
Cancel
Save