@@ -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,7 @@ macro_rules! break_channel_entry {
3293
3296
match $res {
3294
3297
Ok(res) => res,
3295
3298
Err(e) => {
3296
- let key = *$entry.key();
3297
- let (drop, res) =
3298
- convert_channel_err!($self, $peer_state, e, $entry.get_mut(), &key);
3299
+ let (drop, res) = convert_channel_err!($self, $peer_state, e, $entry.get_mut());
3299
3300
if drop {
3300
3301
$entry.remove_entry();
3301
3302
}
@@ -3310,9 +3311,7 @@ macro_rules! try_channel_entry {
3310
3311
match $res {
3311
3312
Ok(res) => res,
3312
3313
Err(e) => {
3313
- let key = *$entry.key();
3314
- let (drop, res) =
3315
- convert_channel_err!($self, $peer_state, e, $entry.get_mut(), &key);
3314
+ let (drop, res) = convert_channel_err!($self, $peer_state, e, $entry.get_mut());
3316
3315
if drop {
3317
3316
$entry.remove_entry();
3318
3317
}
@@ -4154,7 +4153,7 @@ where
4154
4153
let reason = ClosureReason::LocallyCoopClosedUnfundedChannel;
4155
4154
let err = ChannelError::Close((reason.to_string(), reason));
4156
4155
let mut chan = chan_entry.remove();
4157
- let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan, chan_id );
4156
+ let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan);
4158
4157
e.dont_send_error_message();
4159
4158
shutdown_result = Err(e);
4160
4159
}
@@ -4351,7 +4350,7 @@ where
4351
4350
if let Some(mut chan) = peer_state.channel_by_id.remove(&channel_id) {
4352
4351
let reason = ClosureReason::FundingBatchClosure;
4353
4352
let err = ChannelError::Close((reason.to_string(), reason));
4354
- let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan, &channel_id );
4353
+ let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan);
4355
4354
shutdown_results.push((Err(e), counterparty_node_id));
4356
4355
}
4357
4356
}
@@ -4415,7 +4414,7 @@ where
4415
4414
if let Some(mut chan) = peer_state.channel_by_id.remove(channel_id) {
4416
4415
log_error!(logger, "Force-closing channel {}", channel_id);
4417
4416
let err = ChannelError::Close((message, reason));
4418
- let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan, channel_id );
4417
+ let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan);
4419
4418
mem::drop(peer_state_lock);
4420
4419
mem::drop(per_peer_state);
4421
4420
if is_from_counterparty {
@@ -5894,7 +5893,7 @@ where
5894
5893
let reason = ClosureReason::ProcessingError { err: e.clone() };
5895
5894
let err = ChannelError::Close((e.clone(), reason));
5896
5895
let (_, e) =
5897
- convert_channel_err!(self, peer_state, err, &mut chan, &channel_id );
5896
+ convert_channel_err!(self, peer_state, err, &mut chan);
5898
5897
shutdown_results.push((Err(e), counterparty_node_id));
5899
5898
});
5900
5899
}
@@ -7062,7 +7061,7 @@ where
7062
7061
if chan_needs_persist == NotifyOption::DoPersist { should_persist = NotifyOption::DoPersist; }
7063
7062
7064
7063
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);
7064
+ let (needs_close, err) = convert_channel_err!(self, peer_state, e, funded_chan, FUNDED_CHANNEL);
7066
7065
handle_errors.push((Err(err), counterparty_node_id));
7067
7066
if needs_close { return false; }
7068
7067
}
@@ -7140,7 +7139,7 @@ where
7140
7139
let reason = ClosureReason::FundingTimedOut;
7141
7140
let msg = "Force-closing pending channel due to timeout awaiting establishment handshake".to_owned();
7142
7141
let err = ChannelError::Close((msg, reason));
7143
- let (_, e) = convert_channel_err!(self, peer_state, err, chan, chan_id );
7142
+ let (_, e) = convert_channel_err!(self, peer_state, err, chan);
7144
7143
handle_errors.push((Err(e), counterparty_node_id));
7145
7144
false
7146
7145
} else {
@@ -8726,18 +8725,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8726
8725
// above so at this point we just need to clean up any lingering entries
8727
8726
// concerning this channel as it is safe to do so.
8728
8727
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
8728
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);
8729
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan).1);
8734
8730
},
8735
8731
}
8736
8732
},
8737
8733
Some(Err(mut chan)) => {
8738
8734
let err_msg = format!("Got an unexpected funding_created message from peer with counterparty_node_id {}", counterparty_node_id);
8739
8735
let err = ChannelError::close(err_msg);
8740
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &msg.temporary_channel_id ).1);
8736
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan).1);
8741
8737
},
8742
8738
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
8739
};
@@ -8753,7 +8749,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8753
8749
let err = ChannelError::close($err.to_owned());
8754
8750
chan.unset_funding_info();
8755
8751
let mut chan = Channel::from(chan);
8756
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &funded_channel_id, UNFUNDED_CHANNEL).1);
8752
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan, UNFUNDED_CHANNEL).1);
8757
8753
} } }
8758
8754
8759
8755
match peer_state.channel_by_id.entry(funded_channel_id) {
@@ -9293,8 +9289,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9293
9289
let reason = ClosureReason::CounterpartyCoopClosedUnfundedChannel;
9294
9290
let err = ChannelError::Close((reason.to_string(), reason));
9295
9291
let mut chan = chan_entry.remove();
9296
- let (_, mut e) =
9297
- convert_channel_err!(self, peer_state, err, &mut chan, &msg.channel_id);
9292
+ let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan);
9298
9293
e.dont_send_error_message();
9299
9294
return Err(e);
9300
9295
},
@@ -9353,7 +9348,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9353
9348
// also implies there are no pending HTLCs left on the channel, so we can
9354
9349
// fully delete it from tracking (the channel monitor is still around to
9355
9350
// watch for old state broadcasts)!
9356
- let (_, err) = convert_channel_err!(self, peer_state, close_res, chan, &msg.channel_id, COOP_CLOSED);
9351
+ let (_, err) = convert_channel_err!(self, peer_state, close_res, chan, COOP_CLOSED);
9357
9352
chan_entry.remove();
9358
9353
Some((tx, Err(err)))
9359
9354
} else {
@@ -10312,7 +10307,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10312
10307
};
10313
10308
let err = ChannelError::Close((reason.to_string(), reason));
10314
10309
let mut chan = chan_entry.remove();
10315
- let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan, &channel_id );
10310
+ let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan);
10316
10311
failed_channels.push((Err(e), counterparty_node_id));
10317
10312
}
10318
10313
}
@@ -10500,12 +10495,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10500
10495
let chan_id = context.channel_id();
10501
10496
log_trace!(logger, "Removing channel {} now that the signer is unblocked", chan_id);
10502
10497
let (remove, err) = if let Some(funded_channel) = chan.as_funded_mut() {
10503
- convert_channel_err!(self, peer_state, shutdown_res, funded_channel, &chan_id, COOP_CLOSED)
10498
+ convert_channel_err!(self, peer_state, shutdown_res, funded_channel, COOP_CLOSED)
10504
10499
} else {
10505
10500
debug_assert!(false);
10506
10501
let reason = shutdown_res.closure_reason.clone();
10507
10502
let err = ChannelError::Close((reason.to_string(), reason));
10508
- convert_channel_err!(self, peer_state, err, chan, &chan_id, UNFUNDED_CHANNEL)
10503
+ convert_channel_err!(self, peer_state, err, chan, UNFUNDED_CHANNEL)
10509
10504
};
10510
10505
debug_assert!(remove);
10511
10506
shutdown_results.push((Err(err), *cp_id));
@@ -10535,7 +10530,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10535
10530
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
10536
10531
let peer_state = &mut *peer_state_lock;
10537
10532
let pending_msg_events = &mut peer_state.pending_msg_events;
10538
- peer_state.channel_by_id.retain(|channel_id , chan| {
10533
+ peer_state.channel_by_id.retain(|_ , chan| {
10539
10534
match chan.as_funded_mut() {
10540
10535
Some(funded_chan) => {
10541
10536
let logger = WithChannelContext::from(&self.logger, &funded_chan.context, None);
@@ -10551,7 +10546,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10551
10546
if let Some((tx, shutdown_res)) = tx_shutdown_result_opt {
10552
10547
// We're done with this channel. We got a closing_signed and sent back
10553
10548
// a closing_signed with a closing transaction to broadcast.
10554
- let (_, err) = convert_channel_err!(self, peer_state, shutdown_res, funded_chan, channel_id, COOP_CLOSED);
10549
+ let (_, err) = convert_channel_err!(self, peer_state, shutdown_res, funded_chan, COOP_CLOSED);
10555
10550
handle_errors.push((*cp_id, Err(err)));
10556
10551
10557
10552
log_info!(logger, "Broadcasting {}", log_tx!(tx));
@@ -10561,7 +10556,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10561
10556
},
10562
10557
Err(e) => {
10563
10558
has_update = true;
10564
- let (close_channel, res) = convert_channel_err!(self, peer_state, e, funded_chan, channel_id, FUNDED_CHANNEL);
10559
+ let (close_channel, res) = convert_channel_err!(self, peer_state, e, funded_chan, FUNDED_CHANNEL);
10565
10560
handle_errors.push((funded_chan.context.get_counterparty_node_id(), Err(res)));
10566
10561
!close_channel
10567
10562
}
@@ -11815,15 +11810,15 @@ where
11815
11810
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
11816
11811
let peer_state = &mut *peer_state_lock;
11817
11812
let pending_msg_events = &mut peer_state.pending_msg_events;
11818
- peer_state.channel_by_id.retain(|chan_id , chan| {
11813
+ peer_state.channel_by_id.retain(|_ , chan| {
11819
11814
let logger = WithChannelContext::from(&self.logger, &chan.context(), None);
11820
11815
if chan.peer_disconnected_is_resumable(&&logger) {
11821
11816
return true;
11822
11817
}
11823
11818
// Clean up for removal.
11824
11819
let reason = ClosureReason::DisconnectedPeer;
11825
11820
let err = ChannelError::Close((reason.to_string(), reason));
11826
- let (_, e) = convert_channel_err!(self, peer_state, err, chan, chan_id );
11821
+ let (_, e) = convert_channel_err!(self, peer_state, err, chan);
11827
11822
failed_channels.push((Err(e), counterparty_node_id));
11828
11823
false
11829
11824
});
@@ -12376,7 +12371,7 @@ where
12376
12371
let peer_state = &mut *peer_state_lock;
12377
12372
let pending_msg_events = &mut peer_state.pending_msg_events;
12378
12373
12379
- peer_state.channel_by_id.retain(|chan_id , chan| {
12374
+ peer_state.channel_by_id.retain(|channel_id , chan| {
12380
12375
match chan.as_funded_mut() {
12381
12376
// Retain unfunded channels.
12382
12377
None => true,
@@ -12387,22 +12382,22 @@ where
12387
12382
let reason = LocalHTLCFailureReason::CLTVExpiryTooSoon;
12388
12383
let data = self.get_htlc_inbound_temp_fail_data(reason);
12389
12384
timed_out_htlcs.push((source, payment_hash, HTLCFailReason::reason(reason, data),
12390
- HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: funded_channel.context. channel_id() }));
12385
+ HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: * channel_id }));
12391
12386
}
12392
12387
let logger = WithChannelContext::from(&self.logger, &funded_channel.context, None);
12393
12388
match funding_confirmed_opt {
12394
12389
Some(FundingConfirmedMessage::Establishment(channel_ready)) => {
12395
12390
send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
12396
12391
if funded_channel.context.is_usable() {
12397
- log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", funded_channel.context. channel_id() );
12392
+ log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", channel_id);
12398
12393
if let Ok(msg) = self.get_channel_update_for_unicast(funded_channel) {
12399
12394
pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
12400
12395
node_id: funded_channel.context.get_counterparty_node_id(),
12401
12396
msg,
12402
12397
});
12403
12398
}
12404
12399
} else {
12405
- log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", funded_channel.context. channel_id() );
12400
+ log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", channel_id);
12406
12401
}
12407
12402
},
12408
12403
#[cfg(splicing)]
@@ -12413,7 +12408,7 @@ where
12413
12408
12414
12409
let mut pending_events = self.pending_events.lock().unwrap();
12415
12410
pending_events.push_back((events::Event::ChannelReady {
12416
- channel_id: funded_channel.context.channel_id() ,
12411
+ channel_id,
12417
12412
user_channel_id: funded_channel.context.get_user_id(),
12418
12413
counterparty_node_id: funded_channel.context.get_counterparty_node_id(),
12419
12414
funding_txo: funding_txo.map(|outpoint| outpoint.into_bitcoin_outpoint()),
@@ -12485,8 +12480,8 @@ where
12485
12480
// un-confirmed we force-close the channel, ensuring short_to_chan_info
12486
12481
// is always consistent.
12487
12482
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
12488
- let scid_insert = short_to_chan_info.insert(real_scid, (funded_channel.context.get_counterparty_node_id(), funded_channel.context. channel_id() ));
12489
- assert!(scid_insert.is_none() || scid_insert.unwrap() == (funded_channel.context.get_counterparty_node_id(), funded_channel.context. channel_id() ),
12483
+ let scid_insert = short_to_chan_info.insert(real_scid, (funded_channel.context.get_counterparty_node_id(), * channel_id));
12484
+ assert!(scid_insert.is_none() || scid_insert.unwrap() == (funded_channel.context.get_counterparty_node_id(), * channel_id),
12490
12485
"SCIDs should never collide - ensure you weren't behind by a full {} blocks when creating channels",
12491
12486
fake_scid::MAX_SCID_BLOCKS_FROM_NOW);
12492
12487
}
@@ -12500,7 +12495,6 @@ where
12500
12495
peer_state,
12501
12496
err,
12502
12497
funded_channel,
12503
- chan_id,
12504
12498
FUNDED_CHANNEL
12505
12499
);
12506
12500
failed_channels.push((Err(e), *counterparty_node_id));
0 commit comments