@@ -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
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,13 +11048,14 @@ 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) = chan.as_funded_mut() {
11062
- let err = convert_channel_err!(self, peer_state, shutdown, funded, &chan_id, COOP_CLOSED);
11051
+ let err =
11052
+ convert_channel_err!(self, peer_state, shutdown, funded, COOP_CLOSED);
11063
11053
(true, err)
11064
11054
} else {
11065
11055
debug_assert!(false);
11066
11056
let reason = shutdown.closure_reason.clone();
11067
11057
let err = ChannelError::Close((reason.to_string(), reason));
11068
- convert_channel_err!(self, peer_state, err, chan, &chan_id, UNFUNDED_CHANNEL)
11058
+ convert_channel_err!(self, peer_state, err, chan, UNFUNDED_CHANNEL)
11069
11059
};
11070
11060
debug_assert!(remove);
11071
11061
shutdown_results.push((Err(err), *cp_id));
@@ -11095,7 +11085,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
11095
11085
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
11096
11086
let peer_state = &mut *peer_state_lock;
11097
11087
let pending_msg_events = &mut peer_state.pending_msg_events;
11098
- peer_state.channel_by_id.retain(|channel_id , chan| {
11088
+ peer_state.channel_by_id.retain(|_ , chan| {
11099
11089
match chan.as_funded_mut() {
11100
11090
Some(funded_chan) => {
11101
11091
let logger = WithChannelContext::from(&self.logger, &funded_chan.context, None);
@@ -11111,7 +11101,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
11111
11101
if let Some((tx, shutdown_res)) = tx_shutdown_result_opt {
11112
11102
// We're done with this channel. We got a closing_signed and sent back
11113
11103
// a closing_signed with a closing transaction to broadcast.
11114
- let err = convert_channel_err!(self, peer_state, shutdown_res, funded_chan, channel_id, COOP_CLOSED);
11104
+ let err = convert_channel_err!(self, peer_state, shutdown_res, funded_chan, COOP_CLOSED);
11115
11105
handle_errors.push((*cp_id, Err(err)));
11116
11106
11117
11107
log_info!(logger, "Broadcasting {}", log_tx!(tx));
@@ -11121,7 +11111,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
11121
11111
},
11122
11112
Err(e) => {
11123
11113
has_update = true;
11124
- let (close_channel, res) = convert_channel_err!(self, peer_state, e, funded_chan, channel_id, FUNDED_CHANNEL);
11114
+ let (close_channel, res) = convert_channel_err!(self, peer_state, e, funded_chan, FUNDED_CHANNEL);
11125
11115
handle_errors.push((funded_chan.context.get_counterparty_node_id(), Err(res)));
11126
11116
!close_channel
11127
11117
}
@@ -12375,15 +12365,15 @@ where
12375
12365
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
12376
12366
let peer_state = &mut *peer_state_lock;
12377
12367
let pending_msg_events = &mut peer_state.pending_msg_events;
12378
- peer_state.channel_by_id.retain(|chan_id , chan| {
12368
+ peer_state.channel_by_id.retain(|_ , chan| {
12379
12369
let logger = WithChannelContext::from(&self.logger, &chan.context(), None);
12380
12370
if chan.peer_disconnected_is_resumable(&&logger) {
12381
12371
return true;
12382
12372
}
12383
12373
// Clean up for removal.
12384
12374
let reason = ClosureReason::DisconnectedPeer;
12385
12375
let err = ChannelError::Close((reason.to_string(), reason));
12386
- let (_, e) = convert_channel_err!(self, peer_state, err, chan, chan_id );
12376
+ let (_, e) = convert_channel_err!(self, peer_state, err, chan);
12387
12377
failed_channels.push((Err(e), counterparty_node_id));
12388
12378
false
12389
12379
});
@@ -12936,7 +12926,7 @@ where
12936
12926
let peer_state = &mut *peer_state_lock;
12937
12927
let pending_msg_events = &mut peer_state.pending_msg_events;
12938
12928
12939
- peer_state.channel_by_id.retain(|chan_id , chan| {
12929
+ peer_state.channel_by_id.retain(|channel_id , chan| {
12940
12930
match chan.as_funded_mut() {
12941
12931
// Retain unfunded channels.
12942
12932
None => true,
@@ -12947,22 +12937,22 @@ where
12947
12937
let reason = LocalHTLCFailureReason::CLTVExpiryTooSoon;
12948
12938
let data = self.get_htlc_inbound_temp_fail_data(reason);
12949
12939
timed_out_htlcs.push((source, payment_hash, HTLCFailReason::reason(reason, data),
12950
- HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: funded_channel.context. channel_id() }));
12940
+ HTLCHandlingFailureType::Forward { node_id: Some(funded_channel.context.get_counterparty_node_id()), channel_id: * channel_id }));
12951
12941
}
12952
12942
let logger = WithChannelContext::from(&self.logger, &funded_channel.context, None);
12953
12943
match funding_confirmed_opt {
12954
12944
Some(FundingConfirmedMessage::Establishment(channel_ready)) => {
12955
12945
send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
12956
12946
if funded_channel.context.is_usable() {
12957
- log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", funded_channel.context. channel_id() );
12947
+ log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", channel_id);
12958
12948
if let Ok(msg) = self.get_channel_update_for_unicast(funded_channel) {
12959
12949
pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
12960
12950
node_id: funded_channel.context.get_counterparty_node_id(),
12961
12951
msg,
12962
12952
});
12963
12953
}
12964
12954
} else {
12965
- log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", funded_channel.context. channel_id() );
12955
+ log_trace!(logger, "Sending channel_ready WITHOUT channel_update for {}", channel_id);
12966
12956
}
12967
12957
},
12968
12958
#[cfg(splicing)]
@@ -12973,7 +12963,7 @@ where
12973
12963
12974
12964
let mut pending_events = self.pending_events.lock().unwrap();
12975
12965
pending_events.push_back((events::Event::ChannelReady {
12976
- channel_id: funded_channel.context. channel_id() ,
12966
+ channel_id: * channel_id,
12977
12967
user_channel_id: funded_channel.context.get_user_id(),
12978
12968
counterparty_node_id: funded_channel.context.get_counterparty_node_id(),
12979
12969
funding_txo: funding_txo.map(|outpoint| outpoint.into_bitcoin_outpoint()),
@@ -13045,8 +13035,8 @@ where
13045
13035
// un-confirmed we force-close the channel, ensuring short_to_chan_info
13046
13036
// is always consistent.
13047
13037
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
13048
- let scid_insert = short_to_chan_info.insert(real_scid, (funded_channel.context.get_counterparty_node_id(), funded_channel.context. channel_id() ));
13049
- assert!(scid_insert.is_none() || scid_insert.unwrap() == (funded_channel.context.get_counterparty_node_id(), funded_channel.context. channel_id() ),
13038
+ let scid_insert = short_to_chan_info.insert(real_scid, (funded_channel.context.get_counterparty_node_id(), * channel_id));
13039
+ assert!(scid_insert.is_none() || scid_insert.unwrap() == (funded_channel.context.get_counterparty_node_id(), * channel_id),
13050
13040
"SCIDs should never collide - ensure you weren't behind by a full {} blocks when creating channels",
13051
13041
fake_scid::MAX_SCID_BLOCKS_FROM_NOW);
13052
13042
}
@@ -13060,7 +13050,6 @@ where
13060
13050
peer_state,
13061
13051
err,
13062
13052
funded_channel,
13063
- chan_id,
13064
13053
FUNDED_CHANNEL
13065
13054
);
13066
13055
failed_channels.push((Err(e), *counterparty_node_id));
0 commit comments