Skip to content

Commit 8c334cb

Browse files
committed
Add splicing feature flag (also triggers dual_funding)
1 parent ac9a2c8 commit 8c334cb

File tree

9 files changed

+73
-69
lines changed

9 files changed

+73
-69
lines changed

ci/check-cfg-flags.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ def check_cfg_tag(cfg):
9898
pass
9999
elif cfg == "dual_funding":
100100
pass
101+
elif cfg == "splicing":
102+
pass
101103
else:
102104
print("Bad cfg tag: " + cfg)
103105
assert False

ci/ci-tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,5 @@ RUSTFLAGS="--cfg=taproot" cargo test --verbose --color always -p lightning
177177
RUSTFLAGS="--cfg=async_signing" cargo test --verbose --color always -p lightning
178178
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
179179
RUSTFLAGS="--cfg=dual_funding" cargo test --verbose --color always -p lightning
180+
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
181+
RUSTFLAGS="--cfg=splicing" cargo test --verbose --color always -p lightning

lightning-net-tokio/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,11 @@ mod tests {
624624
fn handle_open_channel_v2(&self, _their_node_id: &PublicKey, _msg: &OpenChannelV2) {}
625625
fn handle_accept_channel_v2(&self, _their_node_id: &PublicKey, _msg: &AcceptChannelV2) {}
626626
fn handle_stfu(&self, _their_node_id: &PublicKey, _msg: &Stfu) {}
627-
#[cfg(dual_funding)]
627+
#[cfg(splicing)]
628628
fn handle_splice(&self, _their_node_id: &PublicKey, _msg: &Splice) {}
629-
#[cfg(dual_funding)]
629+
#[cfg(splicing)]
630630
fn handle_splice_ack(&self, _their_node_id: &PublicKey, _msg: &SpliceAck) {}
631-
#[cfg(dual_funding)]
631+
#[cfg(splicing)]
632632
fn handle_splice_locked(&self, _their_node_id: &PublicKey, _msg: &SpliceLocked) {}
633633
fn handle_tx_add_input(&self, _their_node_id: &PublicKey, _msg: &TxAddInput) {}
634634
fn handle_tx_add_output(&self, _their_node_id: &PublicKey, _msg: &TxAddOutput) {}

lightning/src/ln/channel.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,9 +1189,9 @@ impl_writeable_tlv_based!(PendingChannelMonitorUpdate, {
11891189
pub(super) enum ChannelPhase<SP: Deref> where SP::Target: SignerProvider {
11901190
UnfundedOutboundV1(OutboundV1Channel<SP>),
11911191
UnfundedInboundV1(InboundV1Channel<SP>),
1192-
#[cfg(dual_funding)]
1192+
#[cfg(any(dual_funding, splicing))]
11931193
UnfundedOutboundV2(OutboundV2Channel<SP>),
1194-
#[cfg(dual_funding)]
1194+
#[cfg(any(dual_funding, splicing))]
11951195
UnfundedInboundV2(InboundV2Channel<SP>),
11961196
Funded(Channel<SP>),
11971197
}
@@ -1205,9 +1205,9 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
12051205
ChannelPhase::Funded(chan) => &chan.context,
12061206
ChannelPhase::UnfundedOutboundV1(chan) => &chan.context,
12071207
ChannelPhase::UnfundedInboundV1(chan) => &chan.context,
1208-
#[cfg(dual_funding)]
1208+
#[cfg(any(dual_funding, splicing))]
12091209
ChannelPhase::UnfundedOutboundV2(chan) => &chan.context,
1210-
#[cfg(dual_funding)]
1210+
#[cfg(any(dual_funding, splicing))]
12111211
ChannelPhase::UnfundedInboundV2(chan) => &chan.context,
12121212
}
12131213
}
@@ -1217,9 +1217,9 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
12171217
ChannelPhase::Funded(ref mut chan) => &mut chan.context,
12181218
ChannelPhase::UnfundedOutboundV1(ref mut chan) => &mut chan.context,
12191219
ChannelPhase::UnfundedInboundV1(ref mut chan) => &mut chan.context,
1220-
#[cfg(dual_funding)]
1220+
#[cfg(any(dual_funding, splicing))]
12211221
ChannelPhase::UnfundedOutboundV2(ref mut chan) => &mut chan.context,
1222-
#[cfg(dual_funding)]
1222+
#[cfg(any(dual_funding, splicing))]
12231223
ChannelPhase::UnfundedInboundV2(ref mut chan) => &mut chan.context,
12241224
}
12251225
}
@@ -3501,7 +3501,7 @@ pub(crate) fn get_legacy_default_holder_selected_channel_reserve_satoshis(channe
35013501
///
35023502
/// This is used both for outbound and inbound channels and has lower bound
35033503
/// of `dust_limit_satoshis`.
3504-
#[cfg(dual_funding)]
3504+
#[cfg(any(dual_funding, splicing))]
35053505
fn get_v2_channel_reserve_satoshis(channel_value_satoshis: u64, dust_limit_satoshis: u64) -> u64 {
35063506
// Fixed at 1% of channel value by spec.
35073507
let (q, _) = channel_value_satoshis.overflowing_div(100);
@@ -3524,7 +3524,7 @@ pub(crate) fn commit_tx_fee_msat(feerate_per_kw: u32, num_htlcs: usize, channel_
35243524
}
35253525

35263526
/// Context for dual-funded channels.
3527-
#[cfg(dual_funding)]
3527+
#[cfg(any(dual_funding, splicing))]
35283528
pub(super) struct DualFundingChannelContext {
35293529
/// The amount in satoshis we will be contributing to the channel.
35303530
pub our_funding_satoshis: u64,
@@ -3541,7 +3541,7 @@ pub(super) struct DualFundingChannelContext {
35413541
// Counterparty designates channel data owned by the another channel participant entity.
35423542
pub(super) struct Channel<SP: Deref> where SP::Target: SignerProvider {
35433543
pub context: ChannelContext<SP>,
3544-
#[cfg(dual_funding)]
3544+
#[cfg(any(dual_funding, splicing))]
35453545
pub dual_funding_channel_context: Option<DualFundingChannelContext>,
35463546
}
35473547

@@ -7704,7 +7704,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
77047704

77057705
let mut channel = Channel {
77067706
context: self.context,
7707-
#[cfg(dual_funding)]
7707+
#[cfg(any(dual_funding, splicing))]
77087708
dual_funding_channel_context: None,
77097709
};
77107710

@@ -7994,7 +7994,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
79947994
// `ChannelMonitor`.
79957995
let mut channel = Channel {
79967996
context: self.context,
7997-
#[cfg(dual_funding)]
7997+
#[cfg(any(dual_funding, splicing))]
79987998
dual_funding_channel_context: None,
79997999
};
80008000
let need_channel_ready = channel.check_get_channel_ready(0).is_some();
@@ -8005,15 +8005,15 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
80058005
}
80068006

80078007
// A not-yet-funded outbound (from holder) channel using V2 channel establishment.
8008-
#[cfg(dual_funding)]
8008+
#[cfg(any(dual_funding, splicing))]
80098009
pub(super) struct OutboundV2Channel<SP: Deref> where SP::Target: SignerProvider {
80108010
pub context: ChannelContext<SP>,
80118011
pub unfunded_context: UnfundedChannelContext,
8012-
#[cfg(dual_funding)]
8012+
#[cfg(any(dual_funding, splicing))]
80138013
pub dual_funding_context: DualFundingChannelContext,
80148014
}
80158015

8016-
#[cfg(dual_funding)]
8016+
#[cfg(any(dual_funding, splicing))]
80178017
impl<SP: Deref> OutboundV2Channel<SP> where SP::Target: SignerProvider {
80188018
pub fn new<ES: Deref, F: Deref>(
80198019
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
@@ -8129,14 +8129,14 @@ impl<SP: Deref> OutboundV2Channel<SP> where SP::Target: SignerProvider {
81298129
}
81308130

81318131
// A not-yet-funded inbound (from counterparty) channel using V2 channel establishment.
8132-
#[cfg(dual_funding)]
8132+
#[cfg(any(dual_funding, splicing))]
81338133
pub(super) struct InboundV2Channel<SP: Deref> where SP::Target: SignerProvider {
81348134
pub context: ChannelContext<SP>,
81358135
pub unfunded_context: UnfundedChannelContext,
81368136
pub dual_funding_context: DualFundingChannelContext,
81378137
}
81388138

8139-
#[cfg(dual_funding)]
8139+
#[cfg(any(dual_funding, splicing))]
81408140
impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
81418141
/// Creates a new dual-funded channel from a remote side's request for one.
81428142
/// Assumes chain_hash has already been checked and corresponds with what we expect!
@@ -9303,7 +9303,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
93039303

93049304
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
93059305
},
9306-
#[cfg(dual_funding)]
9306+
#[cfg(any(dual_funding, splicing))]
93079307
dual_funding_channel_context: None,
93089308
})
93099309
}

lightning/src/ln/channelmanager.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -918,9 +918,9 @@ impl <SP: Deref> PeerState<SP> where SP::Target: SignerProvider {
918918
match phase {
919919
ChannelPhase::Funded(_) | ChannelPhase::UnfundedOutboundV1(_) => true,
920920
ChannelPhase::UnfundedInboundV1(_) => false,
921-
#[cfg(dual_funding)]
921+
#[cfg(any(dual_funding, splicing))]
922922
ChannelPhase::UnfundedOutboundV2(_) => true,
923-
#[cfg(dual_funding)]
923+
#[cfg(any(dual_funding, splicing))]
924924
ChannelPhase::UnfundedInboundV2(_) => false,
925925
}
926926
)
@@ -2774,11 +2774,11 @@ macro_rules! convert_chan_phase_err {
27742774
ChannelPhase::UnfundedInboundV1(channel) => {
27752775
convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
27762776
},
2777-
#[cfg(dual_funding)]
2777+
#[cfg(any(dual_funding, splicing))]
27782778
ChannelPhase::UnfundedOutboundV2(channel) => {
27792779
convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
27802780
},
2781-
#[cfg(dual_funding)]
2781+
#[cfg(any(dual_funding, splicing))]
27822782
ChannelPhase::UnfundedInboundV2(channel) => {
27832783
convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
27842784
},
@@ -3653,8 +3653,8 @@ where
36533653
// Unfunded channel has no update
36543654
(None, chan_phase.context().get_counterparty_node_id())
36553655
},
3656-
// TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
3657-
#[cfg(dual_funding)]
3656+
// TODO(dual_funding): Combine this match arm with above once #[cfg(any(dual_funding, splicing))] is removed.
3657+
#[cfg(any(dual_funding, splicing))]
36583658
ChannelPhase::UnfundedOutboundV2(_) | ChannelPhase::UnfundedInboundV2(_) => {
36593659
self.finish_close_channel(chan_phase.context_mut().force_shutdown(false, closure_reason));
36603660
// Unfunded channel has no update
@@ -5882,12 +5882,12 @@ where
58825882
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
58835883
pending_msg_events, counterparty_node_id)
58845884
},
5885-
#[cfg(dual_funding)]
5885+
#[cfg(any(dual_funding, splicing))]
58865886
ChannelPhase::UnfundedInboundV2(chan) => {
58875887
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
58885888
pending_msg_events, counterparty_node_id)
58895889
},
5890-
#[cfg(dual_funding)]
5890+
#[cfg(any(dual_funding, splicing))]
58915891
ChannelPhase::UnfundedOutboundV2(chan) => {
58925892
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
58935893
pending_msg_events, counterparty_node_id)
@@ -7059,8 +7059,8 @@ where
70597059
num_unfunded_channels += 1;
70607060
}
70617061
},
7062-
// TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
7063-
#[cfg(dual_funding)]
7062+
// TODO(dual_funding): Combine this match arm with above once #[cfg(any(dual_funding, splicing))] is removed.
7063+
#[cfg(any(dual_funding, splicing))]
70647064
ChannelPhase::UnfundedInboundV2(chan) => {
70657065
// Only inbound V2 channels that are not 0conf and that we do not contribute to will be
70667066
// included in the unfunded count.
@@ -7073,8 +7073,8 @@ where
70737073
// Outbound channels don't contribute to the unfunded count in the DoS context.
70747074
continue;
70757075
},
7076-
// TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
7077-
#[cfg(dual_funding)]
7076+
// TODO(dual_funding): Combine this match arm with above once #[cfg(any(dual_funding, splicing))] is removed.
7077+
#[cfg(any(dual_funding, splicing))]
70787078
ChannelPhase::UnfundedOutboundV2(_) => {
70797079
// Outbound channels don't contribute to the unfunded count in the DoS context.
70807080
continue;
@@ -7501,7 +7501,7 @@ where
75017501
finish_shutdown = Some(chan.context_mut().force_shutdown(false, ClosureReason::CounterpartyCoopClosedUnfundedChannel));
75027502
},
75037503
// TODO(dual_funding): Combine this match arm with above.
7504-
#[cfg(dual_funding)]
7504+
#[cfg(any(dual_funding, splicing))]
75057505
ChannelPhase::UnfundedInboundV2(_) | ChannelPhase::UnfundedOutboundV2(_) => {
75067506
let context = phase.context_mut();
75077507
log_error!(self.logger, "Immediately closing unfunded channel {} as peer asked to cooperatively shut it down (which is unnecessary)", &msg.channel_id);
@@ -9450,7 +9450,7 @@ where
94509450
// Retain unfunded channels.
94519451
ChannelPhase::UnfundedOutboundV1(_) | ChannelPhase::UnfundedInboundV1(_) => true,
94529452
// TODO(dual_funding): Combine this match arm with above.
9453-
#[cfg(dual_funding)]
9453+
#[cfg(any(dual_funding, splicing))]
94549454
ChannelPhase::UnfundedOutboundV2(_) | ChannelPhase::UnfundedInboundV2(_) => true,
94559455
ChannelPhase::Funded(channel) => {
94569456
let res = f(channel);
@@ -9756,21 +9756,21 @@ where
97569756
msg.channel_id.clone())), *counterparty_node_id);
97579757
}
97589758

9759-
#[cfg(dual_funding)]
9759+
#[cfg(splicing)]
97609760
fn handle_splice(&self, counterparty_node_id: &PublicKey, msg: &msgs::Splice) {
97619761
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
97629762
"Splicing not supported".to_owned(),
97639763
msg.channel_id.clone())), *counterparty_node_id);
97649764
}
97659765

9766-
#[cfg(dual_funding)]
9766+
#[cfg(splicing)]
97679767
fn handle_splice_ack(&self, counterparty_node_id: &PublicKey, msg: &msgs::SpliceAck) {
97689768
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
97699769
"Splicing not supported (splice_ack)".to_owned(),
97709770
msg.channel_id.clone())), *counterparty_node_id);
97719771
}
97729772

9773-
#[cfg(dual_funding)]
9773+
#[cfg(splicing)]
97749774
fn handle_splice_locked(&self, counterparty_node_id: &PublicKey, msg: &msgs::SpliceLocked) {
97759775
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
97769776
"Splicing not supported (splice_locked)".to_owned(),
@@ -9928,11 +9928,11 @@ where
99289928
ChannelPhase::UnfundedInboundV1(chan) => {
99299929
&mut chan.context
99309930
},
9931-
#[cfg(dual_funding)]
9931+
#[cfg(any(dual_funding, splicing))]
99329932
ChannelPhase::UnfundedOutboundV2(chan) => {
99339933
&mut chan.context
99349934
},
9935-
#[cfg(dual_funding)]
9935+
#[cfg(any(dual_funding, splicing))]
99369936
ChannelPhase::UnfundedInboundV2(chan) => {
99379937
&mut chan.context
99389938
},
@@ -10093,8 +10093,8 @@ where
1009310093
});
1009410094
}
1009510095

10096-
// TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
10097-
#[cfg(dual_funding)]
10096+
// TODO(dual_funding): Combine this match arm with above once #[cfg(any(dual_funding, splicing))] is removed.
10097+
#[cfg(any(dual_funding, splicing))]
1009810098
ChannelPhase::UnfundedOutboundV2(chan) => {
1009910099
pending_msg_events.push(events::MessageSendEvent::SendOpenChannelV2 {
1010010100
node_id: chan.context.get_counterparty_node_id(),
@@ -10109,8 +10109,8 @@ where
1010910109
debug_assert!(false);
1011010110
}
1011110111

10112-
// TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
10113-
#[cfg(dual_funding)]
10112+
// TODO(dual_funding): Combine this match arm with above once #[cfg(any(dual_funding, splicing))] is removed.
10113+
#[cfg(any(dual_funding, splicing))]
1011410114
ChannelPhase::UnfundedInboundV2(channel) => {
1011510115
// Since unfunded inbound channel maps are cleared upon disconnecting a peer,
1011610116
// they are not persisted and won't be recovered after a crash.
@@ -10213,7 +10213,7 @@ where
1021310213
return;
1021410214
}
1021510215
},
10216-
#[cfg(dual_funding)]
10216+
#[cfg(any(dual_funding, splicing))]
1021710217
Some(ChannelPhase::UnfundedOutboundV2(ref mut chan)) => {
1021810218
if let Ok(msg) = chan.maybe_handle_error_without_close(self.chain_hash, &self.fee_estimator) {
1021910219
peer_state.pending_msg_events.push(events::MessageSendEvent::SendOpenChannelV2 {
@@ -10224,7 +10224,7 @@ where
1022410224
}
1022510225
},
1022610226
None | Some(ChannelPhase::UnfundedInboundV1(_) | ChannelPhase::Funded(_)) => (),
10227-
#[cfg(dual_funding)]
10227+
#[cfg(any(dual_funding, splicing))]
1022810228
Some(ChannelPhase::UnfundedInboundV2(_)) => (),
1022910229
}
1023010230
}

lightning/src/ln/msgs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,13 +1462,13 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider {
14621462

14631463
// Splicing
14641464
/// Handle an incoming `splice` message from the given peer.
1465-
#[cfg(dual_funding)]
1465+
#[cfg(splicing)]
14661466
fn handle_splice(&self, their_node_id: &PublicKey, msg: &Splice);
14671467
/// Handle an incoming `splice_ack` message from the given peer.
1468-
#[cfg(dual_funding)]
1468+
#[cfg(splicing)]
14691469
fn handle_splice_ack(&self, their_node_id: &PublicKey, msg: &SpliceAck);
14701470
/// Handle an incoming `splice_locked` message from the given peer.
1471-
#[cfg(dual_funding)]
1471+
#[cfg(splicing)]
14721472
fn handle_splice_locked(&self, their_node_id: &PublicKey, msg: &SpliceLocked);
14731473

14741474
// Interactive channel construction

lightning/src/ln/peer_handler.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,15 @@ impl ChannelMessageHandler for ErroringMessageHandler {
248248
fn handle_stfu(&self, their_node_id: &PublicKey, msg: &msgs::Stfu) {
249249
ErroringMessageHandler::push_error(&self, their_node_id, msg.channel_id);
250250
}
251-
#[cfg(dual_funding)]
251+
#[cfg(splicing)]
252252
fn handle_splice(&self, their_node_id: &PublicKey, msg: &msgs::Splice) {
253253
ErroringMessageHandler::push_error(&self, their_node_id, msg.channel_id);
254254
}
255-
#[cfg(dual_funding)]
255+
#[cfg(splicing)]
256256
fn handle_splice_ack(&self, their_node_id: &PublicKey, msg: &msgs::SpliceAck) {
257257
ErroringMessageHandler::push_error(&self, their_node_id, msg.channel_id);
258258
}
259-
#[cfg(dual_funding)]
259+
#[cfg(splicing)]
260260
fn handle_splice_locked(&self, their_node_id: &PublicKey, msg: &msgs::SpliceLocked) {
261261
ErroringMessageHandler::push_error(&self, their_node_id, msg.channel_id);
262262
}
@@ -1787,16 +1787,16 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
17871787
self.message_handler.chan_handler.handle_stfu(&their_node_id, &msg);
17881788
}
17891789

1790-
#[cfg(dual_funding)]
1790+
#[cfg(splicing)]
17911791
// Splicing messages:
17921792
wire::Message::Splice(msg) => {
17931793
self.message_handler.chan_handler.handle_splice(&their_node_id, &msg);
17941794
}
1795-
#[cfg(dual_funding)]
1795+
#[cfg(splicing)]
17961796
wire::Message::SpliceAck(msg) => {
17971797
self.message_handler.chan_handler.handle_splice_ack(&their_node_id, &msg);
17981798
}
1799-
#[cfg(dual_funding)]
1799+
#[cfg(splicing)]
18001800
wire::Message::SpliceLocked(msg) => {
18011801
self.message_handler.chan_handler.handle_splice_locked(&their_node_id, &msg);
18021802
}

0 commit comments

Comments
 (0)