@@ -1980,7 +1980,7 @@ macro_rules! handle_monitor_update_completion {
19801980}
19811981
19821982macro_rules! handle_new_monitor_update {
1983- ($self: ident, $update_res: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $ chan: expr, _internal, $remove: expr , $completed: expr) => { {
1983+ ($self: ident, $update_res: expr, $chan: expr, _internal, $completed: expr) => { {
19841984 // update_maps_on_chan_removal needs to be able to take id_to_peer, so make sure we can in
19851985 // any case so that it won't deadlock.
19861986 debug_assert_ne!($self.id_to_peer.held_by_thread(), LockHeldState::HeldByThread);
@@ -1997,23 +1997,11 @@ macro_rules! handle_new_monitor_update {
19971997 },
19981998 }
19991999 } };
2000- ($self: ident, $update_res: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan: expr, MANUALLY_REMOVING_INITIAL_MONITOR, $remove: expr) => {
2001- handle_new_monitor_update!($self, $update_res, $peer_state_lock, $peer_state,
2002- $per_peer_state_lock, $chan, _internal, $remove,
2000+ ($self: ident, $update_res: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan: expr, INITIAL_MONITOR) => {
2001+ handle_new_monitor_update!($self, $update_res, $chan, _internal,
20032002 handle_monitor_update_completion!($self, $peer_state_lock, $peer_state, $per_peer_state_lock, $chan))
20042003 };
2005- ($self: ident, $update_res: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan_entry: expr, INITIAL_MONITOR) => {
2006- if let ChannelPhase::Funded(chan) = $chan_entry.get_mut() {
2007- handle_new_monitor_update!($self, $update_res, $peer_state_lock, $peer_state,
2008- $per_peer_state_lock, chan, MANUALLY_REMOVING_INITIAL_MONITOR, { $chan_entry.remove() })
2009- } else {
2010- // We're not supposed to handle monitor updates for unfunded channels (they have no monitors to
2011- // update). Throwing away a monitor update could be dangerous, so we assert even in
2012- // release builds.
2013- panic!("Initial Monitors should not exist for non-funded channels");
2014- }
2015- };
2016- ($self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan: expr, MANUALLY_REMOVING, $remove: expr) => { {
2004+ ($self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan: expr) => { {
20172005 let in_flight_updates = $peer_state.in_flight_monitor_updates.entry($funding_txo)
20182006 .or_insert_with(Vec::new);
20192007 // During startup, we push monitor updates as background events through to here in
@@ -2025,26 +2013,14 @@ macro_rules! handle_new_monitor_update {
20252013 in_flight_updates.len() - 1
20262014 });
20272015 let update_res = $self.chain_monitor.update_channel($funding_txo, &in_flight_updates[idx]);
2028- handle_new_monitor_update!($self, update_res, $peer_state_lock, $peer_state,
2029- $per_peer_state_lock, $chan, _internal, $remove,
2016+ handle_new_monitor_update!($self, update_res, $chan, _internal,
20302017 {
20312018 let _ = in_flight_updates.remove(idx);
20322019 if in_flight_updates.is_empty() && $chan.blocked_monitor_updates_pending() == 0 {
20332020 handle_monitor_update_completion!($self, $peer_state_lock, $peer_state, $per_peer_state_lock, $chan);
20342021 }
20352022 })
20362023 } };
2037- ($self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan_entry: expr) => {
2038- if let ChannelPhase::Funded(chan) = $chan_entry.get_mut() {
2039- handle_new_monitor_update!($self, $funding_txo, $update, $peer_state_lock, $peer_state,
2040- $per_peer_state_lock, chan, MANUALLY_REMOVING, { $chan_entry.remove() })
2041- } else {
2042- // We're not supposed to handle monitor updates for unfunded channels (they have no monitors to
2043- // update). Throwing away a monitor update could be dangerous, so we assert even in
2044- // release builds.
2045- panic!("Monitor updates should not exist for non-funded channels");
2046- }
2047- }
20482024}
20492025
20502026macro_rules! process_events_body {
@@ -2480,7 +2456,7 @@ where
24802456 // Update the monitor with the shutdown script if necessary.
24812457 if let Some(monitor_update) = monitor_update_opt.take() {
24822458 handle_new_monitor_update!(self, funding_txo_opt.unwrap(), monitor_update,
2483- peer_state_lock, peer_state, per_peer_state, chan_phase_entry );
2459+ peer_state_lock, peer_state, per_peer_state, chan );
24842460 break;
24852461 }
24862462
@@ -3242,7 +3218,7 @@ where
32423218 }, onion_packet, None, &self.fee_estimator, &self.logger);
32433219 match break_chan_phase_entry!(self, send_res, chan_phase_entry) {
32443220 Some(monitor_update) => {
3245- match handle_new_monitor_update!(self, funding_txo, monitor_update, peer_state_lock, peer_state, per_peer_state, chan_phase_entry ) {
3221+ match handle_new_monitor_update!(self, funding_txo, monitor_update, peer_state_lock, peer_state, per_peer_state, chan ) {
32463222 false => {
32473223 // Note that MonitorUpdateInProgress here indicates (per function
32483224 // docs) that we will resend the commitment update once monitor
@@ -4328,9 +4304,13 @@ where
43284304 let peer_state = &mut *peer_state_lock;
43294305 match peer_state.channel_by_id.entry(funding_txo.to_channel_id()) {
43304306 hash_map::Entry::Occupied(mut chan_phase) => {
4331- updated_chan = true;
4332- handle_new_monitor_update!(self, funding_txo, update.clone(),
4333- peer_state_lock, peer_state, per_peer_state, chan_phase);
4307+ if let ChannelPhase::Funded(chan) = chan_phase.get_mut() {
4308+ updated_chan = true;
4309+ handle_new_monitor_update!(self, funding_txo, update.clone(),
4310+ peer_state_lock, peer_state, per_peer_state, chan);
4311+ } else {
4312+ debug_assert!(false, "We shouldn't have an update for a non-funded channel");
4313+ }
43344314 },
43354315 hash_map::Entry::Vacant(_) => {},
43364316 }
@@ -5063,7 +5043,7 @@ where
50635043 }
50645044 if !during_init {
50655045 handle_new_monitor_update!(self, prev_hop.outpoint, monitor_update, peer_state_lock,
5066- peer_state, per_peer_state, chan_phase_entry );
5046+ peer_state, per_peer_state, chan );
50675047 } else {
50685048 // If we're running during init we cannot update a monitor directly -
50695049 // they probably haven't actually been loaded yet. Instead, push the
@@ -5703,16 +5683,14 @@ where
57035683 // hasn't persisted to disk yet - we can't lose money on a transaction that we haven't
57045684 // accepted payment from yet. We do, however, need to wait to send our channel_ready
57055685 // until we have persisted our monitor.
5706- let new_channel_id = funding_msg.channel_id;
57075686 peer_state.pending_msg_events.push(events::MessageSendEvent::SendFundingSigned {
57085687 node_id: counterparty_node_id.clone(),
57095688 msg: funding_msg,
57105689 });
57115690
57125691 if let ChannelPhase::Funded(chan) = e.insert(ChannelPhase::Funded(chan)) {
57135692 handle_new_monitor_update!(self, persist_state, peer_state_lock, peer_state,
5714- per_peer_state, chan, MANUALLY_REMOVING_INITIAL_MONITOR,
5715- { peer_state.channel_by_id.remove(&new_channel_id) });
5693+ per_peer_state, chan, INITIAL_MONITOR);
57165694 } else {
57175695 unreachable!("This must be a funded channel as we just inserted it.");
57185696 }
@@ -5747,7 +5725,7 @@ where
57475725 let monitor = try_chan_phase_entry!(self,
57485726 chan.funding_signed(&msg, best_block, &self.signer_provider, &self.logger), chan_phase_entry);
57495727 if let Ok(persist_status) = self.chain_monitor.watch_channel(chan.context.get_funding_txo().unwrap(), monitor) {
5750- handle_new_monitor_update!(self, persist_status, peer_state_lock, peer_state, per_peer_state, chan_phase_entry , INITIAL_MONITOR);
5728+ handle_new_monitor_update!(self, persist_status, peer_state_lock, peer_state, per_peer_state, chan , INITIAL_MONITOR);
57515729 Ok(())
57525730 } else {
57535731 try_chan_phase_entry!(self, Err(ChannelError::Close("Channel funding outpoint was a duplicate".to_owned())), chan_phase_entry)
@@ -5852,7 +5830,7 @@ where
58525830 // Update the monitor with the shutdown script if necessary.
58535831 if let Some(monitor_update) = monitor_update_opt {
58545832 handle_new_monitor_update!(self, funding_txo_opt.unwrap(), monitor_update,
5855- peer_state_lock, peer_state, per_peer_state, chan_phase_entry );
5833+ peer_state_lock, peer_state, per_peer_state, chan );
58565834 }
58575835 },
58585836 ChannelPhase::UnfundedInboundV1(_) | ChannelPhase::UnfundedOutboundV1(_) => {
@@ -6097,7 +6075,7 @@ where
60976075 let monitor_update_opt = try_chan_phase_entry!(self, chan.commitment_signed(&msg, &self.logger), chan_phase_entry);
60986076 if let Some(monitor_update) = monitor_update_opt {
60996077 handle_new_monitor_update!(self, funding_txo.unwrap(), monitor_update, peer_state_lock,
6100- peer_state, per_peer_state, chan_phase_entry );
6078+ peer_state, per_peer_state, chan );
61016079 }
61026080 Ok(())
61036081 } else {
@@ -6271,7 +6249,7 @@ where
62716249 let funding_txo = funding_txo_opt
62726250 .expect("Funding outpoint must have been set for RAA handling to succeed");
62736251 handle_new_monitor_update!(self, funding_txo, monitor_update,
6274- peer_state_lock, peer_state, per_peer_state, chan_phase_entry );
6252+ peer_state_lock, peer_state, per_peer_state, chan );
62756253 }
62766254 htlcs_to_fail
62776255 } else {
@@ -6566,10 +6544,8 @@ where
65666544 if let Some(monitor_update) = monitor_opt {
65676545 has_monitor_update = true;
65686546
6569- let channel_id: ChannelId = *channel_id;
65706547 handle_new_monitor_update!(self, funding_txo.unwrap(), monitor_update,
6571- peer_state_lock, peer_state, per_peer_state, chan, MANUALLY_REMOVING,
6572- peer_state.channel_by_id.remove(&channel_id));
6548+ peer_state_lock, peer_state, per_peer_state, chan);
65736549 continue 'peer_loop;
65746550 }
65756551 }
@@ -6878,7 +6854,6 @@ where
68786854 /// operation. It will double-check that nothing *else* is also blocking the same channel from
68796855 /// making progress and then let any blocked [`ChannelMonitorUpdate`]s fly.
68806856 fn handle_monitor_update_release(&self, counterparty_node_id: PublicKey, channel_funding_outpoint: OutPoint, mut completed_blocker: Option<RAAMonitorUpdateBlockingAction>) {
6881- let mut errors = Vec::new();
68826857 loop {
68836858 let per_peer_state = self.per_peer_state.read().unwrap();
68846859 if let Some(peer_state_mtx) = per_peer_state.get(&counterparty_node_id) {
@@ -6911,7 +6886,7 @@ where
69116886 log_debug!(self.logger, "Unlocking monitor updating for channel {} and updating monitor",
69126887 channel_funding_outpoint.to_channel_id());
69136888 handle_new_monitor_update!(self, channel_funding_outpoint, monitor_update,
6914- peer_state_lck, peer_state, per_peer_state, chan_phase_entry );
6889+ peer_state_lck, peer_state, per_peer_state, chan );
69156890 if further_update_exists {
69166891 // If there are more `ChannelMonitorUpdate`s to process, restart at the
69176892 // top of the loop.
@@ -6930,10 +6905,6 @@ where
69306905 }
69316906 break;
69326907 }
6933- for (err, counterparty_node_id) in errors {
6934- let res = Err::<(), _>(err);
6935- let _ = handle_error!(self, res, counterparty_node_id);
6936- }
69376908 }
69386909
69396910 fn handle_post_event_actions(&self, actions: Vec<EventCompletionAction>) {
0 commit comments