@@ -3167,32 +3167,33 @@ macro_rules! locked_close_channel {
3167
3167
/// Returns (boolean indicating if we should remove the Channel object from memory, a mapped error)
3168
3168
#[rustfmt::skip]
3169
3169
macro_rules! convert_channel_err {
3170
- ($self: ident, $peer_state: expr, $err: expr, $chan: expr, $close: expr, $locked_close: expr, $channel_id: expr, _internal) => {
3170
+ ($self: ident, $peer_state: expr, $err: expr, $chan: expr, $close: expr, $locked_close: expr, $channel_id: expr, _internal) => { {
3171
3171
match $err {
3172
3172
ChannelError::Warn(msg) => {
3173
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), * $channel_id))
3173
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), $channel_id))
3174
3174
},
3175
3175
ChannelError::WarnAndDisconnect(msg) => {
3176
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::WarnAndDisconnect(msg), * $channel_id))
3176
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::WarnAndDisconnect(msg), $channel_id))
3177
3177
},
3178
3178
ChannelError::Ignore(msg) => {
3179
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), * $channel_id))
3179
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), $channel_id))
3180
3180
},
3181
3181
ChannelError::Close((msg, reason)) => {
3182
3182
let (mut shutdown_res, chan_update) = $close(reason);
3183
3183
let logger = WithChannelContext::from(&$self.logger, &$chan.context(), None);
3184
3184
log_error!(logger, "Closed channel {} due to close-required error: {}", $channel_id, msg);
3185
3185
$locked_close(&mut shutdown_res, $chan);
3186
3186
let err =
3187
- MsgHandleErrInternal::from_finish_shutdown(msg, * $channel_id, shutdown_res, chan_update);
3187
+ MsgHandleErrInternal::from_finish_shutdown(msg, $channel_id, shutdown_res, chan_update);
3188
3188
(true, err)
3189
3189
},
3190
3190
ChannelError::SendError(msg) => {
3191
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::SendError(msg), * $channel_id))
3191
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::SendError(msg), $channel_id))
3192
3192
},
3193
3193
}
3194
- };
3195
- ($self: ident, $peer_state: expr, $shutdown_result: expr, $funded_channel: expr, $channel_id: expr, COOP_CLOSED) => { {
3194
+ } };
3195
+ ($self: ident, $peer_state: expr, $shutdown_result: expr, $funded_channel: expr, COOP_CLOSED) => { {
3196
+ let chan_id = $funded_channel.context.channel_id();
3196
3197
let reason = ChannelError::Close(("Coop Closed".to_owned(), $shutdown_result.closure_reason.clone()));
3197
3198
let do_close = |_| {
3198
3199
(
@@ -3204,12 +3205,13 @@ macro_rules! convert_channel_err {
3204
3205
locked_close_channel!($self, $peer_state, funded_channel, shutdown_res_mut, FUNDED);
3205
3206
};
3206
3207
let (close, mut err) =
3207
- convert_channel_err!($self, $peer_state, reason, $funded_channel, do_close, locked_close, $channel_id , _internal);
3208
+ convert_channel_err!($self, $peer_state, reason, $funded_channel, do_close, locked_close, chan_id , _internal);
3208
3209
err.dont_send_error_message();
3209
3210
debug_assert!(close);
3210
3211
err
3211
3212
} };
3212
- ($self: ident, $peer_state: expr, $err: expr, $funded_channel: expr, $channel_id: expr, FUNDED_CHANNEL) => { {
3213
+ ($self: ident, $peer_state: expr, $err: expr, $funded_channel: expr, FUNDED_CHANNEL) => { {
3214
+ let chan_id = $funded_channel.context.channel_id();
3213
3215
let mut do_close = |reason| {
3214
3216
(
3215
3217
$funded_channel.force_shutdown(reason),
@@ -3219,20 +3221,21 @@ macro_rules! convert_channel_err {
3219
3221
let mut locked_close = |shutdown_res_mut: &mut ShutdownResult, funded_channel: &mut FundedChannel<_>| {
3220
3222
locked_close_channel!($self, $peer_state, funded_channel, shutdown_res_mut, FUNDED);
3221
3223
};
3222
- convert_channel_err!($self, $peer_state, $err, $funded_channel, do_close, locked_close, $channel_id , _internal)
3224
+ convert_channel_err!($self, $peer_state, $err, $funded_channel, do_close, locked_close, chan_id , _internal)
3223
3225
} };
3224
- ($self: ident, $peer_state: expr, $err: expr, $channel: expr, $channel_id: expr, UNFUNDED_CHANNEL) => { {
3226
+ ($self: ident, $peer_state: expr, $err: expr, $channel: expr, UNFUNDED_CHANNEL) => { {
3227
+ let chan_id = $channel.context().channel_id();
3225
3228
let mut do_close = |reason| { ($channel.force_shutdown(reason), None) };
3226
3229
let locked_close = |_, chan: &mut Channel<_>| { locked_close_channel!($self, chan.context(), UNFUNDED); };
3227
- convert_channel_err!($self, $peer_state, $err, $channel, do_close, locked_close, $channel_id , _internal)
3230
+ convert_channel_err!($self, $peer_state, $err, $channel, do_close, locked_close, chan_id , _internal)
3228
3231
} };
3229
- ($self: ident, $peer_state: expr, $err: expr, $channel: expr, $channel_id: expr ) => {
3232
+ ($self: ident, $peer_state: expr, $err: expr, $channel: expr) => {
3230
3233
match $channel.as_funded_mut() {
3231
3234
Some(funded_channel) => {
3232
- convert_channel_err!($self, $peer_state, $err, funded_channel, $channel_id, FUNDED_CHANNEL)
3235
+ convert_channel_err!($self, $peer_state, $err, funded_channel, FUNDED_CHANNEL)
3233
3236
},
3234
3237
None => {
3235
- convert_channel_err!($self, $peer_state, $err, $channel, $channel_id, UNFUNDED_CHANNEL)
3238
+ convert_channel_err!($self, $peer_state, $err, $channel, UNFUNDED_CHANNEL)
3236
3239
},
3237
3240
}
3238
3241
};
@@ -3243,9 +3246,7 @@ macro_rules! break_channel_entry {
3243
3246
match $res {
3244
3247
Ok(res) => res,
3245
3248
Err(e) => {
3246
- let key = *$entry.key();
3247
- let (drop, res) =
3248
- convert_channel_err!($self, $peer_state, e, $entry.get_mut(), &key);
3249
+ let (drop, res) = convert_channel_err!($self, $peer_state, e, $entry.get_mut());
3249
3250
if drop {
3250
3251
$entry.remove_entry();
3251
3252
}
@@ -3260,9 +3261,7 @@ macro_rules! try_channel_entry {
3260
3261
match $res {
3261
3262
Ok(res) => res,
3262
3263
Err(e) => {
3263
- let key = *$entry.key();
3264
- let (drop, res) =
3265
- convert_channel_err!($self, $peer_state, e, $entry.get_mut(), &key);
3264
+ let (drop, res) = convert_channel_err!($self, $peer_state, e, $entry.get_mut());
3266
3265
if drop {
3267
3266
$entry.remove_entry();
3268
3267
}
@@ -4105,7 +4104,7 @@ where
4105
4104
let reason = ClosureReason::LocallyCoopClosedUnfundedChannel;
4106
4105
let err = ChannelError::Close((reason.to_string(), reason));
4107
4106
let mut chan = chan_entry.remove();
4108
- let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan, chan_id );
4107
+ let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan);
4109
4108
e.dont_send_error_message();
4110
4109
shutdown_result = Err(e);
4111
4110
}
@@ -4302,7 +4301,7 @@ where
4302
4301
if let Some(mut chan) = peer_state.channel_by_id.remove(&channel_id) {
4303
4302
let reason = ClosureReason::FundingBatchClosure;
4304
4303
let err = ChannelError::Close((reason.to_string(), reason));
4305
- let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan, &channel_id );
4304
+ let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan);
4306
4305
shutdown_results.push((Err(e), counterparty_node_id));
4307
4306
}
4308
4307
}
@@ -4366,7 +4365,7 @@ where
4366
4365
if let Some(mut chan) = peer_state.channel_by_id.remove(channel_id) {
4367
4366
log_error!(logger, "Force-closing channel {}", channel_id);
4368
4367
let err = ChannelError::Close((message, reason));
4369
- let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan, channel_id );
4368
+ let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan);
4370
4369
mem::drop(peer_state_lock);
4371
4370
mem::drop(per_peer_state);
4372
4371
if is_from_counterparty {
@@ -5842,7 +5841,7 @@ where
5842
5841
let reason = ClosureReason::ProcessingError { err: e.clone() };
5843
5842
let err = ChannelError::Close((e.clone(), reason));
5844
5843
let (_, e) =
5845
- convert_channel_err!(self, peer_state, err, &mut chan, &channel_id );
5844
+ convert_channel_err!(self, peer_state, err, &mut chan);
5846
5845
shutdown_results.push((Err(e), counterparty_node_id));
5847
5846
});
5848
5847
}
@@ -7308,7 +7307,7 @@ where
7308
7307
if chan_needs_persist == NotifyOption::DoPersist { should_persist = NotifyOption::DoPersist; }
7309
7308
7310
7309
if let Err(e) = funded_chan.timer_check_closing_negotiation_progress() {
7311
- let (needs_close, err) = convert_channel_err!(self, peer_state, e, funded_chan, chan_id, FUNDED_CHANNEL);
7310
+ let (needs_close, err) = convert_channel_err!(self, peer_state, e, funded_chan, FUNDED_CHANNEL);
7312
7311
handle_errors.push((Err(err), counterparty_node_id));
7313
7312
if needs_close { return false; }
7314
7313
}
@@ -7386,7 +7385,7 @@ where
7386
7385
let reason = ClosureReason::FundingTimedOut;
7387
7386
let msg = "Force-closing pending channel due to timeout awaiting establishment handshake".to_owned();
7388
7387
let err = ChannelError::Close((msg, reason));
7389
- let (_, e) = convert_channel_err!(self, peer_state, err, chan, chan_id );
7388
+ let (_, e) = convert_channel_err!(self, peer_state, err, chan);
7390
7389
handle_errors.push((Err(e), counterparty_node_id));
7391
7390
false
7392
7391
} else {
@@ -9202,18 +9201,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9202
9201
// above so at this point we just need to clean up any lingering entries
9203
9202
// concerning this channel as it is safe to do so.
9204
9203
debug_assert!(matches!(err, ChannelError::Close(_)));
9205
- // Really we should be returning the channel_id the peer expects based
9206
- // on their funding info here, but they're horribly confused anyway, so
9207
- // there's not a lot we can do to save them.
9208
9204
let mut chan = Channel::from(inbound_chan);
9209
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &msg.temporary_channel_id, UNFUNDED_CHANNEL ).1);
9205
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan).1);
9210
9206
},
9211
9207
}
9212
9208
},
9213
9209
Some(Err(mut chan)) => {
9214
9210
let err_msg = format!("Got an unexpected funding_created message from peer with counterparty_node_id {}", counterparty_node_id);
9215
9211
let err = ChannelError::close(err_msg);
9216
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &msg.temporary_channel_id ).1);
9212
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan).1);
9217
9213
},
9218
9214
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))
9219
9215
};
@@ -9229,7 +9225,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9229
9225
let err = ChannelError::close($err.to_owned());
9230
9226
chan.unset_funding_info();
9231
9227
let mut chan = Channel::from(chan);
9232
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &funded_channel_id, UNFUNDED_CHANNEL).1);
9228
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan, UNFUNDED_CHANNEL).1);
9233
9229
} } }
9234
9230
9235
9231
match peer_state.channel_by_id.entry(funded_channel_id) {
@@ -9769,8 +9765,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9769
9765
let reason = ClosureReason::CounterpartyCoopClosedUnfundedChannel;
9770
9766
let err = ChannelError::Close((reason.to_string(), reason));
9771
9767
let mut chan = chan_entry.remove();
9772
- let (_, mut e) =
9773
- convert_channel_err!(self, peer_state, err, &mut chan, &msg.channel_id);
9768
+ let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan);
9774
9769
e.dont_send_error_message();
9775
9770
return Err(e);
9776
9771
},
@@ -9829,7 +9824,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9829
9824
// also implies there are no pending HTLCs left on the channel, so we can
9830
9825
// fully delete it from tracking (the channel monitor is still around to
9831
9826
// watch for old state broadcasts)!
9832
- let err = convert_channel_err!(self, peer_state, close_res, chan, &msg.channel_id, COOP_CLOSED);
9827
+ let err = convert_channel_err!(self, peer_state, close_res, chan, COOP_CLOSED);
9833
9828
chan_entry.remove();
9834
9829
Some((tx, Err(err)))
9835
9830
} else {
@@ -10881,13 +10876,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10881
10876
};
10882
10877
let err = ChannelError::Close((reason.to_string(), reason));
10883
10878
let mut chan = chan_entry.remove();
10884
- let (_, e) = convert_channel_err!(
10885
- self,
10886
- peer_state,
10887
- err,
10888
- &mut chan,
10889
- &channel_id
10890
- );
10879
+ let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan);
10891
10880
failed_channels.push((Err(e), counterparty_node_id));
10892
10881
}
10893
10882
}
@@ -11083,13 +11072,14 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
11083
11072
let chan_id = context.channel_id();
11084
11073
log_trace!(logger, "Removing channel {} now that the signer is unblocked", chan_id);
11085
11074
let (remove, err) = if let Some(funded) = chan.as_funded_mut() {
11086
- let err = convert_channel_err!(self, peer_state, shutdown, funded, &chan_id, COOP_CLOSED);
11075
+ let err =
11076
+ convert_channel_err!(self, peer_state, shutdown, funded, COOP_CLOSED);
11087
11077
(true, err)
11088
11078
} else {
11089
11079
debug_assert!(false);
11090
11080
let reason = shutdown.closure_reason.clone();
11091
11081
let err = ChannelError::Close((reason.to_string(), reason));
11092
- convert_channel_err!(self, peer_state, err, chan, &chan_id, UNFUNDED_CHANNEL)
11082
+ convert_channel_err!(self, peer_state, err, chan, UNFUNDED_CHANNEL)
11093
11083
};
11094
11084
debug_assert!(remove);
11095
11085
shutdown_results.push((Err(err), *cp_id));
@@ -11119,7 +11109,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
11119
11109
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
11120
11110
let peer_state = &mut *peer_state_lock;
11121
11111
let pending_msg_events = &mut peer_state.pending_msg_events;
11122
- peer_state.channel_by_id.retain(|channel_id , chan| {
11112
+ peer_state.channel_by_id.retain(|_ , chan| {
11123
11113
match chan.as_funded_mut() {
11124
11114
Some(funded_chan) => {
11125
11115
let logger = WithChannelContext::from(&self.logger, &funded_chan.context, None);
@@ -11135,7 +11125,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
11135
11125
if let Some((tx, shutdown_res)) = tx_shutdown_result_opt {
11136
11126
// We're done with this channel. We got a closing_signed and sent back
11137
11127
// a closing_signed with a closing transaction to broadcast.
11138
- let err = convert_channel_err!(self, peer_state, shutdown_res, funded_chan, channel_id, COOP_CLOSED);
11128
+ let err = convert_channel_err!(self, peer_state, shutdown_res, funded_chan, COOP_CLOSED);
11139
11129
handle_errors.push((*cp_id, Err(err)));
11140
11130
11141
11131
log_info!(logger, "Broadcasting {}", log_tx!(tx));
@@ -11145,7 +11135,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
11145
11135
},
11146
11136
Err(e) => {
11147
11137
has_update = true;
11148
- let (close_channel, res) = convert_channel_err!(self, peer_state, e, funded_chan, channel_id, FUNDED_CHANNEL);
11138
+ let (close_channel, res) = convert_channel_err!(self, peer_state, e, funded_chan, FUNDED_CHANNEL);
11149
11139
handle_errors.push((funded_chan.context.get_counterparty_node_id(), Err(res)));
11150
11140
!close_channel
11151
11141
}
@@ -12399,15 +12389,15 @@ where
12399
12389
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
12400
12390
let peer_state = &mut *peer_state_lock;
12401
12391
let pending_msg_events = &mut peer_state.pending_msg_events;
12402
- peer_state.channel_by_id.retain(|chan_id , chan| {
12392
+ peer_state.channel_by_id.retain(|_ , chan| {
12403
12393
let logger = WithChannelContext::from(&self.logger, &chan.context(), None);
12404
12394
if chan.peer_disconnected_is_resumable(&&logger) {
12405
12395
return true;
12406
12396
}
12407
12397
// Clean up for removal.
12408
12398
let reason = ClosureReason::DisconnectedPeer;
12409
12399
let err = ChannelError::Close((reason.to_string(), reason));
12410
- let (_, e) = convert_channel_err!(self, peer_state, err, chan, chan_id );
12400
+ let (_, e) = convert_channel_err!(self, peer_state, err, chan);
12411
12401
failed_channels.push((Err(e), counterparty_node_id));
12412
12402
false
12413
12403
});
@@ -12962,7 +12952,7 @@ where
12962
12952
let peer_state = &mut *peer_state_lock;
12963
12953
let pending_msg_events = &mut peer_state.pending_msg_events;
12964
12954
12965
- peer_state.channel_by_id.retain(|chan_id , chan| {
12955
+ peer_state.channel_by_id.retain(|channel_id , chan| {
12966
12956
match chan.as_funded_mut() {
12967
12957
// Retain unfunded channels.
12968
12958
None => true,
@@ -12973,22 +12963,22 @@ where
12973
12963
let reason = LocalHTLCFailureReason::CLTVExpiryTooSoon;
12974
12964
let data = self.get_htlc_inbound_temp_fail_data(reason);
12975
12965
timed_out_htlcs.push((source, payment_hash, HTLCFailReason::reason(reason, data),
12976
- HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: funded_channel.context. channel_id() }));
12966
+ HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: * channel_id }));
12977
12967
}
12978
12968
let logger = WithChannelContext::from(&self.logger, &funded_channel.context, None);
12979
12969
match funding_confirmed_opt {
12980
12970
Some(FundingConfirmedMessage::Establishment(channel_ready)) => {
12981
12971
send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
12982
12972
if funded_channel.context.is_usable() {
12983
- log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", funded_channel.context. channel_id() );
12973
+ log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", channel_id);
12984
12974
if let Ok(msg) = self.get_channel_update_for_unicast(funded_channel) {
12985
12975
pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
12986
12976
node_id: funded_channel.context.get_counterparty_node_id(),
12987
12977
msg,
12988
12978
});
12989
12979
}
12990
12980
} else {
12991
- log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", funded_channel.context. channel_id() );
12981
+ log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", channel_id);
12992
12982
}
12993
12983
},
12994
12984
#[cfg(splicing)]
@@ -13016,7 +13006,7 @@ where
13016
13006
13017
13007
let mut pending_events = self.pending_events.lock().unwrap();
13018
13008
pending_events.push_back((events::Event::ChannelReady {
13019
- channel_id,
13009
+ channel_id: *channel_id ,
13020
13010
user_channel_id: funded_channel.context.get_user_id(),
13021
13011
counterparty_node_id,
13022
13012
funding_txo: Some(funding_txo.into_bitcoin_outpoint()),
@@ -13088,8 +13078,8 @@ where
13088
13078
// un-confirmed we force-close the channel, ensuring short_to_chan_info
13089
13079
// is always consistent.
13090
13080
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
13091
- let scid_insert = short_to_chan_info.insert(real_scid, (funded_channel.context.get_counterparty_node_id(), funded_channel.context. channel_id() ));
13092
- assert!(scid_insert.is_none() || scid_insert.unwrap() == (funded_channel.context.get_counterparty_node_id(), funded_channel.context. channel_id() ),
13081
+ let scid_insert = short_to_chan_info.insert(real_scid, (funded_channel.context.get_counterparty_node_id(), * channel_id));
13082
+ assert!(scid_insert.is_none() || scid_insert.unwrap() == (funded_channel.context.get_counterparty_node_id(), * channel_id),
13093
13083
"SCIDs should never collide - ensure you weren't behind by a full {} blocks when creating channels",
13094
13084
fake_scid::MAX_SCID_BLOCKS_FROM_NOW);
13095
13085
}
@@ -13103,7 +13093,6 @@ where
13103
13093
peer_state,
13104
13094
err,
13105
13095
funded_channel,
13106
- chan_id,
13107
13096
FUNDED_CHANNEL
13108
13097
);
13109
13098
failed_channels.push((Err(e), *counterparty_node_id));
0 commit comments