use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use bitcoin::secp256k1::PublicKey;
-#[derive(Clone, Copy, Hash, PartialEq, Eq)]
+#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
/// A specific update's ID stored in a `MonitorUpdateId`, separated out to make the contents
/// entirely opaque.
enum UpdateOrigin {
let mut pending_monitor_updates = monitor_data.pending_monitor_updates.lock().unwrap();
pending_monitor_updates.retain(|update_id| *update_id != completed_update_id);
+ log_trace!(self.logger, "Received a channel_monitor_updated for id: {:?}",
+ completed_update_id.contents);
match completed_update_id {
MonitorUpdateId { contents: UpdateOrigin::OffChain(_) } => {
// Note that we only check for `UpdateOrigin::OffChain` failures here - if
// If there are still monitor updates pending (or an old monitor update
// finished after a later one perm-failed), we cannot yet construct an
// Completed event.
+ log_debug!(self.logger,
+ "Have pending monitor update for channel {:?}, refusing to generate a Completed event",
+ funding_txo);
return Ok(());
}
self.pending_monitor_events.lock().unwrap().push((funding_txo, vec![MonitorEvent::Completed {
fn release_pending_monitor_events(&self) -> Vec<(OutPoint, Vec<MonitorEvent>, Option<PublicKey>)> {
let mut pending_monitor_events = self.pending_monitor_events.lock().unwrap().split_off(0);
+ log_trace!(self.logger, "Got {} monitor events from ChainMonitor for release.",
+ pending_monitor_events.len());
for monitor_state in self.monitors.read().unwrap().values() {
let is_pending_monitor_update = monitor_state.has_pending_chainsync_updates(&monitor_state.pending_monitor_updates.lock().unwrap());
if is_pending_monitor_update &&
log_error!(self.logger, " This may cause duplicate payment events to be generated.");
}
let monitor_events = monitor_state.monitor.get_and_clear_pending_monitor_events();
+ let monitor_outpoint = monitor_state.monitor.get_funding_txo().0;
+ log_trace!(self.logger, "Got {} monitor events from ChannelMonitor {:?}",
+ monitor_events.len(), monitor_outpoint);
if monitor_events.len() > 0 {
- let monitor_outpoint = monitor_state.monitor.get_funding_txo().0;
let counterparty_node_id = monitor_state.monitor.get_counterparty_node_id();
pending_monitor_events.push((monitor_outpoint, monitor_events, counterparty_node_id));
}
let id_to_peer = self.id_to_peer.lock().unwrap();
match id_to_peer.get(&funding_txo.to_channel_id()) {
Some(cp_id) => cp_id.clone(),
- None => return,
+ None => {
+ log_debug!(self.logger,
+ "Got a monitor update completion for a since-closed channel: {:?}",
+ funding_txo);
+ return
+ },
}
}
};
let per_peer_state = self.per_peer_state.read().unwrap();
let mut peer_state_lock;
let peer_state_mutex_opt = per_peer_state.get(&counterparty_node_id);
- if peer_state_mutex_opt.is_none() { return }
+ if peer_state_mutex_opt.is_none() {
+ log_debug!(self.logger,
+ "Got a monitor update completion for a peer we have no channels with anymore: {}",
+ counterparty_node_id);
+ return;
+ }
peer_state_lock = peer_state_mutex_opt.unwrap().lock().unwrap();
let peer_state = &mut *peer_state_lock;
let mut channel = {
match peer_state.channel_by_id.entry(funding_txo.to_channel_id()){
hash_map::Entry::Occupied(chan) => chan,
- hash_map::Entry::Vacant(_) => return,
+ hash_map::Entry::Vacant(_) => {
+ log_debug!(self.logger,
+ "Got a monitor update completion for a channel we have since closed: {:?}",
+ funding_txo);
+ return;
+ },
}
};
- log_trace!(self.logger, "ChannelMonitor updated to {}. Current highest is {}",
+ log_debug!(self.logger, "ChannelMonitor updated to {}. Current highest is {}",
highest_applied_update_id, channel.get().get_latest_monitor_update_id());
if !channel.get().is_awaiting_monitor_update() || channel.get().get_latest_monitor_update_id() != highest_applied_update_id {
return;
fn process_pending_monitor_events(&self) -> bool {
let mut failed_channels = Vec::new();
let mut pending_monitor_events = self.chain_monitor.release_pending_monitor_events();
+ log_trace!(self.logger, "Got {} monitor events from ChainMonitor",
+ pending_monitor_events.len());
let has_pending_monitor_events = !pending_monitor_events.is_empty();
for (funding_outpoint, mut monitor_events, counterparty_node_id) in pending_monitor_events.drain(..) {
for monitor_event in monitor_events.drain(..) {