@@ -1370,8 +1370,7 @@ impl <SP: Deref> PeerState<SP> where SP::Target: SignerProvider {
1370
1370
match phase {
1371
1371
ChannelPhase::Funded(_) | ChannelPhase::UnfundedOutboundV1(_) => true,
1372
1372
ChannelPhase::UnfundedInboundV1(_) => false,
1373
- ChannelPhase::UnfundedOutboundV2(_) => true,
1374
- ChannelPhase::UnfundedInboundV2(_) => false,
1373
+ ChannelPhase::UnfundedV2(chan) => chan.context.is_outbound(),
1375
1374
}
1376
1375
)
1377
1376
&& self.monitor_update_blocked_actions.is_empty()
@@ -3048,10 +3047,7 @@ macro_rules! convert_chan_phase_err {
3048
3047
ChannelPhase::UnfundedInboundV1(channel) => {
3049
3048
convert_chan_phase_err!($self, $peer_state, $err, channel, $channel_id, UNFUNDED_CHANNEL)
3050
3049
},
3051
- ChannelPhase::UnfundedOutboundV2(channel) => {
3052
- convert_chan_phase_err!($self, $peer_state, $err, channel, $channel_id, UNFUNDED_CHANNEL)
3053
- },
3054
- ChannelPhase::UnfundedInboundV2(channel) => {
3050
+ ChannelPhase::UnfundedV2(channel) => {
3055
3051
convert_chan_phase_err!($self, $peer_state, $err, channel, $channel_id, UNFUNDED_CHANNEL)
3056
3052
},
3057
3053
}
@@ -4114,7 +4110,7 @@ where
4114
4110
)
4115
4111
},
4116
4112
ChannelPhase::UnfundedOutboundV1(_) | ChannelPhase::UnfundedInboundV1(_) |
4117
- ChannelPhase::UnfundedOutboundV2(_) | ChannelPhase::UnfundedInboundV2 (_) => {
4113
+ ChannelPhase::UnfundedV2 (_) => {
4118
4114
// Unfunded channel has no update
4119
4115
(chan_phase_entry.get_mut().context_mut().force_shutdown(false, closure_reason), None)
4120
4116
},
@@ -6540,10 +6536,7 @@ where
6540
6536
ChannelPhase::UnfundedOutboundV1(chan) => {
6541
6537
process_unfunded_channel_tick!(peer_state, chan, pending_msg_events)
6542
6538
},
6543
- ChannelPhase::UnfundedInboundV2(chan) => {
6544
- process_unfunded_channel_tick!(peer_state, chan, pending_msg_events)
6545
- },
6546
- ChannelPhase::UnfundedOutboundV2(chan) => {
6539
+ ChannelPhase::UnfundedV2(chan) => {
6547
6540
process_unfunded_channel_tick!(peer_state, chan, pending_msg_events)
6548
6541
},
6549
6542
}
@@ -7721,7 +7714,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
7721
7714
node_id: channel.context.get_counterparty_node_id(),
7722
7715
msg: channel.accept_inbound_dual_funded_channel()
7723
7716
};
7724
- (channel.context.channel_id(), ChannelPhase::UnfundedInboundV2 (channel), Some(message_send_event))
7717
+ (channel.context.channel_id(), ChannelPhase::UnfundedV2 (channel), Some(message_send_event))
7725
7718
})
7726
7719
},
7727
7720
}
@@ -7840,15 +7833,20 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
7840
7833
num_unfunded_channels += 1;
7841
7834
}
7842
7835
},
7843
- ChannelPhase::UnfundedInboundV2(chan) => {
7836
+ ChannelPhase::UnfundedV2(chan) => {
7837
+ // Outbound channels don't contribute to the unfunded count in the DoS context.
7838
+ if chan.context.is_outbound() {
7839
+ continue;
7840
+ }
7841
+
7844
7842
// Only inbound V2 channels that are not 0conf and that we do not contribute to will be
7845
7843
// included in the unfunded count.
7846
7844
if chan.context.minimum_depth().unwrap_or(1) != 0 &&
7847
7845
chan.dual_funding_context.our_funding_satoshis == 0 {
7848
7846
num_unfunded_channels += 1;
7849
7847
}
7850
7848
},
7851
- ChannelPhase::UnfundedOutboundV1(_) | ChannelPhase::UnfundedOutboundV2(_) => {
7849
+ ChannelPhase::UnfundedOutboundV1(_) => {
7852
7850
// Outbound channels don't contribute to the unfunded count in the DoS context.
7853
7851
continue;
7854
7852
},
@@ -7996,7 +7994,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
7996
7994
node_id: *counterparty_node_id,
7997
7995
msg: channel.accept_inbound_dual_funded_channel(),
7998
7996
};
7999
- (ChannelPhase::UnfundedInboundV2 (channel), Some(message_send_event))
7997
+ (ChannelPhase::UnfundedV2 (channel), Some(message_send_event))
8000
7998
},
8001
7999
};
8002
8000
@@ -8243,10 +8241,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8243
8241
fn internal_tx_add_input(&self, counterparty_node_id: PublicKey, msg: &msgs::TxAddInput) -> Result<(), MsgHandleErrInternal> {
8244
8242
self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel_phase: &mut ChannelPhase<SP>| {
8245
8243
match channel_phase {
8246
- ChannelPhase::UnfundedInboundV2(ref mut channel) => {
8247
- Ok(channel.tx_add_input(msg).into_msg_send_event(counterparty_node_id))
8248
- },
8249
- ChannelPhase::UnfundedOutboundV2(ref mut channel) => {
8244
+ ChannelPhase::UnfundedV2(ref mut channel) => {
8250
8245
Ok(channel.tx_add_input(msg).into_msg_send_event(counterparty_node_id))
8251
8246
},
8252
8247
_ => Err("tx_add_input"),
@@ -8257,10 +8252,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8257
8252
fn internal_tx_add_output(&self, counterparty_node_id: PublicKey, msg: &msgs::TxAddOutput) -> Result<(), MsgHandleErrInternal> {
8258
8253
self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel_phase: &mut ChannelPhase<SP>| {
8259
8254
match channel_phase {
8260
- ChannelPhase::UnfundedInboundV2(ref mut channel) => {
8261
- Ok(channel.tx_add_output(msg).into_msg_send_event(counterparty_node_id))
8262
- },
8263
- ChannelPhase::UnfundedOutboundV2(ref mut channel) => {
8255
+ ChannelPhase::UnfundedV2(ref mut channel) => {
8264
8256
Ok(channel.tx_add_output(msg).into_msg_send_event(counterparty_node_id))
8265
8257
},
8266
8258
_ => Err("tx_add_output"),
@@ -8271,10 +8263,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8271
8263
fn internal_tx_remove_input(&self, counterparty_node_id: PublicKey, msg: &msgs::TxRemoveInput) -> Result<(), MsgHandleErrInternal> {
8272
8264
self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel_phase: &mut ChannelPhase<SP>| {
8273
8265
match channel_phase {
8274
- ChannelPhase::UnfundedInboundV2(ref mut channel) => {
8275
- Ok(channel.tx_remove_input(msg).into_msg_send_event(counterparty_node_id))
8276
- },
8277
- ChannelPhase::UnfundedOutboundV2(ref mut channel) => {
8266
+ ChannelPhase::UnfundedV2(ref mut channel) => {
8278
8267
Ok(channel.tx_remove_input(msg).into_msg_send_event(counterparty_node_id))
8279
8268
},
8280
8269
_ => Err("tx_remove_input"),
@@ -8285,10 +8274,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8285
8274
fn internal_tx_remove_output(&self, counterparty_node_id: PublicKey, msg: &msgs::TxRemoveOutput) -> Result<(), MsgHandleErrInternal> {
8286
8275
self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel_phase: &mut ChannelPhase<SP>| {
8287
8276
match channel_phase {
8288
- ChannelPhase::UnfundedInboundV2(ref mut channel) => {
8289
- Ok(channel.tx_remove_output(msg).into_msg_send_event(counterparty_node_id))
8290
- },
8291
- ChannelPhase::UnfundedOutboundV2(ref mut channel) => {
8277
+ ChannelPhase::UnfundedV2(ref mut channel) => {
8292
8278
Ok(channel.tx_remove_output(msg).into_msg_send_event(counterparty_node_id))
8293
8279
},
8294
8280
_ => Err("tx_remove_output"),
@@ -8311,9 +8297,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8311
8297
hash_map::Entry::Occupied(mut chan_phase_entry) => {
8312
8298
let channel_phase = chan_phase_entry.get_mut();
8313
8299
let (msg_send_event_opt, signing_session_opt) = match channel_phase {
8314
- ChannelPhase::UnfundedInboundV2(channel) => channel.tx_complete(msg)
8315
- .into_msg_send_event_or_signing_session(counterparty_node_id),
8316
- ChannelPhase::UnfundedOutboundV2(channel) => channel.tx_complete(msg)
8300
+ ChannelPhase::UnfundedV2(channel) => channel.tx_complete(msg)
8317
8301
.into_msg_send_event_or_signing_session(counterparty_node_id),
8318
8302
_ => try_chan_phase_entry!(self, peer_state, Err(ChannelError::Close(
8319
8303
(
@@ -8326,10 +8310,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8326
8310
};
8327
8311
if let Some(mut signing_session) = signing_session_opt {
8328
8312
let (commitment_signed, funding_ready_for_sig_event_opt) = match chan_phase_entry.get_mut() {
8329
- ChannelPhase::UnfundedOutboundV2(chan) => {
8330
- chan.funding_tx_constructed(&mut signing_session, &self.logger)
8331
- },
8332
- ChannelPhase::UnfundedInboundV2(chan) => {
8313
+ ChannelPhase::UnfundedV2(chan) => {
8333
8314
chan.funding_tx_constructed(&mut signing_session, &self.logger)
8334
8315
},
8335
8316
_ => Err(ChannelError::Warn(
@@ -8338,8 +8319,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8338
8319
}.map_err(|err| MsgHandleErrInternal::send_err_msg_no_close(format!("{}", err), msg.channel_id))?;
8339
8320
let (channel_id, channel_phase) = chan_phase_entry.remove_entry();
8340
8321
let channel = match channel_phase {
8341
- ChannelPhase::UnfundedOutboundV2(chan) => chan.into_channel(signing_session),
8342
- ChannelPhase::UnfundedInboundV2(chan) => chan.into_channel(signing_session),
8322
+ ChannelPhase::UnfundedV2(chan) => chan.into_channel(signing_session),
8343
8323
_ => {
8344
8324
debug_assert!(false); // It cannot be another variant as we are in the `Ok` branch of the above match.
8345
8325
Err(ChannelError::Warn(
@@ -8435,8 +8415,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8435
8415
hash_map::Entry::Occupied(mut chan_phase_entry) => {
8436
8416
let channel_phase = chan_phase_entry.get_mut();
8437
8417
let tx_constructor = match channel_phase {
8438
- ChannelPhase::UnfundedInboundV2(chan) => &mut chan.interactive_tx_constructor,
8439
- ChannelPhase::UnfundedOutboundV2(chan) => &mut chan.interactive_tx_constructor,
8418
+ ChannelPhase::UnfundedV2(chan) => &mut chan.interactive_tx_constructor,
8440
8419
ChannelPhase::Funded(_) => {
8441
8420
// TODO(splicing)/TODO(RBF): We'll also be doing interactive tx construction
8442
8421
// for a "ChannelPhase::Funded" when we want to bump the fee on an interactively
@@ -8583,7 +8562,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8583
8562
}
8584
8563
},
8585
8564
ChannelPhase::UnfundedInboundV1(_) | ChannelPhase::UnfundedOutboundV1(_) |
8586
- ChannelPhase::UnfundedInboundV2(_) | ChannelPhase::UnfundedOutboundV2 (_) => {
8565
+ ChannelPhase::UnfundedV2 (_) => {
8587
8566
let context = phase.context_mut();
8588
8567
let logger = WithChannelContext::from(&self.logger, context, None);
8589
8568
log_error!(logger, "Immediately closing unfunded channel {} as peer asked to cooperatively shut it down (which is unnecessary)", &msg.channel_id);
@@ -9560,7 +9539,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9560
9539
}
9561
9540
None
9562
9541
},
9563
- ChannelPhase::UnfundedInboundV2(_) | ChannelPhase::UnfundedOutboundV2 (_) => None,
9542
+ ChannelPhase::UnfundedV2 (_) => None,
9564
9543
}
9565
9544
};
9566
9545
@@ -10997,7 +10976,7 @@ where
10997
10976
match phase {
10998
10977
// Retain unfunded channels.
10999
10978
ChannelPhase::UnfundedOutboundV1(_) | ChannelPhase::UnfundedInboundV1(_) |
11000
- ChannelPhase::UnfundedOutboundV2(_) | ChannelPhase::UnfundedInboundV2 (_) => true,
10979
+ ChannelPhase::UnfundedV2 (_) => true,
11001
10980
ChannelPhase::Funded(channel) => {
11002
10981
let res = f(channel);
11003
10982
if let Ok((channel_ready_opt, mut timed_out_pending_htlcs, announcement_sigs)) = res {
@@ -11525,10 +11504,7 @@ where
11525
11504
ChannelPhase::UnfundedInboundV1(chan) => {
11526
11505
&mut chan.context
11527
11506
},
11528
- ChannelPhase::UnfundedOutboundV2(chan) => {
11529
- &mut chan.context
11530
- },
11531
- ChannelPhase::UnfundedInboundV2(chan) => {
11507
+ ChannelPhase::UnfundedV2(chan) => {
11532
11508
&mut chan.context
11533
11509
},
11534
11510
};
@@ -11681,8 +11657,7 @@ where
11681
11657
node_id: chan.context.get_counterparty_node_id(),
11682
11658
msg: chan.get_channel_reestablish(&&logger),
11683
11659
});
11684
- }
11685
-
11660
+ },
11686
11661
ChannelPhase::UnfundedOutboundV1(chan) => {
11687
11662
let logger = WithChannelContext::from(&self.logger, &chan.context, None);
11688
11663
if let Some(msg) = chan.get_open_channel(self.chain_hash, &&logger) {
@@ -11691,21 +11666,26 @@ where
11691
11666
msg,
11692
11667
});
11693
11668
}
11694
- }
11695
-
11696
- ChannelPhase::UnfundedOutboundV2(chan) => {
11697
- pending_msg_events.push(events::MessageSendEvent::SendOpenChannelV2 {
11698
- node_id: chan.context.get_counterparty_node_id(),
11699
- msg: chan.get_open_channel_v2(self.chain_hash),
11700
- });
11701
11669
},
11702
-
11703
- ChannelPhase::UnfundedInboundV1(_) | ChannelPhase::UnfundedInboundV2(_) => {
11670
+ ChannelPhase::UnfundedV2(chan) => {
11671
+ if chan.context.is_outbound() {
11672
+ pending_msg_events.push(events::MessageSendEvent::SendOpenChannelV2 {
11673
+ node_id: chan.context.get_counterparty_node_id(),
11674
+ msg: chan.get_open_channel_v2(self.chain_hash),
11675
+ });
11676
+ } else {
11677
+ // Since unfunded inbound channel maps are cleared upon disconnecting a peer,
11678
+ // they are not persisted and won't be recovered after a crash.
11679
+ // Therefore, they shouldn't exist at this point.
11680
+ debug_assert!(false);
11681
+ }
11682
+ },
11683
+ ChannelPhase::UnfundedInboundV1(_) => {
11704
11684
// Since unfunded inbound channel maps are cleared upon disconnecting a peer,
11705
11685
// they are not persisted and won't be recovered after a crash.
11706
11686
// Therefore, they shouldn't exist at this point.
11707
11687
debug_assert!(false);
11708
- }
11688
+ },
11709
11689
}
11710
11690
}
11711
11691
}
@@ -11803,16 +11783,18 @@ where
11803
11783
return;
11804
11784
}
11805
11785
},
11806
- Some(ChannelPhase::UnfundedOutboundV2(ref mut chan)) => {
11807
- if let Ok(msg) = chan.maybe_handle_error_without_close(self.chain_hash, &self.fee_estimator) {
11808
- peer_state.pending_msg_events.push(events::MessageSendEvent::SendOpenChannelV2 {
11809
- node_id: counterparty_node_id,
11810
- msg,
11811
- });
11812
- return;
11786
+ Some(ChannelPhase::UnfundedV2(ref mut chan)) => {
11787
+ if chan.context.is_outbound() {
11788
+ if let Ok(msg) = chan.maybe_handle_error_without_close(self.chain_hash, &self.fee_estimator) {
11789
+ peer_state.pending_msg_events.push(events::MessageSendEvent::SendOpenChannelV2 {
11790
+ node_id: counterparty_node_id,
11791
+ msg,
11792
+ });
11793
+ return;
11794
+ }
11813
11795
}
11814
11796
},
11815
- None | Some(ChannelPhase::UnfundedInboundV1(_) | ChannelPhase::UnfundedInboundV2(_) | ChannelPhase:: Funded(_)) => (),
11797
+ None | Some(ChannelPhase::UnfundedInboundV1(_) | ChannelPhase::Funded(_)) => (),
11816
11798
}
11817
11799
}
11818
11800
0 commit comments