@@ -3169,32 +3169,33 @@ macro_rules! locked_close_channel {
3169
3169
/// Returns (boolean indicating if we should remove the Channel object from memory, a mapped error)
3170
3170
#[rustfmt::skip]
3171
3171
macro_rules! convert_channel_err {
3172
- ($self: ident, $peer_state: expr, $err: expr, $chan: expr, $close: expr, $locked_close: expr, $channel_id: expr, _internal) => {
3172
+ ($self: ident, $peer_state: expr, $err: expr, $chan: expr, $close: expr, $locked_close: expr, $channel_id: expr, _internal) => { {
3173
3173
match $err {
3174
3174
ChannelError::Warn(msg) => {
3175
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), * $channel_id))
3175
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), $channel_id))
3176
3176
},
3177
3177
ChannelError::WarnAndDisconnect(msg) => {
3178
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::WarnAndDisconnect(msg), * $channel_id))
3178
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::WarnAndDisconnect(msg), $channel_id))
3179
3179
},
3180
3180
ChannelError::Ignore(msg) => {
3181
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), * $channel_id))
3181
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), $channel_id))
3182
3182
},
3183
3183
ChannelError::Close((msg, reason)) => {
3184
3184
let (mut shutdown_res, chan_update) = $close(reason);
3185
3185
let logger = WithChannelContext::from(&$self.logger, &$chan.context(), None);
3186
3186
log_error!(logger, "Closed channel {} due to close-required error: {}", $channel_id, msg);
3187
3187
$locked_close(&mut shutdown_res, $chan);
3188
3188
let err =
3189
- MsgHandleErrInternal::from_finish_shutdown(msg, * $channel_id, shutdown_res, chan_update);
3189
+ MsgHandleErrInternal::from_finish_shutdown(msg, $channel_id, shutdown_res, chan_update);
3190
3190
(true, err)
3191
3191
},
3192
3192
ChannelError::SendError(msg) => {
3193
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::SendError(msg), * $channel_id))
3193
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::SendError(msg), $channel_id))
3194
3194
},
3195
3195
}
3196
- };
3197
- ($self: ident, $peer_state: expr, $shutdown_result: expr, $funded_channel: expr, $channel_id: expr, COOP_CLOSED) => { {
3196
+ } };
3197
+ ($self: ident, $peer_state: expr, $shutdown_result: expr, $funded_channel: expr, COOP_CLOSED) => { {
3198
+ let chan_id = $funded_channel.context.channel_id();
3198
3199
let reason = ChannelError::Close(("Coop Closed".to_owned(), $shutdown_result.closure_reason.clone()));
3199
3200
let do_close = |_| {
3200
3201
(
@@ -3206,12 +3207,13 @@ macro_rules! convert_channel_err {
3206
3207
locked_close_channel!($self, $peer_state, funded_channel, shutdown_res_mut, FUNDED);
3207
3208
};
3208
3209
let (close, mut err) =
3209
- convert_channel_err!($self, $peer_state, reason, $funded_channel, do_close, locked_close, $channel_id , _internal);
3210
+ convert_channel_err!($self, $peer_state, reason, $funded_channel, do_close, locked_close, chan_id , _internal);
3210
3211
err.dont_send_error_message();
3211
3212
debug_assert!(close);
3212
3213
err
3213
3214
} };
3214
- ($self: ident, $peer_state: expr, $err: expr, $funded_channel: expr, $channel_id: expr, FUNDED_CHANNEL) => { {
3215
+ ($self: ident, $peer_state: expr, $err: expr, $funded_channel: expr, FUNDED_CHANNEL) => { {
3216
+ let chan_id = $funded_channel.context.channel_id();
3215
3217
let mut do_close = |reason| {
3216
3218
(
3217
3219
$funded_channel.force_shutdown(reason),
@@ -3221,20 +3223,21 @@ macro_rules! convert_channel_err {
3221
3223
let mut locked_close = |shutdown_res_mut: &mut ShutdownResult, funded_channel: &mut FundedChannel<_>| {
3222
3224
locked_close_channel!($self, $peer_state, funded_channel, shutdown_res_mut, FUNDED);
3223
3225
};
3224
- convert_channel_err!($self, $peer_state, $err, $funded_channel, do_close, locked_close, $channel_id , _internal)
3226
+ convert_channel_err!($self, $peer_state, $err, $funded_channel, do_close, locked_close, chan_id , _internal)
3225
3227
} };
3226
- ($self: ident, $peer_state: expr, $err: expr, $channel: expr, $channel_id: expr, UNFUNDED_CHANNEL) => { {
3228
+ ($self: ident, $peer_state: expr, $err: expr, $channel: expr, UNFUNDED_CHANNEL) => { {
3229
+ let chan_id = $channel.context().channel_id();
3227
3230
let mut do_close = |reason| { ($channel.force_shutdown(reason), None) };
3228
3231
let locked_close = |_, chan: &mut Channel<_>| { locked_close_channel!($self, chan.context(), UNFUNDED); };
3229
- convert_channel_err!($self, $peer_state, $err, $channel, do_close, locked_close, $channel_id , _internal)
3232
+ convert_channel_err!($self, $peer_state, $err, $channel, do_close, locked_close, chan_id , _internal)
3230
3233
} };
3231
- ($self: ident, $peer_state: expr, $err: expr, $channel: expr, $channel_id: expr ) => {
3234
+ ($self: ident, $peer_state: expr, $err: expr, $channel: expr) => {
3232
3235
match $channel.as_funded_mut() {
3233
3236
Some(funded_channel) => {
3234
- convert_channel_err!($self, $peer_state, $err, funded_channel, $channel_id, FUNDED_CHANNEL)
3237
+ convert_channel_err!($self, $peer_state, $err, funded_channel, FUNDED_CHANNEL)
3235
3238
},
3236
3239
None => {
3237
- convert_channel_err!($self, $peer_state, $err, $channel, $channel_id, UNFUNDED_CHANNEL)
3240
+ convert_channel_err!($self, $peer_state, $err, $channel, UNFUNDED_CHANNEL)
3238
3241
},
3239
3242
}
3240
3243
};
@@ -3245,9 +3248,7 @@ macro_rules! break_channel_entry {
3245
3248
match $res {
3246
3249
Ok(res) => res,
3247
3250
Err(e) => {
3248
- let key = *$entry.key();
3249
- let (drop, res) =
3250
- convert_channel_err!($self, $peer_state, e, $entry.get_mut(), &key);
3251
+ let (drop, res) = convert_channel_err!($self, $peer_state, e, $entry.get_mut());
3251
3252
if drop {
3252
3253
$entry.remove_entry();
3253
3254
}
@@ -3262,9 +3263,7 @@ macro_rules! try_channel_entry {
3262
3263
match $res {
3263
3264
Ok(res) => res,
3264
3265
Err(e) => {
3265
- let key = *$entry.key();
3266
- let (drop, res) =
3267
- convert_channel_err!($self, $peer_state, e, $entry.get_mut(), &key);
3266
+ let (drop, res) = convert_channel_err!($self, $peer_state, e, $entry.get_mut());
3268
3267
if drop {
3269
3268
$entry.remove_entry();
3270
3269
}
@@ -4106,7 +4105,7 @@ where
4106
4105
let reason = ClosureReason::LocallyCoopClosedUnfundedChannel;
4107
4106
let err = ChannelError::Close((reason.to_string(), reason));
4108
4107
let mut chan = chan_entry.remove();
4109
- let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan, chan_id );
4108
+ let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan);
4110
4109
e.dont_send_error_message();
4111
4110
shutdown_result = Err(e);
4112
4111
}
@@ -4303,7 +4302,7 @@ where
4303
4302
if let Some(mut chan) = peer_state.channel_by_id.remove(&channel_id) {
4304
4303
let reason = ClosureReason::FundingBatchClosure;
4305
4304
let err = ChannelError::Close((reason.to_string(), reason));
4306
- let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan, &channel_id );
4305
+ let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan);
4307
4306
shutdown_results.push((Err(e), counterparty_node_id));
4308
4307
}
4309
4308
}
@@ -4367,7 +4366,7 @@ where
4367
4366
if let Some(mut chan) = peer_state.channel_by_id.remove(channel_id) {
4368
4367
log_error!(logger, "Force-closing channel {}", channel_id);
4369
4368
let err = ChannelError::Close((message, reason));
4370
- let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan, channel_id );
4369
+ let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan);
4371
4370
mem::drop(peer_state_lock);
4372
4371
mem::drop(per_peer_state);
4373
4372
if is_from_counterparty {
@@ -5843,7 +5842,7 @@ where
5843
5842
let reason = ClosureReason::ProcessingError { err: e.clone() };
5844
5843
let err = ChannelError::Close((e.clone(), reason));
5845
5844
let (_, e) =
5846
- convert_channel_err!(self, peer_state, err, &mut chan, &channel_id );
5845
+ convert_channel_err!(self, peer_state, err, &mut chan);
5847
5846
shutdown_results.push((Err(e), counterparty_node_id));
5848
5847
});
5849
5848
}
@@ -7260,7 +7259,7 @@ where
7260
7259
if chan_needs_persist == NotifyOption::DoPersist { should_persist = NotifyOption::DoPersist; }
7261
7260
7262
7261
if let Err(e) = funded_chan.timer_check_closing_negotiation_progress() {
7263
- let (needs_close, err) = convert_channel_err!(self, peer_state, e, funded_chan, chan_id, FUNDED_CHANNEL);
7262
+ let (needs_close, err) = convert_channel_err!(self, peer_state, e, funded_chan, FUNDED_CHANNEL);
7264
7263
handle_errors.push((Err(err), counterparty_node_id));
7265
7264
if needs_close { return false; }
7266
7265
}
@@ -7338,7 +7337,7 @@ where
7338
7337
let reason = ClosureReason::FundingTimedOut;
7339
7338
let msg = "Force-closing pending channel due to timeout awaiting establishment handshake".to_owned();
7340
7339
let err = ChannelError::Close((msg, reason));
7341
- let (_, e) = convert_channel_err!(self, peer_state, err, chan, chan_id );
7340
+ let (_, e) = convert_channel_err!(self, peer_state, err, chan);
7342
7341
handle_errors.push((Err(e), counterparty_node_id));
7343
7342
false
7344
7343
} else {
@@ -9173,18 +9172,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9173
9172
// above so at this point we just need to clean up any lingering entries
9174
9173
// concerning this channel as it is safe to do so.
9175
9174
debug_assert!(matches!(err, ChannelError::Close(_)));
9176
- // Really we should be returning the channel_id the peer expects based
9177
- // on their funding info here, but they're horribly confused anyway, so
9178
- // there's not a lot we can do to save them.
9179
9175
let mut chan = Channel::from(inbound_chan);
9180
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &msg.temporary_channel_id, UNFUNDED_CHANNEL ).1);
9176
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan).1);
9181
9177
},
9182
9178
}
9183
9179
},
9184
9180
Some(Err(mut chan)) => {
9185
9181
let err_msg = format!("Got an unexpected funding_created message from peer with counterparty_node_id {}", counterparty_node_id);
9186
9182
let err = ChannelError::close(err_msg);
9187
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &msg.temporary_channel_id ).1);
9183
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan).1);
9188
9184
},
9189
9185
None => return Err(MsgHandleErrInternal::send_err_msg_no_close(format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", counterparty_node_id), msg.temporary_channel_id))
9190
9186
};
@@ -9200,7 +9196,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9200
9196
let err = ChannelError::close($err.to_owned());
9201
9197
chan.unset_funding_info();
9202
9198
let mut chan = Channel::from(chan);
9203
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &funded_channel_id, UNFUNDED_CHANNEL).1);
9199
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan, UNFUNDED_CHANNEL).1);
9204
9200
} } }
9205
9201
9206
9202
match peer_state.channel_by_id.entry(funded_channel_id) {
@@ -9740,8 +9736,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9740
9736
let reason = ClosureReason::CounterpartyCoopClosedUnfundedChannel;
9741
9737
let err = ChannelError::Close((reason.to_string(), reason));
9742
9738
let mut chan = chan_entry.remove();
9743
- let (_, mut e) =
9744
- convert_channel_err!(self, peer_state, err, &mut chan, &msg.channel_id);
9739
+ let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan);
9745
9740
e.dont_send_error_message();
9746
9741
return Err(e);
9747
9742
},
@@ -9800,7 +9795,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9800
9795
// also implies there are no pending HTLCs left on the channel, so we can
9801
9796
// fully delete it from tracking (the channel monitor is still around to
9802
9797
// watch for old state broadcasts)!
9803
- let err = convert_channel_err!(self, peer_state, close_res, chan, &msg.channel_id, COOP_CLOSED);
9798
+ let err = convert_channel_err!(self, peer_state, close_res, chan, COOP_CLOSED);
9804
9799
chan_entry.remove();
9805
9800
Some((tx, Err(err)))
9806
9801
} else {
@@ -10887,13 +10882,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10887
10882
};
10888
10883
let err = ChannelError::Close((reason.to_string(), reason));
10889
10884
let mut chan = chan_entry.remove();
10890
- let (_, e) = convert_channel_err!(
10891
- self,
10892
- peer_state,
10893
- err,
10894
- &mut chan,
10895
- &channel_id
10896
- );
10885
+ let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan);
10897
10886
failed_channels.push((Err(e), counterparty_node_id));
10898
10887
}
10899
10888
}
@@ -11098,13 +11087,14 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
11098
11087
let chan_id = context.channel_id();
11099
11088
log_trace!(logger, "Removing channel {} now that the signer is unblocked", chan_id);
11100
11089
let (remove, err) = if let Some(funded) = chan.as_funded_mut() {
11101
- let err = convert_channel_err!(self, peer_state, shutdown, funded, &chan_id, COOP_CLOSED);
11090
+ let err =
11091
+ convert_channel_err!(self, peer_state, shutdown, funded, COOP_CLOSED);
11102
11092
(true, err)
11103
11093
} else {
11104
11094
debug_assert!(false);
11105
11095
let reason = shutdown.closure_reason.clone();
11106
11096
let err = ChannelError::Close((reason.to_string(), reason));
11107
- convert_channel_err!(self, peer_state, err, chan, &chan_id, UNFUNDED_CHANNEL)
11097
+ convert_channel_err!(self, peer_state, err, chan, UNFUNDED_CHANNEL)
11108
11098
};
11109
11099
debug_assert!(remove);
11110
11100
shutdown_results.push((Err(err), *cp_id));
@@ -11134,7 +11124,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
11134
11124
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
11135
11125
let peer_state = &mut *peer_state_lock;
11136
11126
let pending_msg_events = &mut peer_state.pending_msg_events;
11137
- peer_state.channel_by_id.retain(|channel_id , chan| {
11127
+ peer_state.channel_by_id.retain(|_ , chan| {
11138
11128
match chan.as_funded_mut() {
11139
11129
Some(funded_chan) => {
11140
11130
let logger = WithChannelContext::from(&self.logger, &funded_chan.context, None);
@@ -11150,7 +11140,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
11150
11140
if let Some((tx, shutdown_res)) = tx_shutdown_result_opt {
11151
11141
// We're done with this channel. We got a closing_signed and sent back
11152
11142
// a closing_signed with a closing transaction to broadcast.
11153
- let err = convert_channel_err!(self, peer_state, shutdown_res, funded_chan, channel_id, COOP_CLOSED);
11143
+ let err = convert_channel_err!(self, peer_state, shutdown_res, funded_chan, COOP_CLOSED);
11154
11144
handle_errors.push((*cp_id, Err(err)));
11155
11145
11156
11146
log_info!(logger, "Broadcasting {}", log_tx!(tx));
@@ -11160,7 +11150,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
11160
11150
},
11161
11151
Err(e) => {
11162
11152
has_update = true;
11163
- let (close_channel, res) = convert_channel_err!(self, peer_state, e, funded_chan, channel_id, FUNDED_CHANNEL);
11153
+ let (close_channel, res) = convert_channel_err!(self, peer_state, e, funded_chan, FUNDED_CHANNEL);
11164
11154
handle_errors.push((funded_chan.context.get_counterparty_node_id(), Err(res)));
11165
11155
!close_channel
11166
11156
}
@@ -12414,15 +12404,15 @@ where
12414
12404
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
12415
12405
let peer_state = &mut *peer_state_lock;
12416
12406
let pending_msg_events = &mut peer_state.pending_msg_events;
12417
- peer_state.channel_by_id.retain(|chan_id , chan| {
12407
+ peer_state.channel_by_id.retain(|_ , chan| {
12418
12408
let logger = WithChannelContext::from(&self.logger, &chan.context(), None);
12419
12409
if chan.peer_disconnected_is_resumable(&&logger) {
12420
12410
return true;
12421
12411
}
12422
12412
// Clean up for removal.
12423
12413
let reason = ClosureReason::DisconnectedPeer;
12424
12414
let err = ChannelError::Close((reason.to_string(), reason));
12425
- let (_, e) = convert_channel_err!(self, peer_state, err, chan, chan_id );
12415
+ let (_, e) = convert_channel_err!(self, peer_state, err, chan);
12426
12416
failed_channels.push((Err(e), counterparty_node_id));
12427
12417
false
12428
12418
});
@@ -12975,7 +12965,7 @@ where
12975
12965
let peer_state = &mut *peer_state_lock;
12976
12966
let pending_msg_events = &mut peer_state.pending_msg_events;
12977
12967
12978
- peer_state.channel_by_id.retain(|chan_id , chan| {
12968
+ peer_state.channel_by_id.retain(|channel_id , chan| {
12979
12969
match chan.as_funded_mut() {
12980
12970
// Retain unfunded channels.
12981
12971
None => true,
@@ -12986,22 +12976,22 @@ where
12986
12976
let reason = LocalHTLCFailureReason::CLTVExpiryTooSoon;
12987
12977
let data = self.get_htlc_inbound_temp_fail_data(reason);
12988
12978
timed_out_htlcs.push((source, payment_hash, HTLCFailReason::reason(reason, data),
12989
- HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: funded_channel.context. channel_id() }));
12979
+ HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: * channel_id }));
12990
12980
}
12991
12981
let logger = WithChannelContext::from(&self.logger, &funded_channel.context, None);
12992
12982
match funding_confirmed_opt {
12993
12983
Some(FundingConfirmedMessage::Establishment(channel_ready)) => {
12994
12984
send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
12995
12985
if funded_channel.context.is_usable() {
12996
- log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", funded_channel.context. channel_id() );
12986
+ log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", channel_id);
12997
12987
if let Ok(msg) = self.get_channel_update_for_unicast(funded_channel) {
12998
12988
pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
12999
12989
node_id: funded_channel.context.get_counterparty_node_id(),
13000
12990
msg,
13001
12991
});
13002
12992
}
13003
12993
} else {
13004
- log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", funded_channel.context. channel_id() );
12994
+ log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", channel_id);
13005
12995
}
13006
12996
},
13007
12997
#[cfg(splicing)]
@@ -13012,7 +13002,7 @@ where
13012
13002
13013
13003
let mut pending_events = self.pending_events.lock().unwrap();
13014
13004
pending_events.push_back((events::Event::ChannelReady {
13015
- channel_id: funded_channel.context. channel_id() ,
13005
+ channel_id: * channel_id,
13016
13006
user_channel_id: funded_channel.context.get_user_id(),
13017
13007
counterparty_node_id: funded_channel.context.get_counterparty_node_id(),
13018
13008
funding_txo: funding_txo.map(|outpoint| outpoint.into_bitcoin_outpoint()),
@@ -13084,8 +13074,8 @@ where
13084
13074
// un-confirmed we force-close the channel, ensuring short_to_chan_info
13085
13075
// is always consistent.
13086
13076
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
13087
- let scid_insert = short_to_chan_info.insert(real_scid, (funded_channel.context.get_counterparty_node_id(), funded_channel.context. channel_id() ));
13088
- assert!(scid_insert.is_none() || scid_insert.unwrap() == (funded_channel.context.get_counterparty_node_id(), funded_channel.context. channel_id() ),
13077
+ let scid_insert = short_to_chan_info.insert(real_scid, (funded_channel.context.get_counterparty_node_id(), * channel_id));
13078
+ assert!(scid_insert.is_none() || scid_insert.unwrap() == (funded_channel.context.get_counterparty_node_id(), * channel_id),
13089
13079
"SCIDs should never collide - ensure you weren't behind by a full {} blocks when creating channels",
13090
13080
fake_scid::MAX_SCID_BLOCKS_FROM_NOW);
13091
13081
}
@@ -13099,7 +13089,6 @@ where
13099
13089
peer_state,
13100
13090
err,
13101
13091
funded_channel,
13102
- chan_id,
13103
13092
FUNDED_CHANNEL
13104
13093
);
13105
13094
failed_channels.push((Err(e), *counterparty_node_id));
0 commit comments