@@ -3220,32 +3220,33 @@ macro_rules! locked_close_channel {
3220
3220
/// Returns (boolean indicating if we should remove the Channel object from memory, a mapped error)
3221
3221
#[rustfmt::skip]
3222
3222
macro_rules! convert_channel_err {
3223
- ($self: ident, $peer_state: expr, $err: expr, $chan: expr, $close: expr, $locked_close: expr, $channel_id: expr, _internal) => {
3223
+ ($self: ident, $peer_state: expr, $err: expr, $chan: expr, $close: expr, $locked_close: expr, $channel_id: expr, _internal) => { {
3224
3224
match $err {
3225
3225
ChannelError::Warn(msg) => {
3226
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), * $channel_id))
3226
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), $channel_id))
3227
3227
},
3228
3228
ChannelError::WarnAndDisconnect(msg) => {
3229
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::WarnAndDisconnect(msg), * $channel_id))
3229
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::WarnAndDisconnect(msg), $channel_id))
3230
3230
},
3231
3231
ChannelError::Ignore(msg) => {
3232
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), * $channel_id))
3232
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), $channel_id))
3233
3233
},
3234
3234
ChannelError::Close((msg, reason)) => {
3235
3235
let (mut shutdown_res, chan_update) = $close(reason);
3236
3236
let logger = WithChannelContext::from(&$self.logger, &$chan.context(), None);
3237
3237
log_error!(logger, "Closed channel {} due to close-required error: {}", $channel_id, msg);
3238
3238
$locked_close(&mut shutdown_res, $chan);
3239
3239
let err =
3240
- MsgHandleErrInternal::from_finish_shutdown(msg, * $channel_id, shutdown_res, chan_update);
3240
+ MsgHandleErrInternal::from_finish_shutdown(msg, $channel_id, shutdown_res, chan_update);
3241
3241
(true, err)
3242
3242
},
3243
3243
ChannelError::SendError(msg) => {
3244
- (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::SendError(msg), * $channel_id))
3244
+ (false, MsgHandleErrInternal::from_chan_no_close(ChannelError::SendError(msg), $channel_id))
3245
3245
},
3246
3246
}
3247
- };
3248
- ($self: ident, $peer_state: expr, $shutdown_result: expr, $funded_channel: expr, $channel_id: expr, COOP_CLOSED) => { {
3247
+ } };
3248
+ ($self: ident, $peer_state: expr, $shutdown_result: expr, $funded_channel: expr, COOP_CLOSED) => { {
3249
+ let chan_id = $funded_channel.context.channel_id();
3249
3250
let reason = ChannelError::Close(("Coop Closed".to_owned(), $shutdown_result.closure_reason.clone()));
3250
3251
let do_close = |_| {
3251
3252
(
@@ -3257,12 +3258,13 @@ macro_rules! convert_channel_err {
3257
3258
locked_close_channel!($self, $peer_state, funded_channel, shutdown_res_mut, FUNDED);
3258
3259
};
3259
3260
let (close, mut err) =
3260
- convert_channel_err!($self, $peer_state, reason, $funded_channel, do_close, locked_close, $channel_id , _internal);
3261
+ convert_channel_err!($self, $peer_state, reason, $funded_channel, do_close, locked_close, chan_id , _internal);
3261
3262
err.dont_send_error_message();
3262
3263
debug_assert!(close);
3263
3264
(close, err)
3264
3265
} };
3265
- ($self: ident, $peer_state: expr, $err: expr, $funded_channel: expr, $channel_id: expr, FUNDED_CHANNEL) => { {
3266
+ ($self: ident, $peer_state: expr, $err: expr, $funded_channel: expr, FUNDED_CHANNEL) => { {
3267
+ let chan_id = $funded_channel.context.channel_id();
3266
3268
let mut do_close = |reason| {
3267
3269
(
3268
3270
$funded_channel.force_shutdown(reason),
@@ -3272,20 +3274,21 @@ macro_rules! convert_channel_err {
3272
3274
let mut locked_close = |shutdown_res_mut: &mut ShutdownResult, funded_channel: &mut FundedChannel<_>| {
3273
3275
locked_close_channel!($self, $peer_state, funded_channel, shutdown_res_mut, FUNDED);
3274
3276
};
3275
- convert_channel_err!($self, $peer_state, $err, $funded_channel, do_close, locked_close, $channel_id , _internal)
3277
+ convert_channel_err!($self, $peer_state, $err, $funded_channel, do_close, locked_close, chan_id , _internal)
3276
3278
} };
3277
- ($self: ident, $peer_state: expr, $err: expr, $channel: expr, $channel_id: expr, UNFUNDED_CHANNEL) => { {
3279
+ ($self: ident, $peer_state: expr, $err: expr, $channel: expr, UNFUNDED_CHANNEL) => { {
3280
+ let chan_id = $channel.context().channel_id();
3278
3281
let mut do_close = |reason| { ($channel.force_shutdown(reason), None) };
3279
3282
let locked_close = |_, chan: &mut Channel<_>| { locked_close_channel!($self, chan.context(), UNFUNDED); };
3280
- convert_channel_err!($self, $peer_state, $err, $channel, do_close, locked_close, $channel_id , _internal)
3283
+ convert_channel_err!($self, $peer_state, $err, $channel, do_close, locked_close, chan_id , _internal)
3281
3284
} };
3282
- ($self: ident, $peer_state: expr, $err: expr, $channel: expr, $channel_id: expr ) => {
3285
+ ($self: ident, $peer_state: expr, $err: expr, $channel: expr) => {
3283
3286
match $channel.as_funded_mut() {
3284
3287
Some(funded_channel) => {
3285
- convert_channel_err!($self, $peer_state, $err, funded_channel, $channel_id, FUNDED_CHANNEL)
3288
+ convert_channel_err!($self, $peer_state, $err, funded_channel, FUNDED_CHANNEL)
3286
3289
},
3287
3290
None => {
3288
- convert_channel_err!($self, $peer_state, $err, $channel, $channel_id, UNFUNDED_CHANNEL)
3291
+ convert_channel_err!($self, $peer_state, $err, $channel, UNFUNDED_CHANNEL)
3289
3292
},
3290
3293
}
3291
3294
};
@@ -3296,9 +3299,7 @@ macro_rules! break_channel_entry {
3296
3299
match $res {
3297
3300
Ok(res) => res,
3298
3301
Err(e) => {
3299
- let key = *$entry.key();
3300
- let (drop, res) =
3301
- convert_channel_err!($self, $peer_state, e, $entry.get_mut(), &key);
3302
+ let (drop, res) = convert_channel_err!($self, $peer_state, e, $entry.get_mut());
3302
3303
if drop {
3303
3304
$entry.remove_entry();
3304
3305
}
@@ -3313,9 +3314,7 @@ macro_rules! try_channel_entry {
3313
3314
match $res {
3314
3315
Ok(res) => res,
3315
3316
Err(e) => {
3316
- let key = *$entry.key();
3317
- let (drop, res) =
3318
- convert_channel_err!($self, $peer_state, e, $entry.get_mut(), &key);
3317
+ let (drop, res) = convert_channel_err!($self, $peer_state, e, $entry.get_mut());
3319
3318
if drop {
3320
3319
$entry.remove_entry();
3321
3320
}
@@ -4157,7 +4156,7 @@ where
4157
4156
let reason = ClosureReason::LocallyCoopClosedUnfundedChannel;
4158
4157
let err = ChannelError::Close((reason.to_string(), reason));
4159
4158
let mut chan = chan_entry.remove();
4160
- let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan, chan_id );
4159
+ let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan);
4161
4160
e.dont_send_error_message();
4162
4161
shutdown_result = Err(e);
4163
4162
}
@@ -4354,7 +4353,7 @@ where
4354
4353
if let Some(mut chan) = peer_state.channel_by_id.remove(&channel_id) {
4355
4354
let reason = ClosureReason::FundingBatchClosure;
4356
4355
let err = ChannelError::Close((reason.to_string(), reason));
4357
- let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan, &channel_id );
4356
+ let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan);
4358
4357
shutdown_results.push((Err(e), counterparty_node_id));
4359
4358
}
4360
4359
}
@@ -4418,7 +4417,7 @@ where
4418
4417
if let Some(mut chan) = peer_state.channel_by_id.remove(channel_id) {
4419
4418
log_error!(logger, "Force-closing channel {}", channel_id);
4420
4419
let err = ChannelError::Close((message, reason));
4421
- let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan, channel_id );
4420
+ let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan);
4422
4421
mem::drop(peer_state_lock);
4423
4422
mem::drop(per_peer_state);
4424
4423
if is_from_counterparty {
@@ -5897,7 +5896,7 @@ where
5897
5896
let reason = ClosureReason::ProcessingError { err: e.clone() };
5898
5897
let err = ChannelError::Close((e.clone(), reason));
5899
5898
let (_, e) =
5900
- convert_channel_err!(self, peer_state, err, &mut chan, &channel_id );
5899
+ convert_channel_err!(self, peer_state, err, &mut chan);
5901
5900
shutdown_results.push((Err(e), counterparty_node_id));
5902
5901
});
5903
5902
}
@@ -7302,7 +7301,7 @@ where
7302
7301
if chan_needs_persist == NotifyOption::DoPersist { should_persist = NotifyOption::DoPersist; }
7303
7302
7304
7303
if let Err(e) = funded_chan.timer_check_closing_negotiation_progress() {
7305
- let (needs_close, err) = convert_channel_err!(self, peer_state, e, funded_chan, chan_id, FUNDED_CHANNEL);
7304
+ let (needs_close, err) = convert_channel_err!(self, peer_state, e, funded_chan, FUNDED_CHANNEL);
7306
7305
handle_errors.push((Err(err), counterparty_node_id));
7307
7306
if needs_close { return false; }
7308
7307
}
@@ -7380,7 +7379,7 @@ where
7380
7379
let reason = ClosureReason::FundingTimedOut;
7381
7380
let msg = "Force-closing pending channel due to timeout awaiting establishment handshake".to_owned();
7382
7381
let err = ChannelError::Close((msg, reason));
7383
- let (_, e) = convert_channel_err!(self, peer_state, err, chan, chan_id );
7382
+ let (_, e) = convert_channel_err!(self, peer_state, err, chan);
7384
7383
handle_errors.push((Err(e), counterparty_node_id));
7385
7384
false
7386
7385
} else {
@@ -9140,18 +9139,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9140
9139
// above so at this point we just need to clean up any lingering entries
9141
9140
// concerning this channel as it is safe to do so.
9142
9141
debug_assert!(matches!(err, ChannelError::Close(_)));
9143
- // Really we should be returning the channel_id the peer expects based
9144
- // on their funding info here, but they're horribly confused anyway, so
9145
- // there's not a lot we can do to save them.
9146
9142
let mut chan = Channel::from(inbound_chan);
9147
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &msg.temporary_channel_id, UNFUNDED_CHANNEL ).1);
9143
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan).1);
9148
9144
},
9149
9145
}
9150
9146
},
9151
9147
Some(Err(mut chan)) => {
9152
9148
let err_msg = format!("Got an unexpected funding_created message from peer with counterparty_node_id {}", counterparty_node_id);
9153
9149
let err = ChannelError::close(err_msg);
9154
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &msg.temporary_channel_id ).1);
9150
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan).1);
9155
9151
},
9156
9152
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))
9157
9153
};
@@ -9167,7 +9163,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9167
9163
let err = ChannelError::close($err.to_owned());
9168
9164
chan.unset_funding_info();
9169
9165
let mut chan = Channel::from(chan);
9170
- return Err(convert_channel_err!(self, peer_state, err, &mut chan, &funded_channel_id, UNFUNDED_CHANNEL).1);
9166
+ return Err(convert_channel_err!(self, peer_state, err, &mut chan, UNFUNDED_CHANNEL).1);
9171
9167
} } }
9172
9168
9173
9169
match peer_state.channel_by_id.entry(funded_channel_id) {
@@ -9707,8 +9703,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9707
9703
let reason = ClosureReason::CounterpartyCoopClosedUnfundedChannel;
9708
9704
let err = ChannelError::Close((reason.to_string(), reason));
9709
9705
let mut chan = chan_entry.remove();
9710
- let (_, mut e) =
9711
- convert_channel_err!(self, peer_state, err, &mut chan, &msg.channel_id);
9706
+ let (_, mut e) = convert_channel_err!(self, peer_state, err, &mut chan);
9712
9707
e.dont_send_error_message();
9713
9708
return Err(e);
9714
9709
},
@@ -9767,7 +9762,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9767
9762
// also implies there are no pending HTLCs left on the channel, so we can
9768
9763
// fully delete it from tracking (the channel monitor is still around to
9769
9764
// watch for old state broadcasts)!
9770
- let (_, err) = convert_channel_err!(self, peer_state, close_res, chan, &msg.channel_id, COOP_CLOSED);
9765
+ let (_, err) = convert_channel_err!(self, peer_state, close_res, chan, COOP_CLOSED);
9771
9766
chan_entry.remove();
9772
9767
Some((tx, Err(err)))
9773
9768
} else {
@@ -10848,13 +10843,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10848
10843
};
10849
10844
let err = ChannelError::Close((reason.to_string(), reason));
10850
10845
let mut chan = chan_entry.remove();
10851
- let (_, e) = convert_channel_err!(
10852
- self,
10853
- peer_state,
10854
- err,
10855
- &mut chan,
10856
- &channel_id
10857
- );
10846
+ let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan);
10858
10847
failed_channels.push((Err(e), counterparty_node_id));
10859
10848
}
10860
10849
}
@@ -11059,12 +11048,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
11059
11048
let chan_id = context.channel_id();
11060
11049
log_trace!(logger, "Removing channel {} now that the signer is unblocked", chan_id);
11061
11050
let (remove, err) = if let Some(funded_channel) = chan.as_funded_mut() {
11062
- convert_channel_err!(self, peer_state, shutdown_res, funded_channel, &chan_id, COOP_CLOSED)
11051
+ convert_channel_err!(self, peer_state, shutdown_res, funded_channel, COOP_CLOSED)
11063
11052
} else {
11064
11053
debug_assert!(false);
11065
11054
let reason = shutdown_res.closure_reason.clone();
11066
11055
let err = ChannelError::Close((reason.to_string(), reason));
11067
- convert_channel_err!(self, peer_state, err, chan, &chan_id, UNFUNDED_CHANNEL)
11056
+ convert_channel_err!(self, peer_state, err, chan, UNFUNDED_CHANNEL)
11068
11057
};
11069
11058
debug_assert!(remove);
11070
11059
shutdown_results.push((Err(err), *cp_id));
@@ -11094,7 +11083,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
11094
11083
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
11095
11084
let peer_state = &mut *peer_state_lock;
11096
11085
let pending_msg_events = &mut peer_state.pending_msg_events;
11097
- peer_state.channel_by_id.retain(|channel_id , chan| {
11086
+ peer_state.channel_by_id.retain(|_ , chan| {
11098
11087
match chan.as_funded_mut() {
11099
11088
Some(funded_chan) => {
11100
11089
let logger = WithChannelContext::from(&self.logger, &funded_chan.context, None);
@@ -11110,7 +11099,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
11110
11099
if let Some((tx, shutdown_res)) = tx_shutdown_result_opt {
11111
11100
// We're done with this channel. We got a closing_signed and sent back
11112
11101
// a closing_signed with a closing transaction to broadcast.
11113
- let (_, err) = convert_channel_err!(self, peer_state, shutdown_res, funded_chan, channel_id, COOP_CLOSED);
11102
+ let (_, err) = convert_channel_err!(self, peer_state, shutdown_res, funded_chan, COOP_CLOSED);
11114
11103
handle_errors.push((*cp_id, Err(err)));
11115
11104
11116
11105
log_info!(logger, "Broadcasting {}", log_tx!(tx));
@@ -11120,7 +11109,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
11120
11109
},
11121
11110
Err(e) => {
11122
11111
has_update = true;
11123
- let (close_channel, res) = convert_channel_err!(self, peer_state, e, funded_chan, channel_id, FUNDED_CHANNEL);
11112
+ let (close_channel, res) = convert_channel_err!(self, peer_state, e, funded_chan, FUNDED_CHANNEL);
11124
11113
handle_errors.push((funded_chan.context.get_counterparty_node_id(), Err(res)));
11125
11114
!close_channel
11126
11115
}
@@ -12374,15 +12363,15 @@ where
12374
12363
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
12375
12364
let peer_state = &mut *peer_state_lock;
12376
12365
let pending_msg_events = &mut peer_state.pending_msg_events;
12377
- peer_state.channel_by_id.retain(|chan_id , chan| {
12366
+ peer_state.channel_by_id.retain(|_ , chan| {
12378
12367
let logger = WithChannelContext::from(&self.logger, &chan.context(), None);
12379
12368
if chan.peer_disconnected_is_resumable(&&logger) {
12380
12369
return true;
12381
12370
}
12382
12371
// Clean up for removal.
12383
12372
let reason = ClosureReason::DisconnectedPeer;
12384
12373
let err = ChannelError::Close((reason.to_string(), reason));
12385
- let (_, e) = convert_channel_err!(self, peer_state, err, chan, chan_id );
12374
+ let (_, e) = convert_channel_err!(self, peer_state, err, chan);
12386
12375
failed_channels.push((Err(e), counterparty_node_id));
12387
12376
false
12388
12377
});
@@ -12935,7 +12924,7 @@ where
12935
12924
let peer_state = &mut *peer_state_lock;
12936
12925
let pending_msg_events = &mut peer_state.pending_msg_events;
12937
12926
12938
- peer_state.channel_by_id.retain(|chan_id , chan| {
12927
+ peer_state.channel_by_id.retain(|channel_id , chan| {
12939
12928
match chan.as_funded_mut() {
12940
12929
// Retain unfunded channels.
12941
12930
None => true,
@@ -12946,22 +12935,22 @@ where
12946
12935
let reason = LocalHTLCFailureReason::CLTVExpiryTooSoon;
12947
12936
let data = self.get_htlc_inbound_temp_fail_data(reason);
12948
12937
timed_out_htlcs.push((source, payment_hash, HTLCFailReason::reason(reason, data),
12949
- HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: funded_channel.context. channel_id() }));
12938
+ HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: * channel_id }));
12950
12939
}
12951
12940
let logger = WithChannelContext::from(&self.logger, &funded_channel.context, None);
12952
12941
match funding_confirmed_opt {
12953
12942
Some(FundingConfirmedMessage::Establishment(channel_ready)) => {
12954
12943
send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
12955
12944
if funded_channel.context.is_usable() {
12956
- log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", funded_channel.context. channel_id() );
12945
+ log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", channel_id);
12957
12946
if let Ok(msg) = self.get_channel_update_for_unicast(funded_channel) {
12958
12947
pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
12959
12948
node_id: funded_channel.context.get_counterparty_node_id(),
12960
12949
msg,
12961
12950
});
12962
12951
}
12963
12952
} else {
12964
- log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", funded_channel.context. channel_id() );
12953
+ log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", channel_id);
12965
12954
}
12966
12955
},
12967
12956
#[cfg(splicing)]
@@ -12972,7 +12961,7 @@ where
12972
12961
12973
12962
let mut pending_events = self.pending_events.lock().unwrap();
12974
12963
pending_events.push_back((events::Event::ChannelReady {
12975
- channel_id: funded_channel.context. channel_id() ,
12964
+ channel_id: * channel_id,
12976
12965
user_channel_id: funded_channel.context.get_user_id(),
12977
12966
counterparty_node_id: funded_channel.context.get_counterparty_node_id(),
12978
12967
funding_txo: funding_txo.map(|outpoint| outpoint.into_bitcoin_outpoint()),
@@ -13044,8 +13033,8 @@ where
13044
13033
// un-confirmed we force-close the channel, ensuring short_to_chan_info
13045
13034
// is always consistent.
13046
13035
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
13047
- let scid_insert = short_to_chan_info.insert(real_scid, (funded_channel.context.get_counterparty_node_id(), funded_channel.context. channel_id() ));
13048
- assert!(scid_insert.is_none() || scid_insert.unwrap() == (funded_channel.context.get_counterparty_node_id(), funded_channel.context. channel_id() ),
13036
+ let scid_insert = short_to_chan_info.insert(real_scid, (funded_channel.context.get_counterparty_node_id(), * channel_id));
13037
+ assert!(scid_insert.is_none() || scid_insert.unwrap() == (funded_channel.context.get_counterparty_node_id(), * channel_id),
13049
13038
"SCIDs should never collide - ensure you weren't behind by a full {} blocks when creating channels",
13050
13039
fake_scid::MAX_SCID_BLOCKS_FROM_NOW);
13051
13040
}
@@ -13059,7 +13048,6 @@ where
13059
13048
peer_state,
13060
13049
err,
13061
13050
funded_channel,
13062
- chan_id,
13063
13051
FUNDED_CHANNEL
13064
13052
);
13065
13053
failed_channels.push((Err(e), *counterparty_node_id));
0 commit comments