@@ -3215,32 +3215,33 @@ macro_rules! locked_close_channel {
3215
3215
/// Returns (boolean indicating if we should remove the Channel object from memory, a mapped error)
3216
3216
#[rustfmt::skip]
3217
3217
macro_rules! convert_channel_err {
3218
- ($self: ident, $peer_state: expr, $err: expr, $chan: expr, $close: expr, $locked_close: expr, $channel_id: expr, _internal) => {
3218
+ ($self: ident, $peer_state: expr, $err: expr, $chan: expr, $close: expr, $locked_close: expr, $channel_id: expr, _internal) => { {
3219
3219
match $err {
3220
3220
ChannelError::Warn(msg) => {
3221
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), * $channel_id))
3221
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), $channel_id))
3222
3222
},
3223
3223
ChannelError::WarnAndDisconnect(msg) => {
3224
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::WarnAndDisconnect(msg), * $channel_id))
3224
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::WarnAndDisconnect(msg), $channel_id))
3225
3225
},
3226
3226
ChannelError::Ignore(msg) => {
3227
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), * $channel_id))
3227
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), $channel_id))
3228
3228
},
3229
3229
ChannelError::Close((msg, reason)) => {
3230
3230
let (mut shutdown_res, chan_update) = $close(reason);
3231
3231
let logger = WithChannelContext::from(&$self.logger, &$chan.context(), None);
3232
3232
log_error!(logger, "Closed channel {} due to close-required error: {}", $channel_id, msg);
3233
3233
$locked_close(&mut shutdown_res, $chan);
3234
3234
let err =
3235
- MsgHandleErrInternal::from_finish_shutdown(msg, * $channel_id, shutdown_res, chan_update);
3235
+ MsgHandleErrInternal::from_finish_shutdown(msg, $channel_id, shutdown_res, chan_update);
3236
3236
(true, err)
3237
3237
},
3238
3238
ChannelError::SendError(msg) => {
3239
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::SendError(msg), * $channel_id))
3239
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::SendError(msg), $channel_id))
3240
3240
},
3241
3241
}
3242
- };
3243
- ($self: ident, $peer_state: expr, $shutdown_result: expr, $funded_channel: expr, $channel_id: expr, COOP_CLOSED) => { {
3242
+ } };
3243
+ ($self: ident, $peer_state: expr, $shutdown_result: expr, $funded_channel: expr, COOP_CLOSED) => { {
3244
+ let chan_id = $funded_channel.context.channel_id();
3244
3245
let reason = ChannelError::Close(("Coop Closed".to_owned(), $shutdown_result.closure_reason.clone()));
3245
3246
let do_close = |_| {
3246
3247
(
@@ -3252,12 +3253,13 @@ macro_rules! convert_channel_err {
3252
3253
locked_close_channel!($self, $peer_state, funded_channel, shutdown_res_mut, FUNDED);
3253
3254
};
3254
3255
let (close, mut err) =
3255
- convert_channel_err!($self, $peer_state, reason, $funded_channel, do_close, locked_close, $channel_id , _internal);
3256
+ convert_channel_err!($self, $peer_state, reason, $funded_channel, do_close, locked_close, chan_id , _internal);
3256
3257
err.dont_send_error_message();
3257
3258
debug_assert!(close);
3258
3259
(close, err)
3259
3260
} };
3260
- ($self: ident, $peer_state: expr, $err: expr, $funded_channel: expr, $channel_id: expr, FUNDED_CHANNEL) => { {
3261
+ ($self: ident, $peer_state: expr, $err: expr, $funded_channel: expr, FUNDED_CHANNEL) => { {
3262
+ let chan_id = $funded_channel.context.channel_id();
3261
3263
let mut do_close = |reason| {
3262
3264
(
3263
3265
$funded_channel.force_shutdown(reason),
@@ -3267,20 +3269,21 @@ macro_rules! convert_channel_err {
3267
3269
let mut locked_close = |shutdown_res_mut: &mut ShutdownResult, funded_channel: &mut FundedChannel<_>| {
3268
3270
locked_close_channel!($self, $peer_state, funded_channel, shutdown_res_mut, FUNDED);
3269
3271
};
3270
- convert_channel_err!($self, $peer_state, $err, $funded_channel, do_close, locked_close, $channel_id , _internal)
3272
+ convert_channel_err!($self, $peer_state, $err, $funded_channel, do_close, locked_close, chan_id , _internal)
3271
3273
} };
3272
- ($self: ident, $peer_state: expr, $err: expr, $channel: expr, $channel_id: expr, UNFUNDED_CHANNEL) => { {
3274
+ ($self: ident, $peer_state: expr, $err: expr, $channel: expr, UNFUNDED_CHANNEL) => { {
3275
+ let chan_id = $channel.context().channel_id();
3273
3276
let mut do_close = |reason| { ($channel.force_shutdown(reason), None) };
3274
3277
let locked_close = |_, chan: &mut Channel<_>| { locked_close_channel!($self, chan.context(), UNFUNDED); };
3275
- convert_channel_err!($self, $peer_state, $err, $channel, do_close, locked_close, $channel_id , _internal)
3278
+ convert_channel_err!($self, $peer_state, $err, $channel, do_close, locked_close, chan_id , _internal)
3276
3279
} };
3277
- ($self: ident, $peer_state: expr, $err: expr, $channel: expr, $channel_id: expr ) => {
3280
+ ($self: ident, $peer_state: expr, $err: expr, $channel: expr) => {
3278
3281
match $channel.as_funded_mut() {
3279
3282
Some(funded_channel) => {
3280
- convert_channel_err!($self, $peer_state, $err, funded_channel, $channel_id, FUNDED_CHANNEL)
3283
+ convert_channel_err!($self, $peer_state, $err, funded_channel, FUNDED_CHANNEL)
3281
3284
},
3282
3285
None => {
3283
- convert_channel_err!($self, $peer_state, $err, $channel, $channel_id, UNFUNDED_CHANNEL)
3286
+ convert_channel_err!($self, $peer_state, $err, $channel, UNFUNDED_CHANNEL)
3284
3287
},
3285
3288
}
3286
3289
};
@@ -3291,9 +3294,8 @@ macro_rules! break_channel_entry {
3291
3294
match $res {
3292
3295
Ok(res) => res,
3293
3296
Err(e) => {
3294
- let key = *$entry.key();
3295
3297
let (drop, res) =
3296
- convert_channel_err!($self, $peer_state, e, $entry.get_mut(), &key );
3298
+ convert_channel_err!($self, $peer_state, e, $entry.get_mut());
3297
3299
if drop {
3298
3300
$entry.remove_entry();
3299
3301
}
@@ -3308,9 +3310,8 @@ macro_rules! try_channel_entry {
3308
3310
match $res {
3309
3311
Ok(res) => res,
3310
3312
Err(e) => {
3311
- let key = *$entry.key();
3312
3313
let (drop, res) =
3313
- convert_channel_err!($self, $peer_state, e, $entry.get_mut(), &key );
3314
+ convert_channel_err!($self, $peer_state, e, $entry.get_mut());
3314
3315
if drop {
3315
3316
$entry.remove_entry();
3316
3317
}
@@ -4152,7 +4153,7 @@ where
4152
4153
let reason = ClosureReason::LocallyCoopClosedUnfundedChannel;
4153
4154
let err = ChannelError::Close((reason.to_string(), reason));
4154
4155
let mut chan = chan_entry.remove();
4155
- 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);
4156
4157
e.dont_send_error_message();
4157
4158
shutdown_result = Err(e);
4158
4159
}
@@ -4346,7 +4347,7 @@ where
4346
4347
if let Some(mut chan) = peer_state.channel_by_id.remove(&channel_id) {
4347
4348
let reason = ClosureReason::FundingBatchClosure;
4348
4349
let err = ChannelError::Close((reason.to_string(), reason));
4349
- let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan, &channel_id );
4350
+ let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan);
4350
4351
shutdown_results.push((Err(e), counterparty_node_id));
4351
4352
}
4352
4353
}
@@ -4410,7 +4411,7 @@ where
4410
4411
if let Some(mut chan) = peer_state.channel_by_id.remove(channel_id) {
4411
4412
log_error!(logger, "Force-closing channel {}", channel_id);
4412
4413
let err = ChannelError::Close((message, reason));
4413
- let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan, channel_id );
4414
+ let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan);
4414
4415
mem::drop(peer_state_lock);
4415
4416
mem::drop(per_peer_state);
4416
4417
if is_from_counterparty {
@@ -5845,7 +5846,7 @@ where
5845
5846
let reason = ClosureReason::ProcessingError { err: e.clone() };
5846
5847
let err = ChannelError::Close((e.clone(), reason));
5847
5848
let (_, e) =
5848
- convert_channel_err!(self, peer_state, err, &mut chan, &channel_id );
5849
+ convert_channel_err!(self, peer_state, err, &mut chan);
5849
5850
shutdown_results.push((Err(e), counterparty_node_id));
5850
5851
});
5851
5852
}
@@ -7011,7 +7012,7 @@ where
7011
7012
if chan_needs_persist == NotifyOption::DoPersist { should_persist = NotifyOption::DoPersist; }
7012
7013
7013
7014
if let Err(e) = funded_chan.timer_check_closing_negotiation_progress() {
7014
- let (needs_close, err) = convert_channel_err!(self, peer_state, e, funded_chan, chan_id, FUNDED_CHANNEL);
7015
+ let (needs_close, err) = convert_channel_err!(self, peer_state, e, funded_chan, FUNDED_CHANNEL);
7015
7016
handle_errors.push((Err(err), counterparty_node_id));
7016
7017
if needs_close { return false; }
7017
7018
}
@@ -7089,7 +7090,7 @@ where
7089
7090
let reason = ClosureReason::FundingTimedOut;
7090
7091
let msg = "Force-closing pending channel due to timeout awaiting establishment handshake".to_owned();
7091
7092
let err = ChannelError::Close((msg, reason));
7092
- let (_, e) = convert_channel_err!(self, peer_state, err, chan, chan_id );
7093
+ let (_, e) = convert_channel_err!(self, peer_state, err, chan);
7093
7094
handle_errors.push((Err(e), counterparty_node_id));
7094
7095
false
7095
7096
} else {
@@ -8668,18 +8669,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8668
8669
// above so at this point we just need to clean up any lingering entries
8669
8670
// concerning this channel as it is safe to do so.
8670
8671
debug_assert!(matches!(err, ChannelError::Close(_)));
8671
- // Really we should be returning the channel_id the peer expects based
8672
- // on their funding info here, but they're horribly confused anyway, so
8673
- // there's not a lot we can do to save them.
8674
8672
let mut chan = Channel::from(inbound_chan);
8675
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &msg.temporary_channel_id, UNFUNDED_CHANNEL ).1);
8673
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan).1);
8676
8674
},
8677
8675
}
8678
8676
},
8679
8677
Some(Err(mut chan)) => {
8680
8678
let err_msg = format!("Got an unexpected funding_created message from peer with counterparty_node_id {}", counterparty_node_id);
8681
8679
let err = ChannelError::close(err_msg);
8682
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &msg.temporary_channel_id ).1);
8680
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan).1);
8683
8681
},
8684
8682
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))
8685
8683
};
@@ -8695,7 +8693,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8695
8693
let err = ChannelError::close($err.to_owned());
8696
8694
chan.unset_funding_info();
8697
8695
let mut chan = Channel::from(chan);
8698
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &funded_channel_id, UNFUNDED_CHANNEL).1);
8696
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan, UNFUNDED_CHANNEL).1);
8699
8697
} } }
8700
8698
8701
8699
match peer_state.channel_by_id.entry(funded_channel_id) {
@@ -9236,7 +9234,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9236
9234
let err = ChannelError::Close((reason.to_string(), reason));
9237
9235
let mut chan = chan_entry.remove();
9238
9236
let (_, mut e) =
9239
- convert_channel_err!(self, peer_state, err, &mut chan, &msg.channel_id );
9237
+ convert_channel_err!(self, peer_state, err, &mut chan);
9240
9238
e.dont_send_error_message();
9241
9239
return Err(e);
9242
9240
},
@@ -9295,7 +9293,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9295
9293
// also implies there are no pending HTLCs left on the channel, so we can
9296
9294
// fully delete it from tracking (the channel monitor is still around to
9297
9295
// watch for old state broadcasts)!
9298
- let (_, err) = convert_channel_err!(self, peer_state, close_res, chan, &msg.channel_id, COOP_CLOSED);
9296
+ let (_, err) = convert_channel_err!(self, peer_state, close_res, chan, COOP_CLOSED);
9299
9297
chan_entry.remove();
9300
9298
Some((tx, Err(err)))
9301
9299
} else {
@@ -10258,7 +10256,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10258
10256
};
10259
10257
let err = ChannelError::Close((reason.to_string(), reason));
10260
10258
let mut chan = chan_entry.remove();
10261
- let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan, &channel_id );
10259
+ let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan);
10262
10260
failed_channels.push((Err(e), counterparty_node_id));
10263
10261
}
10264
10262
}
@@ -10446,12 +10444,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10446
10444
let chan_id = context.channel_id();
10447
10445
log_trace!(logger, "Removing channel {} now that the signer is unblocked", chan_id);
10448
10446
let (remove, err) = if let Some(funded_channel) = chan.as_funded_mut() {
10449
- convert_channel_err!(self, peer_state, shutdown_res, funded_channel, &chan_id, COOP_CLOSED)
10447
+ convert_channel_err!(self, peer_state, shutdown_res, funded_channel, COOP_CLOSED)
10450
10448
} else {
10451
10449
debug_assert!(false);
10452
10450
let reason = shutdown_res.closure_reason.clone();
10453
10451
let err = ChannelError::Close((reason.to_string(), reason));
10454
- convert_channel_err!(self, peer_state, err, chan, &chan_id, UNFUNDED_CHANNEL)
10452
+ convert_channel_err!(self, peer_state, err, chan, UNFUNDED_CHANNEL)
10455
10453
};
10456
10454
debug_assert!(remove);
10457
10455
shutdown_results.push((Err(err), *cp_id));
@@ -10481,7 +10479,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10481
10479
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
10482
10480
let peer_state = &mut *peer_state_lock;
10483
10481
let pending_msg_events = &mut peer_state.pending_msg_events;
10484
- peer_state.channel_by_id.retain(|channel_id , chan| {
10482
+ peer_state.channel_by_id.retain(|_ , chan| {
10485
10483
match chan.as_funded_mut() {
10486
10484
Some(funded_chan) => {
10487
10485
let logger = WithChannelContext::from(&self.logger, &funded_chan.context, None);
@@ -10497,7 +10495,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10497
10495
if let Some((tx, shutdown_res)) = tx_shutdown_result_opt {
10498
10496
// We're done with this channel. We got a closing_signed and sent back
10499
10497
// a closing_signed with a closing transaction to broadcast.
10500
- let (_, err) = convert_channel_err!(self, peer_state, shutdown_res, funded_chan, channel_id, COOP_CLOSED);
10498
+ let (_, err) = convert_channel_err!(self, peer_state, shutdown_res, funded_chan, COOP_CLOSED);
10501
10499
handle_errors.push((*cp_id, Err(err)));
10502
10500
10503
10501
log_info!(logger, "Broadcasting {}", log_tx!(tx));
@@ -10507,7 +10505,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10507
10505
},
10508
10506
Err(e) => {
10509
10507
has_update = true;
10510
- let (close_channel, res) = convert_channel_err!(self, peer_state, e, funded_chan, channel_id, FUNDED_CHANNEL);
10508
+ let (close_channel, res) = convert_channel_err!(self, peer_state, e, funded_chan, FUNDED_CHANNEL);
10511
10509
handle_errors.push((funded_chan.context.get_counterparty_node_id(), Err(res)));
10512
10510
!close_channel
10513
10511
}
@@ -11692,15 +11690,15 @@ where
11692
11690
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
11693
11691
let peer_state = &mut *peer_state_lock;
11694
11692
let pending_msg_events = &mut peer_state.pending_msg_events;
11695
- peer_state.channel_by_id.retain(|chan_id , chan| {
11693
+ peer_state.channel_by_id.retain(|_ , chan| {
11696
11694
let logger = WithChannelContext::from(&self.logger, &chan.context(), None);
11697
11695
if chan.peer_disconnected_is_resumable(&&logger) {
11698
11696
return true;
11699
11697
}
11700
11698
// Clean up for removal.
11701
11699
let reason = ClosureReason::DisconnectedPeer;
11702
11700
let err = ChannelError::Close((reason.to_string(), reason));
11703
- let (_, e) = convert_channel_err!(self, peer_state, err, chan, chan_id );
11701
+ let (_, e) = convert_channel_err!(self, peer_state, err, chan);
11704
11702
failed_channels.push((Err(e), counterparty_node_id));
11705
11703
false
11706
11704
});
@@ -12246,7 +12244,7 @@ where
12246
12244
let peer_state = &mut *peer_state_lock;
12247
12245
let pending_msg_events = &mut peer_state.pending_msg_events;
12248
12246
12249
- peer_state.channel_by_id.retain(|chan_id , chan| {
12247
+ peer_state.channel_by_id.retain(|channel_id , chan| {
12250
12248
match chan.as_funded_mut() {
12251
12249
// Retain unfunded channels.
12252
12250
None => true,
@@ -12257,22 +12255,22 @@ where
12257
12255
let reason = LocalHTLCFailureReason::CLTVExpiryTooSoon;
12258
12256
let data = self.get_htlc_inbound_temp_fail_data(reason);
12259
12257
timed_out_htlcs.push((source, payment_hash, HTLCFailReason::reason(reason, data),
12260
- HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: funded_channel.context. channel_id() }));
12258
+ HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: * channel_id }));
12261
12259
}
12262
12260
let logger = WithChannelContext::from(&self.logger, &funded_channel.context, None);
12263
12261
match funding_confirmed_opt {
12264
12262
Some(FundingConfirmedMessage::Establishment(channel_ready)) => {
12265
12263
send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
12266
12264
if funded_channel.context.is_usable() {
12267
- log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", funded_channel.context. channel_id() );
12265
+ log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", channel_id);
12268
12266
if let Ok(msg) = self.get_channel_update_for_unicast(funded_channel) {
12269
12267
pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
12270
12268
node_id: funded_channel.context.get_counterparty_node_id(),
12271
12269
msg,
12272
12270
});
12273
12271
}
12274
12272
} else {
12275
- log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", funded_channel.context. channel_id() );
12273
+ log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", channel_id);
12276
12274
}
12277
12275
},
12278
12276
#[cfg(splicing)]
@@ -12283,7 +12281,7 @@ where
12283
12281
12284
12282
let mut pending_events = self.pending_events.lock().unwrap();
12285
12283
pending_events.push_back((events::Event::ChannelReady {
12286
- channel_id: funded_channel.context.channel_id() ,
12284
+ channel_id,
12287
12285
user_channel_id: funded_channel.context.get_user_id(),
12288
12286
counterparty_node_id: funded_channel.context.get_counterparty_node_id(),
12289
12287
funding_txo: funding_txo.map(|outpoint| outpoint.into_bitcoin_outpoint()),
@@ -12355,8 +12353,8 @@ where
12355
12353
// un-confirmed we force-close the channel, ensuring short_to_chan_info
12356
12354
// is always consistent.
12357
12355
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
12358
- let scid_insert = short_to_chan_info.insert(real_scid, (funded_channel.context.get_counterparty_node_id(), funded_channel.context. channel_id() ));
12359
- assert!(scid_insert.is_none() || scid_insert.unwrap() == (funded_channel.context.get_counterparty_node_id(), funded_channel.context. channel_id() ),
12356
+ let scid_insert = short_to_chan_info.insert(real_scid, (funded_channel.context.get_counterparty_node_id(), * channel_id));
12357
+ assert!(scid_insert.is_none() || scid_insert.unwrap() == (funded_channel.context.get_counterparty_node_id(), * channel_id),
12360
12358
"SCIDs should never collide - ensure you weren't behind by a full {} blocks when creating channels",
12361
12359
fake_scid::MAX_SCID_BLOCKS_FROM_NOW);
12362
12360
}
@@ -12370,7 +12368,6 @@ where
12370
12368
peer_state,
12371
12369
err,
12372
12370
funded_channel,
12373
- chan_id,
12374
12371
FUNDED_CHANNEL
12375
12372
);
12376
12373
failed_channels.push((Err(e), *counterparty_node_id));
0 commit comments