@@ -1980,7 +1980,7 @@ macro_rules! handle_monitor_update_completion {
1980
1980
}
1981
1981
1982
1982
macro_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) => { {
1984
1984
// update_maps_on_chan_removal needs to be able to take id_to_peer, so make sure we can in
1985
1985
// any case so that it won't deadlock.
1986
1986
debug_assert_ne!($self.id_to_peer.held_by_thread(), LockHeldState::HeldByThread);
@@ -1997,23 +1997,11 @@ macro_rules! handle_new_monitor_update {
1997
1997
},
1998
1998
}
1999
1999
} };
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,
2003
2002
handle_monitor_update_completion!($self, $peer_state_lock, $peer_state, $per_peer_state_lock, $chan))
2004
2003
};
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) => { {
2017
2005
let in_flight_updates = $peer_state.in_flight_monitor_updates.entry($funding_txo)
2018
2006
.or_insert_with(Vec::new);
2019
2007
// During startup, we push monitor updates as background events through to here in
@@ -2025,26 +2013,14 @@ macro_rules! handle_new_monitor_update {
2025
2013
in_flight_updates.len() - 1
2026
2014
});
2027
2015
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,
2030
2017
{
2031
2018
let _ = in_flight_updates.remove(idx);
2032
2019
if in_flight_updates.is_empty() && $chan.blocked_monitor_updates_pending() == 0 {
2033
2020
handle_monitor_update_completion!($self, $peer_state_lock, $peer_state, $per_peer_state_lock, $chan);
2034
2021
}
2035
2022
})
2036
2023
} };
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
- }
2048
2024
}
2049
2025
2050
2026
macro_rules! process_events_body {
@@ -2480,7 +2456,7 @@ where
2480
2456
// Update the monitor with the shutdown script if necessary.
2481
2457
if let Some(monitor_update) = monitor_update_opt.take() {
2482
2458
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 );
2484
2460
break;
2485
2461
}
2486
2462
@@ -3242,7 +3218,7 @@ where
3242
3218
}, onion_packet, None, &self.fee_estimator, &self.logger);
3243
3219
match break_chan_phase_entry!(self, send_res, chan_phase_entry) {
3244
3220
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 ) {
3246
3222
false => {
3247
3223
// Note that MonitorUpdateInProgress here indicates (per function
3248
3224
// docs) that we will resend the commitment update once monitor
@@ -4328,9 +4304,13 @@ where
4328
4304
let peer_state = &mut *peer_state_lock;
4329
4305
match peer_state.channel_by_id.entry(funding_txo.to_channel_id()) {
4330
4306
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
+ }
4334
4314
},
4335
4315
hash_map::Entry::Vacant(_) => {},
4336
4316
}
@@ -5063,7 +5043,7 @@ where
5063
5043
}
5064
5044
if !during_init {
5065
5045
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 );
5067
5047
} else {
5068
5048
// If we're running during init we cannot update a monitor directly -
5069
5049
// they probably haven't actually been loaded yet. Instead, push the
@@ -5703,16 +5683,14 @@ where
5703
5683
// hasn't persisted to disk yet - we can't lose money on a transaction that we haven't
5704
5684
// accepted payment from yet. We do, however, need to wait to send our channel_ready
5705
5685
// until we have persisted our monitor.
5706
- let new_channel_id = funding_msg.channel_id;
5707
5686
peer_state.pending_msg_events.push(events::MessageSendEvent::SendFundingSigned {
5708
5687
node_id: counterparty_node_id.clone(),
5709
5688
msg: funding_msg,
5710
5689
});
5711
5690
5712
5691
if let ChannelPhase::Funded(chan) = e.insert(ChannelPhase::Funded(chan)) {
5713
5692
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);
5716
5694
} else {
5717
5695
unreachable!("This must be a funded channel as we just inserted it.");
5718
5696
}
@@ -5747,7 +5725,7 @@ where
5747
5725
let monitor = try_chan_phase_entry!(self,
5748
5726
chan.funding_signed(&msg, best_block, &self.signer_provider, &self.logger), chan_phase_entry);
5749
5727
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);
5751
5729
Ok(())
5752
5730
} else {
5753
5731
try_chan_phase_entry!(self, Err(ChannelError::Close("Channel funding outpoint was a duplicate".to_owned())), chan_phase_entry)
@@ -5852,7 +5830,7 @@ where
5852
5830
// Update the monitor with the shutdown script if necessary.
5853
5831
if let Some(monitor_update) = monitor_update_opt {
5854
5832
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 );
5856
5834
}
5857
5835
},
5858
5836
ChannelPhase::UnfundedInboundV1(_) | ChannelPhase::UnfundedOutboundV1(_) => {
@@ -6097,7 +6075,7 @@ where
6097
6075
let monitor_update_opt = try_chan_phase_entry!(self, chan.commitment_signed(&msg, &self.logger), chan_phase_entry);
6098
6076
if let Some(monitor_update) = monitor_update_opt {
6099
6077
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 );
6101
6079
}
6102
6080
Ok(())
6103
6081
} else {
@@ -6271,7 +6249,7 @@ where
6271
6249
let funding_txo = funding_txo_opt
6272
6250
.expect("Funding outpoint must have been set for RAA handling to succeed");
6273
6251
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 );
6275
6253
}
6276
6254
htlcs_to_fail
6277
6255
} else {
@@ -6566,10 +6544,8 @@ where
6566
6544
if let Some(monitor_update) = monitor_opt {
6567
6545
has_monitor_update = true;
6568
6546
6569
- let channel_id: ChannelId = *channel_id;
6570
6547
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);
6573
6549
continue 'peer_loop;
6574
6550
}
6575
6551
}
@@ -6878,7 +6854,6 @@ where
6878
6854
/// operation. It will double-check that nothing *else* is also blocking the same channel from
6879
6855
/// making progress and then let any blocked [`ChannelMonitorUpdate`]s fly.
6880
6856
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();
6882
6857
loop {
6883
6858
let per_peer_state = self.per_peer_state.read().unwrap();
6884
6859
if let Some(peer_state_mtx) = per_peer_state.get(&counterparty_node_id) {
@@ -6911,7 +6886,7 @@ where
6911
6886
log_debug!(self.logger, "Unlocking monitor updating for channel {} and updating monitor",
6912
6887
channel_funding_outpoint.to_channel_id());
6913
6888
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 );
6915
6890
if further_update_exists {
6916
6891
// If there are more `ChannelMonitorUpdate`s to process, restart at the
6917
6892
// top of the loop.
@@ -6930,10 +6905,6 @@ where
6930
6905
}
6931
6906
break;
6932
6907
}
6933
- for (err, counterparty_node_id) in errors {
6934
- let res = Err::<(), _>(err);
6935
- let _ = handle_error!(self, res, counterparty_node_id);
6936
- }
6937
6908
}
6938
6909
6939
6910
fn handle_post_event_actions(&self, actions: Vec<EventCompletionAction>) {
0 commit comments