Skip to content

Commit 19dae8b

Browse files
authored
Merge pull request #3001 from optout21/splicing-feature-bit-with-any
Add splicing feature flag
2 parents 6264a44 + 8c334cb commit 19dae8b

File tree

9 files changed

+73
-69
lines changed

9 files changed

+73
-69
lines changed

ci/check-cfg-flags.py

+2
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

+2
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

+3-3
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

+17-17
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

+25-25
Original file line numberDiff line numberDiff line change
@@ -927,9 +927,9 @@ impl <SP: Deref> PeerState<SP> where SP::Target: SignerProvider {
927927
match phase {
928928
ChannelPhase::Funded(_) | ChannelPhase::UnfundedOutboundV1(_) => true,
929929
ChannelPhase::UnfundedInboundV1(_) => false,
930-
#[cfg(dual_funding)]
930+
#[cfg(any(dual_funding, splicing))]
931931
ChannelPhase::UnfundedOutboundV2(_) => true,
932-
#[cfg(dual_funding)]
932+
#[cfg(any(dual_funding, splicing))]
933933
ChannelPhase::UnfundedInboundV2(_) => false,
934934
}
935935
)
@@ -2791,11 +2791,11 @@ macro_rules! convert_chan_phase_err {
27912791
ChannelPhase::UnfundedInboundV1(channel) => {
27922792
convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
27932793
},
2794-
#[cfg(dual_funding)]
2794+
#[cfg(any(dual_funding, splicing))]
27952795
ChannelPhase::UnfundedOutboundV2(channel) => {
27962796
convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
27972797
},
2798-
#[cfg(dual_funding)]
2798+
#[cfg(any(dual_funding, splicing))]
27992799
ChannelPhase::UnfundedInboundV2(channel) => {
28002800
convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
28012801
},
@@ -3670,8 +3670,8 @@ where
36703670
// Unfunded channel has no update
36713671
(None, chan_phase.context().get_counterparty_node_id())
36723672
},
3673-
// TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
3674-
#[cfg(dual_funding)]
3673+
// TODO(dual_funding): Combine this match arm with above once #[cfg(any(dual_funding, splicing))] is removed.
3674+
#[cfg(any(dual_funding, splicing))]
36753675
ChannelPhase::UnfundedOutboundV2(_) | ChannelPhase::UnfundedInboundV2(_) => {
36763676
self.finish_close_channel(chan_phase.context_mut().force_shutdown(false, closure_reason));
36773677
// Unfunded channel has no update
@@ -5902,12 +5902,12 @@ where
59025902
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
59035903
pending_msg_events, counterparty_node_id)
59045904
},
5905-
#[cfg(dual_funding)]
5905+
#[cfg(any(dual_funding, splicing))]
59065906
ChannelPhase::UnfundedInboundV2(chan) => {
59075907
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
59085908
pending_msg_events, counterparty_node_id)
59095909
},
5910-
#[cfg(dual_funding)]
5910+
#[cfg(any(dual_funding, splicing))]
59115911
ChannelPhase::UnfundedOutboundV2(chan) => {
59125912
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
59135913
pending_msg_events, counterparty_node_id)
@@ -7079,8 +7079,8 @@ where
70797079
num_unfunded_channels += 1;
70807080
}
70817081
},
7082-
// TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
7083-
#[cfg(dual_funding)]
7082+
// TODO(dual_funding): Combine this match arm with above once #[cfg(any(dual_funding, splicing))] is removed.
7083+
#[cfg(any(dual_funding, splicing))]
70847084
ChannelPhase::UnfundedInboundV2(chan) => {
70857085
// Only inbound V2 channels that are not 0conf and that we do not contribute to will be
70867086
// included in the unfunded count.
@@ -7093,8 +7093,8 @@ where
70937093
// Outbound channels don't contribute to the unfunded count in the DoS context.
70947094
continue;
70957095
},
7096-
// TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
7097-
#[cfg(dual_funding)]
7096+
// TODO(dual_funding): Combine this match arm with above once #[cfg(any(dual_funding, splicing))] is removed.
7097+
#[cfg(any(dual_funding, splicing))]
70987098
ChannelPhase::UnfundedOutboundV2(_) => {
70997099
// Outbound channels don't contribute to the unfunded count in the DoS context.
71007100
continue;
@@ -7521,7 +7521,7 @@ where
75217521
finish_shutdown = Some(chan.context_mut().force_shutdown(false, ClosureReason::CounterpartyCoopClosedUnfundedChannel));
75227522
},
75237523
// TODO(dual_funding): Combine this match arm with above.
7524-
#[cfg(dual_funding)]
7524+
#[cfg(any(dual_funding, splicing))]
75257525
ChannelPhase::UnfundedInboundV2(_) | ChannelPhase::UnfundedOutboundV2(_) => {
75267526
let context = phase.context_mut();
75277527
log_error!(self.logger, "Immediately closing unfunded channel {} as peer asked to cooperatively shut it down (which is unnecessary)", &msg.channel_id);
@@ -9474,7 +9474,7 @@ where
94749474
// Retain unfunded channels.
94759475
ChannelPhase::UnfundedOutboundV1(_) | ChannelPhase::UnfundedInboundV1(_) => true,
94769476
// TODO(dual_funding): Combine this match arm with above.
9477-
#[cfg(dual_funding)]
9477+
#[cfg(any(dual_funding, splicing))]
94789478
ChannelPhase::UnfundedOutboundV2(_) | ChannelPhase::UnfundedInboundV2(_) => true,
94799479
ChannelPhase::Funded(channel) => {
94809480
let res = f(channel);
@@ -9780,21 +9780,21 @@ where
97809780
msg.channel_id.clone())), *counterparty_node_id);
97819781
}
97829782

9783-
#[cfg(dual_funding)]
9783+
#[cfg(splicing)]
97849784
fn handle_splice(&self, counterparty_node_id: &PublicKey, msg: &msgs::Splice) {
97859785
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
97869786
"Splicing not supported".to_owned(),
97879787
msg.channel_id.clone())), *counterparty_node_id);
97889788
}
97899789

9790-
#[cfg(dual_funding)]
9790+
#[cfg(splicing)]
97919791
fn handle_splice_ack(&self, counterparty_node_id: &PublicKey, msg: &msgs::SpliceAck) {
97929792
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
97939793
"Splicing not supported (splice_ack)".to_owned(),
97949794
msg.channel_id.clone())), *counterparty_node_id);
97959795
}
97969796

9797-
#[cfg(dual_funding)]
9797+
#[cfg(splicing)]
97989798
fn handle_splice_locked(&self, counterparty_node_id: &PublicKey, msg: &msgs::SpliceLocked) {
97999799
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
98009800
"Splicing not supported (splice_locked)".to_owned(),
@@ -9952,11 +9952,11 @@ where
99529952
ChannelPhase::UnfundedInboundV1(chan) => {
99539953
&mut chan.context
99549954
},
9955-
#[cfg(dual_funding)]
9955+
#[cfg(any(dual_funding, splicing))]
99569956
ChannelPhase::UnfundedOutboundV2(chan) => {
99579957
&mut chan.context
99589958
},
9959-
#[cfg(dual_funding)]
9959+
#[cfg(any(dual_funding, splicing))]
99609960
ChannelPhase::UnfundedInboundV2(chan) => {
99619961
&mut chan.context
99629962
},
@@ -10117,8 +10117,8 @@ where
1011710117
});
1011810118
}
1011910119

10120-
// TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
10121-
#[cfg(dual_funding)]
10120+
// TODO(dual_funding): Combine this match arm with above once #[cfg(any(dual_funding, splicing))] is removed.
10121+
#[cfg(any(dual_funding, splicing))]
1012210122
ChannelPhase::UnfundedOutboundV2(chan) => {
1012310123
pending_msg_events.push(events::MessageSendEvent::SendOpenChannelV2 {
1012410124
node_id: chan.context.get_counterparty_node_id(),
@@ -10133,8 +10133,8 @@ where
1013310133
debug_assert!(false);
1013410134
}
1013510135

10136-
// TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
10137-
#[cfg(dual_funding)]
10136+
// TODO(dual_funding): Combine this match arm with above once #[cfg(any(dual_funding, splicing))] is removed.
10137+
#[cfg(any(dual_funding, splicing))]
1013810138
ChannelPhase::UnfundedInboundV2(channel) => {
1013910139
// Since unfunded inbound channel maps are cleared upon disconnecting a peer,
1014010140
// they are not persisted and won't be recovered after a crash.
@@ -10237,7 +10237,7 @@ where
1023710237
return;
1023810238
}
1023910239
},
10240-
#[cfg(dual_funding)]
10240+
#[cfg(any(dual_funding, splicing))]
1024110241
Some(ChannelPhase::UnfundedOutboundV2(ref mut chan)) => {
1024210242
if let Ok(msg) = chan.maybe_handle_error_without_close(self.chain_hash, &self.fee_estimator) {
1024310243
peer_state.pending_msg_events.push(events::MessageSendEvent::SendOpenChannelV2 {
@@ -10248,7 +10248,7 @@ where
1024810248
}
1024910249
},
1025010250
None | Some(ChannelPhase::UnfundedInboundV1(_) | ChannelPhase::Funded(_)) => (),
10251-
#[cfg(dual_funding)]
10251+
#[cfg(any(dual_funding, splicing))]
1025210252
Some(ChannelPhase::UnfundedInboundV2(_)) => (),
1025310253
}
1025410254
}

lightning/src/ln/msgs.rs

+3-3
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

+6-6
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)