@@ -2042,10 +2042,7 @@ macro_rules! handle_monitor_update_completion {
2042
2042
}
2043
2043
2044
2044
macro_rules! handle_new_monitor_update {
2045
- ($self: ident, $update_res: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan: expr, _internal, $remove: expr, $completed: expr) => { {
2046
- // update_maps_on_chan_removal needs to be able to take id_to_peer, so make sure we can in
2047
- // any case so that it won't deadlock.
2048
- debug_assert_ne!($self.id_to_peer.held_by_thread(), LockHeldState::HeldByThread);
2045
+ ($self: ident, $update_res: expr, $chan: expr, _internal, $completed: expr) => { {
2049
2046
debug_assert!($self.background_events_processed_since_startup.load(Ordering::Acquire));
2050
2047
match $update_res {
2051
2048
ChannelMonitorUpdateStatus::InProgress => {
@@ -2059,23 +2056,11 @@ macro_rules! handle_new_monitor_update {
2059
2056
},
2060
2057
}
2061
2058
} };
2062
- ($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) => {
2063
- handle_new_monitor_update!($self, $update_res, $peer_state_lock, $peer_state,
2064
- $per_peer_state_lock, $chan, _internal, $remove,
2059
+ ($self: ident, $update_res: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan: expr, INITIAL_MONITOR) => {
2060
+ handle_new_monitor_update!($self, $update_res, $chan, _internal,
2065
2061
handle_monitor_update_completion!($self, $peer_state_lock, $peer_state, $per_peer_state_lock, $chan))
2066
2062
};
2067
- ($self: ident, $update_res: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan_entry: expr, INITIAL_MONITOR) => {
2068
- if let ChannelPhase::Funded(chan) = $chan_entry.get_mut() {
2069
- handle_new_monitor_update!($self, $update_res, $peer_state_lock, $peer_state,
2070
- $per_peer_state_lock, chan, MANUALLY_REMOVING_INITIAL_MONITOR, { $chan_entry.remove() })
2071
- } else {
2072
- // We're not supposed to handle monitor updates for unfunded channels (they have no monitors to
2073
- // update). Throwing away a monitor update could be dangerous, so we assert even in
2074
- // release builds.
2075
- panic!("Initial Monitors should not exist for non-funded channels");
2076
- }
2077
- };
2078
- ($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) => { {
2063
+ ($self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan: expr) => { {
2079
2064
let in_flight_updates = $peer_state.in_flight_monitor_updates.entry($funding_txo)
2080
2065
.or_insert_with(Vec::new);
2081
2066
// During startup, we push monitor updates as background events through to here in
@@ -2087,26 +2072,14 @@ macro_rules! handle_new_monitor_update {
2087
2072
in_flight_updates.len() - 1
2088
2073
});
2089
2074
let update_res = $self.chain_monitor.update_channel($funding_txo, &in_flight_updates[idx]);
2090
- handle_new_monitor_update!($self, update_res, $peer_state_lock, $peer_state,
2091
- $per_peer_state_lock, $chan, _internal, $remove,
2075
+ handle_new_monitor_update!($self, update_res, $chan, _internal,
2092
2076
{
2093
2077
let _ = in_flight_updates.remove(idx);
2094
2078
if in_flight_updates.is_empty() && $chan.blocked_monitor_updates_pending() == 0 {
2095
2079
handle_monitor_update_completion!($self, $peer_state_lock, $peer_state, $per_peer_state_lock, $chan);
2096
2080
}
2097
2081
})
2098
2082
} };
2099
- ($self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan_entry: expr) => {
2100
- if let ChannelPhase::Funded(chan) = $chan_entry.get_mut() {
2101
- handle_new_monitor_update!($self, $funding_txo, $update, $peer_state_lock, $peer_state,
2102
- $per_peer_state_lock, chan, MANUALLY_REMOVING, { $chan_entry.remove() })
2103
- } else {
2104
- // We're not supposed to handle monitor updates for unfunded channels (they have no monitors to
2105
- // update). Throwing away a monitor update could be dangerous, so we assert even in
2106
- // release builds.
2107
- panic!("Monitor updates should not exist for non-funded channels");
2108
- }
2109
- }
2110
2083
}
2111
2084
2112
2085
macro_rules! process_events_body {
@@ -2551,7 +2524,7 @@ where
2551
2524
// Update the monitor with the shutdown script if necessary.
2552
2525
if let Some(monitor_update) = monitor_update_opt.take() {
2553
2526
handle_new_monitor_update!(self, funding_txo_opt.unwrap(), monitor_update,
2554
- peer_state_lock, peer_state, per_peer_state, chan_phase_entry );
2527
+ peer_state_lock, peer_state, per_peer_state, chan );
2555
2528
break;
2556
2529
}
2557
2530
@@ -3325,7 +3298,7 @@ where
3325
3298
}, onion_packet, None, &self.fee_estimator, &self.logger);
3326
3299
match break_chan_phase_entry!(self, send_res, chan_phase_entry) {
3327
3300
Some(monitor_update) => {
3328
- match handle_new_monitor_update!(self, funding_txo, monitor_update, peer_state_lock, peer_state, per_peer_state, chan_phase_entry ) {
3301
+ match handle_new_monitor_update!(self, funding_txo, monitor_update, peer_state_lock, peer_state, per_peer_state, chan ) {
3329
3302
false => {
3330
3303
// Note that MonitorUpdateInProgress here indicates (per function
3331
3304
// docs) that we will resend the commitment update once monitor
@@ -4524,9 +4497,13 @@ where
4524
4497
let peer_state = &mut *peer_state_lock;
4525
4498
match peer_state.channel_by_id.entry(funding_txo.to_channel_id()) {
4526
4499
hash_map::Entry::Occupied(mut chan_phase) => {
4527
- updated_chan = true;
4528
- handle_new_monitor_update!(self, funding_txo, update.clone(),
4529
- peer_state_lock, peer_state, per_peer_state, chan_phase);
4500
+ if let ChannelPhase::Funded(chan) = chan_phase.get_mut() {
4501
+ updated_chan = true;
4502
+ handle_new_monitor_update!(self, funding_txo, update.clone(),
4503
+ peer_state_lock, peer_state, per_peer_state, chan);
4504
+ } else {
4505
+ debug_assert!(false, "We shouldn't have an update for a non-funded channel");
4506
+ }
4530
4507
},
4531
4508
hash_map::Entry::Vacant(_) => {},
4532
4509
}
@@ -5259,7 +5236,7 @@ where
5259
5236
}
5260
5237
if !during_init {
5261
5238
handle_new_monitor_update!(self, prev_hop.outpoint, monitor_update, peer_state_lock,
5262
- peer_state, per_peer_state, chan_phase_entry );
5239
+ peer_state, per_peer_state, chan );
5263
5240
} else {
5264
5241
// If we're running during init we cannot update a monitor directly -
5265
5242
// they probably haven't actually been loaded yet. Instead, push the
@@ -5903,16 +5880,14 @@ where
5903
5880
// hasn't persisted to disk yet - we can't lose money on a transaction that we haven't
5904
5881
// accepted payment from yet. We do, however, need to wait to send our channel_ready
5905
5882
// until we have persisted our monitor.
5906
- let new_channel_id = funding_msg.channel_id;
5907
5883
peer_state.pending_msg_events.push(events::MessageSendEvent::SendFundingSigned {
5908
5884
node_id: counterparty_node_id.clone(),
5909
5885
msg: funding_msg,
5910
5886
});
5911
5887
5912
5888
if let ChannelPhase::Funded(chan) = e.insert(ChannelPhase::Funded(chan)) {
5913
5889
handle_new_monitor_update!(self, persist_state, peer_state_lock, peer_state,
5914
- per_peer_state, chan, MANUALLY_REMOVING_INITIAL_MONITOR,
5915
- { peer_state.channel_by_id.remove(&new_channel_id) });
5890
+ per_peer_state, chan, INITIAL_MONITOR);
5916
5891
} else {
5917
5892
unreachable!("This must be a funded channel as we just inserted it.");
5918
5893
}
@@ -5947,7 +5922,7 @@ where
5947
5922
let monitor = try_chan_phase_entry!(self,
5948
5923
chan.funding_signed(&msg, best_block, &self.signer_provider, &self.logger), chan_phase_entry);
5949
5924
if let Ok(persist_status) = self.chain_monitor.watch_channel(chan.context.get_funding_txo().unwrap(), monitor) {
5950
- handle_new_monitor_update!(self, persist_status, peer_state_lock, peer_state, per_peer_state, chan_phase_entry , INITIAL_MONITOR);
5925
+ handle_new_monitor_update!(self, persist_status, peer_state_lock, peer_state, per_peer_state, chan , INITIAL_MONITOR);
5951
5926
Ok(())
5952
5927
} else {
5953
5928
try_chan_phase_entry!(self, Err(ChannelError::Close("Channel funding outpoint was a duplicate".to_owned())), chan_phase_entry)
@@ -6054,7 +6029,7 @@ where
6054
6029
// Update the monitor with the shutdown script if necessary.
6055
6030
if let Some(monitor_update) = monitor_update_opt {
6056
6031
handle_new_monitor_update!(self, funding_txo_opt.unwrap(), monitor_update,
6057
- peer_state_lock, peer_state, per_peer_state, chan_phase_entry );
6032
+ peer_state_lock, peer_state, per_peer_state, chan );
6058
6033
}
6059
6034
},
6060
6035
ChannelPhase::UnfundedInboundV1(_) | ChannelPhase::UnfundedOutboundV1(_) => {
@@ -6306,7 +6281,7 @@ where
6306
6281
let monitor_update_opt = try_chan_phase_entry!(self, chan.commitment_signed(&msg, &self.logger), chan_phase_entry);
6307
6282
if let Some(monitor_update) = monitor_update_opt {
6308
6283
handle_new_monitor_update!(self, funding_txo.unwrap(), monitor_update, peer_state_lock,
6309
- peer_state, per_peer_state, chan_phase_entry );
6284
+ peer_state, per_peer_state, chan );
6310
6285
}
6311
6286
Ok(())
6312
6287
} else {
@@ -6480,7 +6455,7 @@ where
6480
6455
let funding_txo = funding_txo_opt
6481
6456
.expect("Funding outpoint must have been set for RAA handling to succeed");
6482
6457
handle_new_monitor_update!(self, funding_txo, monitor_update,
6483
- peer_state_lock, peer_state, per_peer_state, chan_phase_entry );
6458
+ peer_state_lock, peer_state, per_peer_state, chan );
6484
6459
}
6485
6460
htlcs_to_fail
6486
6461
} else {
@@ -6777,10 +6752,8 @@ where
6777
6752
if let Some(monitor_update) = monitor_opt {
6778
6753
has_monitor_update = true;
6779
6754
6780
- let channel_id: ChannelId = *channel_id;
6781
6755
handle_new_monitor_update!(self, funding_txo.unwrap(), monitor_update,
6782
- peer_state_lock, peer_state, per_peer_state, chan, MANUALLY_REMOVING,
6783
- peer_state.channel_by_id.remove(&channel_id));
6756
+ peer_state_lock, peer_state, per_peer_state, chan);
6784
6757
continue 'peer_loop;
6785
6758
}
6786
6759
}
@@ -7089,7 +7062,6 @@ where
7089
7062
/// operation. It will double-check that nothing *else* is also blocking the same channel from
7090
7063
/// making progress and then let any blocked [`ChannelMonitorUpdate`]s fly.
7091
7064
fn handle_monitor_update_release(&self, counterparty_node_id: PublicKey, channel_funding_outpoint: OutPoint, mut completed_blocker: Option<RAAMonitorUpdateBlockingAction>) {
7092
- let mut errors = Vec::new();
7093
7065
loop {
7094
7066
let per_peer_state = self.per_peer_state.read().unwrap();
7095
7067
if let Some(peer_state_mtx) = per_peer_state.get(&counterparty_node_id) {
@@ -7122,7 +7094,7 @@ where
7122
7094
log_debug!(self.logger, "Unlocking monitor updating for channel {} and updating monitor",
7123
7095
channel_funding_outpoint.to_channel_id());
7124
7096
handle_new_monitor_update!(self, channel_funding_outpoint, monitor_update,
7125
- peer_state_lck, peer_state, per_peer_state, chan_phase_entry );
7097
+ peer_state_lck, peer_state, per_peer_state, chan );
7126
7098
if further_update_exists {
7127
7099
// If there are more `ChannelMonitorUpdate`s to process, restart at the
7128
7100
// top of the loop.
@@ -7141,10 +7113,6 @@ where
7141
7113
}
7142
7114
break;
7143
7115
}
7144
- for (err, counterparty_node_id) in errors {
7145
- let res = Err::<(), _>(err);
7146
- let _ = handle_error!(self, res, counterparty_node_id);
7147
- }
7148
7116
}
7149
7117
7150
7118
fn handle_post_event_actions(&self, actions: Vec<EventCompletionAction>) {
0 commit comments