@@ -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
}
@@ -4348,7 +4349,7 @@ where
4348
4349
if let Some(mut chan) = peer_state.channel_by_id.remove(&channel_id) {
4349
4350
let reason = ClosureReason::FundingBatchClosure;
4350
4351
let err = ChannelError::Close((reason.to_string(), reason));
4351
- let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan, &channel_id );
4352
+ let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan);
4352
4353
shutdown_results.push((Err(e), counterparty_node_id));
4353
4354
}
4354
4355
}
@@ -4412,7 +4413,7 @@ where
4412
4413
if let Some(mut chan) = peer_state.channel_by_id.remove(channel_id) {
4413
4414
log_error!(logger, "Force-closing channel {}", channel_id);
4414
4415
let err = ChannelError::Close((message, reason));
4415
- let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan, channel_id );
4416
+ let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan);
4416
4417
mem::drop(peer_state_lock);
4417
4418
mem::drop(per_peer_state);
4418
4419
if is_from_counterparty {
@@ -5871,7 +5872,7 @@ where
5871
5872
let reason = ClosureReason::ProcessingError { err: e.clone() };
5872
5873
let err = ChannelError::Close((e.clone(), reason));
5873
5874
let (_, e) =
5874
- convert_channel_err!(self, peer_state, err, &mut chan, &channel_id );
5875
+ convert_channel_err!(self, peer_state, err, &mut chan);
5875
5876
shutdown_results.push((Err(e), counterparty_node_id));
5876
5877
});
5877
5878
}
@@ -7037,7 +7038,7 @@ where
7037
7038
if chan_needs_persist == NotifyOption::DoPersist { should_persist = NotifyOption::DoPersist; }
7038
7039
7039
7040
if let Err(e) = funded_chan.timer_check_closing_negotiation_progress() {
7040
- let (needs_close, err) = convert_channel_err!(self, peer_state, e, funded_chan, chan_id, FUNDED_CHANNEL);
7041
+ let (needs_close, err) = convert_channel_err!(self, peer_state, e, funded_chan, FUNDED_CHANNEL);
7041
7042
handle_errors.push((Err(err), counterparty_node_id));
7042
7043
if needs_close { return false; }
7043
7044
}
@@ -7115,7 +7116,7 @@ where
7115
7116
let reason = ClosureReason::FundingTimedOut;
7116
7117
let msg = "Force-closing pending channel due to timeout awaiting establishment handshake".to_owned();
7117
7118
let err = ChannelError::Close((msg, reason));
7118
- let (_, e) = convert_channel_err!(self, peer_state, err, chan, chan_id );
7119
+ let (_, e) = convert_channel_err!(self, peer_state, err, chan);
7119
7120
handle_errors.push((Err(e), counterparty_node_id));
7120
7121
false
7121
7122
} else {
@@ -8697,18 +8698,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8697
8698
// above so at this point we just need to clean up any lingering entries
8698
8699
// concerning this channel as it is safe to do so.
8699
8700
debug_assert!(matches!(err, ChannelError::Close(_)));
8700
- // Really we should be returning the channel_id the peer expects based
8701
- // on their funding info here, but they're horribly confused anyway, so
8702
- // there's not a lot we can do to save them.
8703
8701
let mut chan = Channel::from(inbound_chan);
8704
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &msg.temporary_channel_id, UNFUNDED_CHANNEL ).1);
8702
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan).1);
8705
8703
},
8706
8704
}
8707
8705
},
8708
8706
Some(Err(mut chan)) => {
8709
8707
let err_msg = format!("Got an unexpected funding_created message from peer with counterparty_node_id {}", counterparty_node_id);
8710
8708
let err = ChannelError::close(err_msg);
8711
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &msg.temporary_channel_id ).1);
8709
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan).1);
8712
8710
},
8713
8711
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))
8714
8712
};
@@ -8724,7 +8722,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8724
8722
let err = ChannelError::close($err.to_owned());
8725
8723
chan.unset_funding_info();
8726
8724
let mut chan = Channel::from(chan);
8727
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &funded_channel_id, UNFUNDED_CHANNEL).1);
8725
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan, UNFUNDED_CHANNEL).1);
8728
8726
} } }
8729
8727
8730
8728
match peer_state.channel_by_id.entry(funded_channel_id) {
@@ -9265,7 +9263,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9265
9263
let err = ChannelError::Close((reason.to_string(), reason));
9266
9264
let mut chan = chan_entry.remove();
9267
9265
let (_, mut e) =
9268
- convert_channel_err!(self, peer_state, err, &mut chan, &msg.channel_id );
9266
+ convert_channel_err!(self, peer_state, err, &mut chan);
9269
9267
e.dont_send_error_message();
9270
9268
return Err(e);
9271
9269
},
@@ -9324,7 +9322,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9324
9322
// also implies there are no pending HTLCs left on the channel, so we can
9325
9323
// fully delete it from tracking (the channel monitor is still around to
9326
9324
// watch for old state broadcasts)!
9327
- let (_, err) = convert_channel_err!(self, peer_state, close_res, chan, &msg.channel_id, COOP_CLOSED);
9325
+ let (_, err) = convert_channel_err!(self, peer_state, close_res, chan, COOP_CLOSED);
9328
9326
chan_entry.remove();
9329
9327
Some((tx, Err(err)))
9330
9328
} else {
@@ -10287,7 +10285,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10287
10285
};
10288
10286
let err = ChannelError::Close((reason.to_string(), reason));
10289
10287
let mut chan = chan_entry.remove();
10290
- let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan, &channel_id );
10288
+ let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan);
10291
10289
failed_channels.push((Err(e), counterparty_node_id));
10292
10290
}
10293
10291
}
@@ -10475,12 +10473,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10475
10473
let chan_id = context.channel_id();
10476
10474
log_trace!(logger, "Removing channel {} now that the signer is unblocked", chan_id);
10477
10475
let (remove, err) = if let Some(funded_channel) = chan.as_funded_mut() {
10478
- convert_channel_err!(self, peer_state, shutdown_res, funded_channel, &chan_id, COOP_CLOSED)
10476
+ convert_channel_err!(self, peer_state, shutdown_res, funded_channel, COOP_CLOSED)
10479
10477
} else {
10480
10478
debug_assert!(false);
10481
10479
let reason = shutdown_res.closure_reason.clone();
10482
10480
let err = ChannelError::Close((reason.to_string(), reason));
10483
- convert_channel_err!(self, peer_state, err, chan, &chan_id, UNFUNDED_CHANNEL)
10481
+ convert_channel_err!(self, peer_state, err, chan, UNFUNDED_CHANNEL)
10484
10482
};
10485
10483
debug_assert!(remove);
10486
10484
shutdown_results.push((Err(err), *cp_id));
@@ -10510,7 +10508,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10510
10508
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
10511
10509
let peer_state = &mut *peer_state_lock;
10512
10510
let pending_msg_events = &mut peer_state.pending_msg_events;
10513
- peer_state.channel_by_id.retain(|channel_id , chan| {
10511
+ peer_state.channel_by_id.retain(|_ , chan| {
10514
10512
match chan.as_funded_mut() {
10515
10513
Some(funded_chan) => {
10516
10514
let logger = WithChannelContext::from(&self.logger, &funded_chan.context, None);
@@ -10526,7 +10524,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10526
10524
if let Some((tx, shutdown_res)) = tx_shutdown_result_opt {
10527
10525
// We're done with this channel. We got a closing_signed and sent back
10528
10526
// a closing_signed with a closing transaction to broadcast.
10529
- let (_, err) = convert_channel_err!(self, peer_state, shutdown_res, funded_chan, channel_id, COOP_CLOSED);
10527
+ let (_, err) = convert_channel_err!(self, peer_state, shutdown_res, funded_chan, COOP_CLOSED);
10530
10528
handle_errors.push((*cp_id, Err(err)));
10531
10529
10532
10530
log_info!(logger, "Broadcasting {}", log_tx!(tx));
@@ -10536,7 +10534,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10536
10534
},
10537
10535
Err(e) => {
10538
10536
has_update = true;
10539
- let (close_channel, res) = convert_channel_err!(self, peer_state, e, funded_chan, channel_id, FUNDED_CHANNEL);
10537
+ let (close_channel, res) = convert_channel_err!(self, peer_state, e, funded_chan, FUNDED_CHANNEL);
10540
10538
handle_errors.push((funded_chan.context.get_counterparty_node_id(), Err(res)));
10541
10539
!close_channel
10542
10540
}
@@ -11761,15 +11759,15 @@ where
11761
11759
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
11762
11760
let peer_state = &mut *peer_state_lock;
11763
11761
let pending_msg_events = &mut peer_state.pending_msg_events;
11764
- peer_state.channel_by_id.retain(|chan_id , chan| {
11762
+ peer_state.channel_by_id.retain(|_ , chan| {
11765
11763
let logger = WithChannelContext::from(&self.logger, &chan.context(), None);
11766
11764
if chan.peer_disconnected_is_resumable(&&logger) {
11767
11765
return true;
11768
11766
}
11769
11767
// Clean up for removal.
11770
11768
let reason = ClosureReason::DisconnectedPeer;
11771
11769
let err = ChannelError::Close((reason.to_string(), reason));
11772
- let (_, e) = convert_channel_err!(self, peer_state, err, chan, chan_id );
11770
+ let (_, e) = convert_channel_err!(self, peer_state, err, chan);
11773
11771
failed_channels.push((Err(e), counterparty_node_id));
11774
11772
false
11775
11773
});
@@ -12322,7 +12320,7 @@ where
12322
12320
let peer_state = &mut *peer_state_lock;
12323
12321
let pending_msg_events = &mut peer_state.pending_msg_events;
12324
12322
12325
- peer_state.channel_by_id.retain(|chan_id , chan| {
12323
+ peer_state.channel_by_id.retain(|channel_id , chan| {
12326
12324
match chan.as_funded_mut() {
12327
12325
// Retain unfunded channels.
12328
12326
None => true,
@@ -12333,22 +12331,22 @@ where
12333
12331
let reason = LocalHTLCFailureReason::CLTVExpiryTooSoon;
12334
12332
let data = self.get_htlc_inbound_temp_fail_data(reason);
12335
12333
timed_out_htlcs.push((source, payment_hash, HTLCFailReason::reason(reason, data),
12336
- HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: funded_channel.context. channel_id() }));
12334
+ HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: * channel_id }));
12337
12335
}
12338
12336
let logger = WithChannelContext::from(&self.logger, &funded_channel.context, None);
12339
12337
match funding_confirmed_opt {
12340
12338
Some(FundingConfirmedMessage::Establishment(channel_ready)) => {
12341
12339
send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
12342
12340
if funded_channel.context.is_usable() {
12343
- log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", funded_channel.context. channel_id() );
12341
+ log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", channel_id);
12344
12342
if let Ok(msg) = self.get_channel_update_for_unicast(funded_channel) {
12345
12343
pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
12346
12344
node_id: funded_channel.context.get_counterparty_node_id(),
12347
12345
msg,
12348
12346
});
12349
12347
}
12350
12348
} else {
12351
- log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", funded_channel.context. channel_id() );
12349
+ log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", channel_id);
12352
12350
}
12353
12351
},
12354
12352
#[cfg(splicing)]
@@ -12359,7 +12357,7 @@ where
12359
12357
12360
12358
let mut pending_events = self.pending_events.lock().unwrap();
12361
12359
pending_events.push_back((events::Event::ChannelReady {
12362
- channel_id: funded_channel.context.channel_id() ,
12360
+ channel_id,
12363
12361
user_channel_id: funded_channel.context.get_user_id(),
12364
12362
counterparty_node_id: funded_channel.context.get_counterparty_node_id(),
12365
12363
funding_txo: funding_txo.map(|outpoint| outpoint.into_bitcoin_outpoint()),
@@ -12431,8 +12429,8 @@ where
12431
12429
// un-confirmed we force-close the channel, ensuring short_to_chan_info
12432
12430
// is always consistent.
12433
12431
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
12434
- let scid_insert = short_to_chan_info.insert(real_scid, (funded_channel.context.get_counterparty_node_id(), funded_channel.context. channel_id() ));
12435
- assert!(scid_insert.is_none() || scid_insert.unwrap() == (funded_channel.context.get_counterparty_node_id(), funded_channel.context. channel_id() ),
12432
+ let scid_insert = short_to_chan_info.insert(real_scid, (funded_channel.context.get_counterparty_node_id(), * channel_id));
12433
+ assert!(scid_insert.is_none() || scid_insert.unwrap() == (funded_channel.context.get_counterparty_node_id(), * channel_id),
12436
12434
"SCIDs should never collide - ensure you weren't behind by a full {} blocks when creating channels",
12437
12435
fake_scid::MAX_SCID_BLOCKS_FROM_NOW);
12438
12436
}
@@ -12446,7 +12444,6 @@ where
12446
12444
peer_state,
12447
12445
err,
12448
12446
funded_channel,
12449
- chan_id,
12450
12447
FUNDED_CHANNEL
12451
12448
);
12452
12449
failed_channels.push((Err(e), *counterparty_node_id));
0 commit comments