@@ -3217,32 +3217,33 @@ macro_rules! locked_close_channel {
3217
3217
/// Returns (boolean indicating if we should remove the Channel object from memory, a mapped error)
3218
3218
#[rustfmt::skip]
3219
3219
macro_rules! convert_channel_err {
3220
- ($self: ident, $peer_state: expr, $err: expr, $chan: expr, $close: expr, $locked_close: expr, $channel_id: expr, _internal) => {
3220
+ ($self: ident, $peer_state: expr, $err: expr, $chan: expr, $close: expr, $locked_close: expr, $channel_id: expr, _internal) => { {
3221
3221
match $err {
3222
3222
ChannelError::Warn(msg) => {
3223
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), * $channel_id))
3223
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), $channel_id))
3224
3224
},
3225
3225
ChannelError::WarnAndDisconnect(msg) => {
3226
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::WarnAndDisconnect(msg), * $channel_id))
3226
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::WarnAndDisconnect(msg), $channel_id))
3227
3227
},
3228
3228
ChannelError::Ignore(msg) => {
3229
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), * $channel_id))
3229
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), $channel_id))
3230
3230
},
3231
3231
ChannelError::Close((msg, reason)) => {
3232
3232
let (mut shutdown_res, chan_update) = $close(reason);
3233
3233
let logger = WithChannelContext::from(&$self.logger, &$chan.context(), None);
3234
3234
log_error!(logger, "Closed channel {} due to close-required error: {}", $channel_id, msg);
3235
3235
$locked_close(&mut shutdown_res, $chan);
3236
3236
let err =
3237
- MsgHandleErrInternal::from_finish_shutdown(msg, * $channel_id, shutdown_res, chan_update);
3237
+ MsgHandleErrInternal::from_finish_shutdown(msg, $channel_id, shutdown_res, chan_update);
3238
3238
(true, err)
3239
3239
},
3240
3240
ChannelError::SendError(msg) => {
3241
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::SendError(msg), * $channel_id))
3241
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::SendError(msg), $channel_id))
3242
3242
},
3243
3243
}
3244
- };
3245
- ($self: ident, $peer_state: expr, $shutdown_result: expr, $funded_channel: expr, $channel_id: expr, COOP_CLOSED) => { {
3244
+ } };
3245
+ ($self: ident, $peer_state: expr, $shutdown_result: expr, $funded_channel: expr, COOP_CLOSED) => { {
3246
+ let chan_id = $funded_channel.context.channel_id();
3246
3247
let reason = ChannelError::Close(("Coop Closed".to_owned(), $shutdown_result.closure_reason.clone()));
3247
3248
let do_close = |_| {
3248
3249
(
@@ -3254,12 +3255,13 @@ macro_rules! convert_channel_err {
3254
3255
locked_close_channel!($self, $peer_state, funded_channel, shutdown_res_mut, FUNDED);
3255
3256
};
3256
3257
let (close, mut err) =
3257
- convert_channel_err!($self, $peer_state, reason, $funded_channel, do_close, locked_close, $channel_id , _internal);
3258
+ convert_channel_err!($self, $peer_state, reason, $funded_channel, do_close, locked_close, chan_id , _internal);
3258
3259
err.dont_send_error_message();
3259
3260
debug_assert!(close);
3260
3261
(close, err)
3261
3262
} };
3262
- ($self: ident, $peer_state: expr, $err: expr, $funded_channel: expr, $channel_id: expr, FUNDED_CHANNEL) => { {
3263
+ ($self: ident, $peer_state: expr, $err: expr, $funded_channel: expr, FUNDED_CHANNEL) => { {
3264
+ let chan_id = $funded_channel.context.channel_id();
3263
3265
let mut do_close = |reason| {
3264
3266
(
3265
3267
$funded_channel.force_shutdown(reason),
@@ -3269,20 +3271,21 @@ macro_rules! convert_channel_err {
3269
3271
let mut locked_close = |shutdown_res_mut: &mut ShutdownResult, funded_channel: &mut FundedChannel<_>| {
3270
3272
locked_close_channel!($self, $peer_state, funded_channel, shutdown_res_mut, FUNDED);
3271
3273
};
3272
- convert_channel_err!($self, $peer_state, $err, $funded_channel, do_close, locked_close, $channel_id , _internal)
3274
+ convert_channel_err!($self, $peer_state, $err, $funded_channel, do_close, locked_close, chan_id , _internal)
3273
3275
} };
3274
- ($self: ident, $peer_state: expr, $err: expr, $channel: expr, $channel_id: expr, UNFUNDED_CHANNEL) => { {
3276
+ ($self: ident, $peer_state: expr, $err: expr, $channel: expr, UNFUNDED_CHANNEL) => { {
3277
+ let chan_id = $channel.context().channel_id();
3275
3278
let mut do_close = |reason| { ($channel.force_shutdown(reason), None) };
3276
3279
let locked_close = |_, chan: &mut Channel<_>| { locked_close_channel!($self, chan.context(), UNFUNDED); };
3277
- convert_channel_err!($self, $peer_state, $err, $channel, do_close, locked_close, $channel_id , _internal)
3280
+ convert_channel_err!($self, $peer_state, $err, $channel, do_close, locked_close, chan_id , _internal)
3278
3281
} };
3279
- ($self: ident, $peer_state: expr, $err: expr, $channel: expr, $channel_id: expr ) => {
3282
+ ($self: ident, $peer_state: expr, $err: expr, $channel: expr) => {
3280
3283
match $channel.as_funded_mut() {
3281
3284
Some(funded_channel) => {
3282
- convert_channel_err!($self, $peer_state, $err, funded_channel, $channel_id, FUNDED_CHANNEL)
3285
+ convert_channel_err!($self, $peer_state, $err, funded_channel, FUNDED_CHANNEL)
3283
3286
},
3284
3287
None => {
3285
- convert_channel_err!($self, $peer_state, $err, $channel, $channel_id, UNFUNDED_CHANNEL)
3288
+ convert_channel_err!($self, $peer_state, $err, $channel, UNFUNDED_CHANNEL)
3286
3289
},
3287
3290
}
3288
3291
};
@@ -3293,9 +3296,8 @@ macro_rules! break_channel_entry {
3293
3296
match $res {
3294
3297
Ok(res) => res,
3295
3298
Err(e) => {
3296
- let key = *$entry.key();
3297
3299
let (drop, res) =
3298
- convert_channel_err!($self, $peer_state, e, $entry.get_mut(), &key );
3300
+ convert_channel_err!($self, $peer_state, e, $entry.get_mut());
3299
3301
if drop {
3300
3302
$entry.remove_entry();
3301
3303
}
@@ -3310,9 +3312,8 @@ macro_rules! try_channel_entry {
3310
3312
match $res {
3311
3313
Ok(res) => res,
3312
3314
Err(e) => {
3313
- let key = *$entry.key();
3314
3315
let (drop, res) =
3315
- convert_channel_err!($self, $peer_state, e, $entry.get_mut(), &key );
3316
+ convert_channel_err!($self, $peer_state, e, $entry.get_mut());
3316
3317
if drop {
3317
3318
$entry.remove_entry();
3318
3319
}
@@ -4154,7 +4155,7 @@ where
4154
4155
let reason = ClosureReason::LocallyCoopClosedUnfundedChannel;
4155
4156
let err = ChannelError::Close((reason.to_string(), reason));
4156
4157
let mut chan = chan_entry.remove();
4157
- let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan, chan_id );
4158
+ let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan);
4158
4159
e.dont_send_error_message();
4159
4160
shutdown_result = Err(e);
4160
4161
}
@@ -4351,7 +4352,7 @@ where
4351
4352
if let Some(mut chan) = peer_state.channel_by_id.remove(&channel_id) {
4352
4353
let reason = ClosureReason::FundingBatchClosure;
4353
4354
let err = ChannelError::Close((reason.to_string(), reason));
4354
- let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan, &channel_id );
4355
+ let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan);
4355
4356
shutdown_results.push((Err(e), counterparty_node_id));
4356
4357
}
4357
4358
}
@@ -4415,7 +4416,7 @@ where
4415
4416
if let Some(mut chan) = peer_state.channel_by_id.remove(channel_id) {
4416
4417
log_error!(logger, "Force-closing channel {}", channel_id);
4417
4418
let err = ChannelError::Close((message, reason));
4418
- let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan, channel_id );
4419
+ let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan);
4419
4420
mem::drop(peer_state_lock);
4420
4421
mem::drop(per_peer_state);
4421
4422
if is_from_counterparty {
@@ -5894,7 +5895,7 @@ where
5894
5895
let reason = ClosureReason::ProcessingError { err: e.clone() };
5895
5896
let err = ChannelError::Close((e.clone(), reason));
5896
5897
let (_, e) =
5897
- convert_channel_err!(self, peer_state, err, &mut chan, &channel_id );
5898
+ convert_channel_err!(self, peer_state, err, &mut chan);
5898
5899
shutdown_results.push((Err(e), counterparty_node_id));
5899
5900
});
5900
5901
}
@@ -7062,7 +7063,7 @@ where
7062
7063
if chan_needs_persist == NotifyOption::DoPersist { should_persist = NotifyOption::DoPersist; }
7063
7064
7064
7065
if let Err(e) = funded_chan.timer_check_closing_negotiation_progress() {
7065
- let (needs_close, err) = convert_channel_err!(self, peer_state, e, funded_chan, chan_id, FUNDED_CHANNEL);
7066
+ let (needs_close, err) = convert_channel_err!(self, peer_state, e, funded_chan, FUNDED_CHANNEL);
7066
7067
handle_errors.push((Err(err), counterparty_node_id));
7067
7068
if needs_close { return false; }
7068
7069
}
@@ -7140,7 +7141,7 @@ where
7140
7141
let reason = ClosureReason::FundingTimedOut;
7141
7142
let msg = "Force-closing pending channel due to timeout awaiting establishment handshake".to_owned();
7142
7143
let err = ChannelError::Close((msg, reason));
7143
- let (_, e) = convert_channel_err!(self, peer_state, err, chan, chan_id );
7144
+ let (_, e) = convert_channel_err!(self, peer_state, err, chan);
7144
7145
handle_errors.push((Err(e), counterparty_node_id));
7145
7146
false
7146
7147
} else {
@@ -8726,18 +8727,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8726
8727
// above so at this point we just need to clean up any lingering entries
8727
8728
// concerning this channel as it is safe to do so.
8728
8729
debug_assert!(matches!(err, ChannelError::Close(_)));
8729
- // Really we should be returning the channel_id the peer expects based
8730
- // on their funding info here, but they're horribly confused anyway, so
8731
- // there's not a lot we can do to save them.
8732
8730
let mut chan = Channel::from(inbound_chan);
8733
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &msg.temporary_channel_id, UNFUNDED_CHANNEL ).1);
8731
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan).1);
8734
8732
},
8735
8733
}
8736
8734
},
8737
8735
Some(Err(mut chan)) => {
8738
8736
let err_msg = format!("Got an unexpected funding_created message from peer with counterparty_node_id {}", counterparty_node_id);
8739
8737
let err = ChannelError::close(err_msg);
8740
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &msg.temporary_channel_id ).1);
8738
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan).1);
8741
8739
},
8742
8740
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))
8743
8741
};
@@ -8753,7 +8751,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8753
8751
let err = ChannelError::close($err.to_owned());
8754
8752
chan.unset_funding_info();
8755
8753
let mut chan = Channel::from(chan);
8756
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &funded_channel_id, UNFUNDED_CHANNEL).1);
8754
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan, UNFUNDED_CHANNEL).1);
8757
8755
} } }
8758
8756
8759
8757
match peer_state.channel_by_id.entry(funded_channel_id) {
@@ -9294,7 +9292,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9294
9292
let err = ChannelError::Close((reason.to_string(), reason));
9295
9293
let mut chan = chan_entry.remove();
9296
9294
let (_, mut e) =
9297
- convert_channel_err!(self, peer_state, err, &mut chan, &msg.channel_id );
9295
+ convert_channel_err!(self, peer_state, err, &mut chan);
9298
9296
e.dont_send_error_message();
9299
9297
return Err(e);
9300
9298
},
@@ -9353,7 +9351,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9353
9351
// also implies there are no pending HTLCs left on the channel, so we can
9354
9352
// fully delete it from tracking (the channel monitor is still around to
9355
9353
// watch for old state broadcasts)!
9356
- let (_, err) = convert_channel_err!(self, peer_state, close_res, chan, &msg.channel_id, COOP_CLOSED);
9354
+ let (_, err) = convert_channel_err!(self, peer_state, close_res, chan, COOP_CLOSED);
9357
9355
chan_entry.remove();
9358
9356
Some((tx, Err(err)))
9359
9357
} else {
@@ -10316,7 +10314,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10316
10314
};
10317
10315
let err = ChannelError::Close((reason.to_string(), reason));
10318
10316
let mut chan = chan_entry.remove();
10319
- let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan, &channel_id );
10317
+ let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan);
10320
10318
failed_channels.push((Err(e), counterparty_node_id));
10321
10319
}
10322
10320
}
@@ -10504,12 +10502,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10504
10502
let chan_id = context.channel_id();
10505
10503
log_trace!(logger, "Removing channel {} now that the signer is unblocked", chan_id);
10506
10504
let (remove, err) = if let Some(funded_channel) = chan.as_funded_mut() {
10507
- convert_channel_err!(self, peer_state, shutdown_res, funded_channel, &chan_id, COOP_CLOSED)
10505
+ convert_channel_err!(self, peer_state, shutdown_res, funded_channel, COOP_CLOSED)
10508
10506
} else {
10509
10507
debug_assert!(false);
10510
10508
let reason = shutdown_res.closure_reason.clone();
10511
10509
let err = ChannelError::Close((reason.to_string(), reason));
10512
- convert_channel_err!(self, peer_state, err, chan, &chan_id, UNFUNDED_CHANNEL)
10510
+ convert_channel_err!(self, peer_state, err, chan, UNFUNDED_CHANNEL)
10513
10511
};
10514
10512
debug_assert!(remove);
10515
10513
shutdown_results.push((Err(err), *cp_id));
@@ -10539,7 +10537,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10539
10537
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
10540
10538
let peer_state = &mut *peer_state_lock;
10541
10539
let pending_msg_events = &mut peer_state.pending_msg_events;
10542
- peer_state.channel_by_id.retain(|channel_id , chan| {
10540
+ peer_state.channel_by_id.retain(|_ , chan| {
10543
10541
match chan.as_funded_mut() {
10544
10542
Some(funded_chan) => {
10545
10543
let logger = WithChannelContext::from(&self.logger, &funded_chan.context, None);
@@ -10555,7 +10553,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10555
10553
if let Some((tx, shutdown_res)) = tx_shutdown_result_opt {
10556
10554
// We're done with this channel. We got a closing_signed and sent back
10557
10555
// a closing_signed with a closing transaction to broadcast.
10558
- let (_, err) = convert_channel_err!(self, peer_state, shutdown_res, funded_chan, channel_id, COOP_CLOSED);
10556
+ let (_, err) = convert_channel_err!(self, peer_state, shutdown_res, funded_chan, COOP_CLOSED);
10559
10557
handle_errors.push((*cp_id, Err(err)));
10560
10558
10561
10559
log_info!(logger, "Broadcasting {}", log_tx!(tx));
@@ -10565,7 +10563,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10565
10563
},
10566
10564
Err(e) => {
10567
10565
has_update = true;
10568
- let (close_channel, res) = convert_channel_err!(self, peer_state, e, funded_chan, channel_id, FUNDED_CHANNEL);
10566
+ let (close_channel, res) = convert_channel_err!(self, peer_state, e, funded_chan, FUNDED_CHANNEL);
10569
10567
handle_errors.push((funded_chan.context.get_counterparty_node_id(), Err(res)));
10570
10568
!close_channel
10571
10569
}
@@ -11819,15 +11817,15 @@ where
11819
11817
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
11820
11818
let peer_state = &mut *peer_state_lock;
11821
11819
let pending_msg_events = &mut peer_state.pending_msg_events;
11822
- peer_state.channel_by_id.retain(|chan_id , chan| {
11820
+ peer_state.channel_by_id.retain(|_ , chan| {
11823
11821
let logger = WithChannelContext::from(&self.logger, &chan.context(), None);
11824
11822
if chan.peer_disconnected_is_resumable(&&logger) {
11825
11823
return true;
11826
11824
}
11827
11825
// Clean up for removal.
11828
11826
let reason = ClosureReason::DisconnectedPeer;
11829
11827
let err = ChannelError::Close((reason.to_string(), reason));
11830
- let (_, e) = convert_channel_err!(self, peer_state, err, chan, chan_id );
11828
+ let (_, e) = convert_channel_err!(self, peer_state, err, chan);
11831
11829
failed_channels.push((Err(e), counterparty_node_id));
11832
11830
false
11833
11831
});
@@ -12380,7 +12378,7 @@ where
12380
12378
let peer_state = &mut *peer_state_lock;
12381
12379
let pending_msg_events = &mut peer_state.pending_msg_events;
12382
12380
12383
- peer_state.channel_by_id.retain(|chan_id , chan| {
12381
+ peer_state.channel_by_id.retain(|channel_id , chan| {
12384
12382
match chan.as_funded_mut() {
12385
12383
// Retain unfunded channels.
12386
12384
None => true,
@@ -12391,22 +12389,22 @@ where
12391
12389
let reason = LocalHTLCFailureReason::CLTVExpiryTooSoon;
12392
12390
let data = self.get_htlc_inbound_temp_fail_data(reason);
12393
12391
timed_out_htlcs.push((source, payment_hash, HTLCFailReason::reason(reason, data),
12394
- HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: funded_channel.context. channel_id() }));
12392
+ HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: * channel_id }));
12395
12393
}
12396
12394
let logger = WithChannelContext::from(&self.logger, &funded_channel.context, None);
12397
12395
match funding_confirmed_opt {
12398
12396
Some(FundingConfirmedMessage::Establishment(channel_ready)) => {
12399
12397
send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
12400
12398
if funded_channel.context.is_usable() {
12401
- log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", funded_channel.context. channel_id() );
12399
+ log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", channel_id);
12402
12400
if let Ok(msg) = self.get_channel_update_for_unicast(funded_channel) {
12403
12401
pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
12404
12402
node_id: funded_channel.context.get_counterparty_node_id(),
12405
12403
msg,
12406
12404
});
12407
12405
}
12408
12406
} else {
12409
- log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", funded_channel.context. channel_id() );
12407
+ log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", channel_id);
12410
12408
}
12411
12409
},
12412
12410
#[cfg(splicing)]
@@ -12417,7 +12415,7 @@ where
12417
12415
12418
12416
let mut pending_events = self.pending_events.lock().unwrap();
12419
12417
pending_events.push_back((events::Event::ChannelReady {
12420
- channel_id: funded_channel.context.channel_id() ,
12418
+ channel_id,
12421
12419
user_channel_id: funded_channel.context.get_user_id(),
12422
12420
counterparty_node_id: funded_channel.context.get_counterparty_node_id(),
12423
12421
funding_txo: funding_txo.map(|outpoint| outpoint.into_bitcoin_outpoint()),
@@ -12489,8 +12487,8 @@ where
12489
12487
// un-confirmed we force-close the channel, ensuring short_to_chan_info
12490
12488
// is always consistent.
12491
12489
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
12492
- let scid_insert = short_to_chan_info.insert(real_scid, (funded_channel.context.get_counterparty_node_id(), funded_channel.context. channel_id() ));
12493
- assert!(scid_insert.is_none() || scid_insert.unwrap() == (funded_channel.context.get_counterparty_node_id(), funded_channel.context. channel_id() ),
12490
+ let scid_insert = short_to_chan_info.insert(real_scid, (funded_channel.context.get_counterparty_node_id(), * channel_id));
12491
+ assert!(scid_insert.is_none() || scid_insert.unwrap() == (funded_channel.context.get_counterparty_node_id(), * channel_id),
12494
12492
"SCIDs should never collide - ensure you weren't behind by a full {} blocks when creating channels",
12495
12493
fake_scid::MAX_SCID_BLOCKS_FROM_NOW);
12496
12494
}
@@ -12504,7 +12502,6 @@ where
12504
12502
peer_state,
12505
12503
err,
12506
12504
funded_channel,
12507
- chan_id,
12508
12505
FUNDED_CHANNEL
12509
12506
);
12510
12507
failed_channels.push((Err(e), *counterparty_node_id));
0 commit comments