Skip to content

Add splicing feature flag #3001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ci/check-cfg-flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ def check_cfg_tag(cfg):
pass
elif cfg == "dual_funding":
pass
elif cfg == "splicing":
pass
else:
print("Bad cfg tag: " + cfg)
assert False
Expand Down
2 changes: 2 additions & 0 deletions ci/ci-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,5 @@ RUSTFLAGS="--cfg=taproot" cargo test --verbose --color always -p lightning
RUSTFLAGS="--cfg=async_signing" cargo test --verbose --color always -p lightning
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
RUSTFLAGS="--cfg=dual_funding" cargo test --verbose --color always -p lightning
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
RUSTFLAGS="--cfg=splicing" cargo test --verbose --color always -p lightning
6 changes: 3 additions & 3 deletions lightning-net-tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,11 @@ mod tests {
fn handle_open_channel_v2(&self, _their_node_id: &PublicKey, _msg: &OpenChannelV2) {}
fn handle_accept_channel_v2(&self, _their_node_id: &PublicKey, _msg: &AcceptChannelV2) {}
fn handle_stfu(&self, _their_node_id: &PublicKey, _msg: &Stfu) {}
#[cfg(dual_funding)]
#[cfg(splicing)]
fn handle_splice(&self, _their_node_id: &PublicKey, _msg: &Splice) {}
#[cfg(dual_funding)]
#[cfg(splicing)]
fn handle_splice_ack(&self, _their_node_id: &PublicKey, _msg: &SpliceAck) {}
#[cfg(dual_funding)]
#[cfg(splicing)]
fn handle_splice_locked(&self, _their_node_id: &PublicKey, _msg: &SpliceLocked) {}
fn handle_tx_add_input(&self, _their_node_id: &PublicKey, _msg: &TxAddInput) {}
fn handle_tx_add_output(&self, _their_node_id: &PublicKey, _msg: &TxAddOutput) {}
Expand Down
34 changes: 17 additions & 17 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,9 +1189,9 @@ impl_writeable_tlv_based!(PendingChannelMonitorUpdate, {
pub(super) enum ChannelPhase<SP: Deref> where SP::Target: SignerProvider {
UnfundedOutboundV1(OutboundV1Channel<SP>),
UnfundedInboundV1(InboundV1Channel<SP>),
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
UnfundedOutboundV2(OutboundV2Channel<SP>),
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
UnfundedInboundV2(InboundV2Channel<SP>),
Funded(Channel<SP>),
}
Expand All @@ -1205,9 +1205,9 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
ChannelPhase::Funded(chan) => &chan.context,
ChannelPhase::UnfundedOutboundV1(chan) => &chan.context,
ChannelPhase::UnfundedInboundV1(chan) => &chan.context,
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
ChannelPhase::UnfundedOutboundV2(chan) => &chan.context,
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
ChannelPhase::UnfundedInboundV2(chan) => &chan.context,
}
}
Expand All @@ -1217,9 +1217,9 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
ChannelPhase::Funded(ref mut chan) => &mut chan.context,
ChannelPhase::UnfundedOutboundV1(ref mut chan) => &mut chan.context,
ChannelPhase::UnfundedInboundV1(ref mut chan) => &mut chan.context,
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
ChannelPhase::UnfundedOutboundV2(ref mut chan) => &mut chan.context,
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
ChannelPhase::UnfundedInboundV2(ref mut chan) => &mut chan.context,
}
}
Expand Down Expand Up @@ -3501,7 +3501,7 @@ pub(crate) fn get_legacy_default_holder_selected_channel_reserve_satoshis(channe
///
/// This is used both for outbound and inbound channels and has lower bound
/// of `dust_limit_satoshis`.
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
fn get_v2_channel_reserve_satoshis(channel_value_satoshis: u64, dust_limit_satoshis: u64) -> u64 {
// Fixed at 1% of channel value by spec.
let (q, _) = channel_value_satoshis.overflowing_div(100);
Expand All @@ -3524,7 +3524,7 @@ pub(crate) fn commit_tx_fee_msat(feerate_per_kw: u32, num_htlcs: usize, channel_
}

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

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

let mut channel = Channel {
context: self.context,
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
};

Expand Down Expand Up @@ -7994,7 +7994,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
// `ChannelMonitor`.
let mut channel = Channel {
context: self.context,
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
};
let need_channel_ready = channel.check_get_channel_ready(0).is_some();
Expand All @@ -8005,15 +8005,15 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
}

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

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

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

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

blocked_monitor_updates: blocked_monitor_updates.unwrap(),
},
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
})
}
Expand Down
50 changes: 25 additions & 25 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,9 @@ impl <SP: Deref> PeerState<SP> where SP::Target: SignerProvider {
match phase {
ChannelPhase::Funded(_) | ChannelPhase::UnfundedOutboundV1(_) => true,
ChannelPhase::UnfundedInboundV1(_) => false,
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
ChannelPhase::UnfundedOutboundV2(_) => true,
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
ChannelPhase::UnfundedInboundV2(_) => false,
}
)
Expand Down Expand Up @@ -2774,11 +2774,11 @@ macro_rules! convert_chan_phase_err {
ChannelPhase::UnfundedInboundV1(channel) => {
convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
},
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
ChannelPhase::UnfundedOutboundV2(channel) => {
convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
},
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
ChannelPhase::UnfundedInboundV2(channel) => {
convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
},
Expand Down Expand Up @@ -3653,8 +3653,8 @@ where
// Unfunded channel has no update
(None, chan_phase.context().get_counterparty_node_id())
},
// TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
#[cfg(dual_funding)]
// TODO(dual_funding): Combine this match arm with above once #[cfg(any(dual_funding, splicing))] is removed.
#[cfg(any(dual_funding, splicing))]
ChannelPhase::UnfundedOutboundV2(_) | ChannelPhase::UnfundedInboundV2(_) => {
self.finish_close_channel(chan_phase.context_mut().force_shutdown(false, closure_reason));
// Unfunded channel has no update
Expand Down Expand Up @@ -5882,12 +5882,12 @@ where
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
pending_msg_events, counterparty_node_id)
},
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
ChannelPhase::UnfundedInboundV2(chan) => {
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
pending_msg_events, counterparty_node_id)
},
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
ChannelPhase::UnfundedOutboundV2(chan) => {
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
pending_msg_events, counterparty_node_id)
Expand Down Expand Up @@ -7059,8 +7059,8 @@ where
num_unfunded_channels += 1;
}
},
// TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
#[cfg(dual_funding)]
// TODO(dual_funding): Combine this match arm with above once #[cfg(any(dual_funding, splicing))] is removed.
#[cfg(any(dual_funding, splicing))]
ChannelPhase::UnfundedInboundV2(chan) => {
// Only inbound V2 channels that are not 0conf and that we do not contribute to will be
// included in the unfunded count.
Expand All @@ -7073,8 +7073,8 @@ where
// Outbound channels don't contribute to the unfunded count in the DoS context.
continue;
},
// TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
#[cfg(dual_funding)]
// TODO(dual_funding): Combine this match arm with above once #[cfg(any(dual_funding, splicing))] is removed.
#[cfg(any(dual_funding, splicing))]
ChannelPhase::UnfundedOutboundV2(_) => {
// Outbound channels don't contribute to the unfunded count in the DoS context.
continue;
Expand Down Expand Up @@ -7501,7 +7501,7 @@ where
finish_shutdown = Some(chan.context_mut().force_shutdown(false, ClosureReason::CounterpartyCoopClosedUnfundedChannel));
},
// TODO(dual_funding): Combine this match arm with above.
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
ChannelPhase::UnfundedInboundV2(_) | ChannelPhase::UnfundedOutboundV2(_) => {
let context = phase.context_mut();
log_error!(self.logger, "Immediately closing unfunded channel {} as peer asked to cooperatively shut it down (which is unnecessary)", &msg.channel_id);
Expand Down Expand Up @@ -9450,7 +9450,7 @@ where
// Retain unfunded channels.
ChannelPhase::UnfundedOutboundV1(_) | ChannelPhase::UnfundedInboundV1(_) => true,
// TODO(dual_funding): Combine this match arm with above.
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
ChannelPhase::UnfundedOutboundV2(_) | ChannelPhase::UnfundedInboundV2(_) => true,
ChannelPhase::Funded(channel) => {
let res = f(channel);
Expand Down Expand Up @@ -9756,21 +9756,21 @@ where
msg.channel_id.clone())), *counterparty_node_id);
}

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

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

#[cfg(dual_funding)]
#[cfg(splicing)]
fn handle_splice_locked(&self, counterparty_node_id: &PublicKey, msg: &msgs::SpliceLocked) {
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
"Splicing not supported (splice_locked)".to_owned(),
Expand Down Expand Up @@ -9928,11 +9928,11 @@ where
ChannelPhase::UnfundedInboundV1(chan) => {
&mut chan.context
},
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
ChannelPhase::UnfundedOutboundV2(chan) => {
&mut chan.context
},
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
ChannelPhase::UnfundedInboundV2(chan) => {
&mut chan.context
},
Expand Down Expand Up @@ -10093,8 +10093,8 @@ where
});
}

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

// TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
#[cfg(dual_funding)]
// TODO(dual_funding): Combine this match arm with above once #[cfg(any(dual_funding, splicing))] is removed.
#[cfg(any(dual_funding, splicing))]
ChannelPhase::UnfundedInboundV2(channel) => {
// Since unfunded inbound channel maps are cleared upon disconnecting a peer,
// they are not persisted and won't be recovered after a crash.
Expand Down Expand Up @@ -10213,7 +10213,7 @@ where
return;
}
},
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
Some(ChannelPhase::UnfundedOutboundV2(ref mut chan)) => {
if let Ok(msg) = chan.maybe_handle_error_without_close(self.chain_hash, &self.fee_estimator) {
peer_state.pending_msg_events.push(events::MessageSendEvent::SendOpenChannelV2 {
Expand All @@ -10224,7 +10224,7 @@ where
}
},
None | Some(ChannelPhase::UnfundedInboundV1(_) | ChannelPhase::Funded(_)) => (),
#[cfg(dual_funding)]
#[cfg(any(dual_funding, splicing))]
Some(ChannelPhase::UnfundedInboundV2(_)) => (),
}
}
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1462,13 +1462,13 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider {

// Splicing
/// Handle an incoming `splice` message from the given peer.
#[cfg(dual_funding)]
#[cfg(splicing)]
fn handle_splice(&self, their_node_id: &PublicKey, msg: &Splice);
/// Handle an incoming `splice_ack` message from the given peer.
#[cfg(dual_funding)]
#[cfg(splicing)]
fn handle_splice_ack(&self, their_node_id: &PublicKey, msg: &SpliceAck);
/// Handle an incoming `splice_locked` message from the given peer.
#[cfg(dual_funding)]
#[cfg(splicing)]
fn handle_splice_locked(&self, their_node_id: &PublicKey, msg: &SpliceLocked);

// Interactive channel construction
Expand Down
12 changes: 6 additions & 6 deletions lightning/src/ln/peer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,15 @@ impl ChannelMessageHandler for ErroringMessageHandler {
fn handle_stfu(&self, their_node_id: &PublicKey, msg: &msgs::Stfu) {
ErroringMessageHandler::push_error(&self, their_node_id, msg.channel_id);
}
#[cfg(dual_funding)]
#[cfg(splicing)]
fn handle_splice(&self, their_node_id: &PublicKey, msg: &msgs::Splice) {
ErroringMessageHandler::push_error(&self, their_node_id, msg.channel_id);
}
#[cfg(dual_funding)]
#[cfg(splicing)]
fn handle_splice_ack(&self, their_node_id: &PublicKey, msg: &msgs::SpliceAck) {
ErroringMessageHandler::push_error(&self, their_node_id, msg.channel_id);
}
#[cfg(dual_funding)]
#[cfg(splicing)]
fn handle_splice_locked(&self, their_node_id: &PublicKey, msg: &msgs::SpliceLocked) {
ErroringMessageHandler::push_error(&self, their_node_id, msg.channel_id);
}
Expand Down Expand Up @@ -1787,16 +1787,16 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
self.message_handler.chan_handler.handle_stfu(&their_node_id, &msg);
}

#[cfg(dual_funding)]
#[cfg(splicing)]
// Splicing messages:
wire::Message::Splice(msg) => {
self.message_handler.chan_handler.handle_splice(&their_node_id, &msg);
}
#[cfg(dual_funding)]
#[cfg(splicing)]
wire::Message::SpliceAck(msg) => {
self.message_handler.chan_handler.handle_splice_ack(&their_node_id, &msg);
}
#[cfg(dual_funding)]
#[cfg(splicing)]
wire::Message::SpliceLocked(msg) => {
self.message_handler.chan_handler.handle_splice_locked(&their_node_id, &msg);
}
Expand Down
Loading
Loading