Skip to content
Draft
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
50 changes: 20 additions & 30 deletions fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1391,14 +1391,8 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
let splice_channel = |node: &ChanMan,
counterparty_node_id: &PublicKey,
channel_id: &ChannelId,
f: &dyn Fn(FundingTemplate) -> Result<FundingContribution, ()>,
funding_feerate_sat_per_kw: FeeRate| {
match node.splice_channel(
channel_id,
counterparty_node_id,
funding_feerate_sat_per_kw,
FeeRate::MAX,
) {
f: &dyn Fn(FundingTemplate) -> Result<FundingContribution, ()>| {
match node.splice_channel(channel_id, counterparty_node_id) {
Ok(funding_template) => {
if let Ok(contribution) = f(funding_template) {
let _ = node.funding_contributed(
Expand All @@ -1425,15 +1419,10 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
channel_id: &ChannelId,
wallet: &WalletSync<&TestWalletSource, Arc<dyn Logger + MaybeSend + MaybeSync>>,
funding_feerate_sat_per_kw: FeeRate| {
splice_channel(
node,
counterparty_node_id,
channel_id,
&move |funding_template: FundingTemplate| {
funding_template.splice_in_sync(Amount::from_sat(10_000), wallet)
},
funding_feerate_sat_per_kw,
);
splice_channel(node, counterparty_node_id, channel_id, &move |funding_template: FundingTemplate| {
let feerate = funding_template.min_rbf_feerate().unwrap_or(funding_feerate_sat_per_kw);
funding_template.splice_in_sync(Amount::from_sat(10_000), feerate, FeeRate::MAX, wallet)
});
};

let splice_out = |node: &ChanMan,
Expand All @@ -1454,19 +1443,20 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
if outbound_capacity_msat < 20_000_000 {
return;
}
splice_channel(
node,
counterparty_node_id,
channel_id,
&move |funding_template| {
let outputs = vec![TxOut {
value: Amount::from_sat(MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS),
script_pubkey: wallet.get_change_script().unwrap(),
}];
funding_template.splice_out_sync(outputs, &WalletSync::new(wallet, logger.clone()))
},
funding_feerate_sat_per_kw,
);
splice_channel(node, counterparty_node_id, channel_id, &move |funding_template| {
let feerate =
funding_template.min_rbf_feerate().unwrap_or(funding_feerate_sat_per_kw);
let outputs = vec![TxOut {
value: Amount::from_sat(MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS),
script_pubkey: wallet.get_change_script().unwrap(),
}];
funding_template.splice_out_sync(
outputs,
feerate,
FeeRate::MAX,
&WalletSync::new(wallet, logger.clone()),
)
});
};

loop {
Expand Down
35 changes: 19 additions & 16 deletions fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,16 +1032,19 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger + MaybeSend + MaybeSync>
}
let chan_id = chan.channel_id;
let counterparty = chan.counterparty.node_id;
if let Ok(funding_template) = channelmanager.splice_channel(
&chan_id,
&counterparty,
FeeRate::from_sat_per_kwu(253),
FeeRate::MAX,
) {
if let Ok(funding_template) =
channelmanager.splice_channel(&chan_id, &counterparty)
{
let feerate = funding_template
.min_rbf_feerate()
.unwrap_or(FeeRate::from_sat_per_kwu(253));
let wallet_sync = WalletSync::new(&wallet, Arc::clone(&logger));
if let Ok(contribution) = funding_template
.splice_in_sync(Amount::from_sat(splice_in_sats.min(900_000)), &wallet_sync)
{
if let Ok(contribution) = funding_template.splice_in_sync(
Amount::from_sat(splice_in_sats.min(900_000)),
feerate,
FeeRate::MAX,
&wallet_sync,
) {
let _ = channelmanager.funding_contributed(
&chan_id,
&counterparty,
Expand Down Expand Up @@ -1073,19 +1076,19 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger + MaybeSend + MaybeSync>
let splice_out_sats = splice_out_sats.min(max_splice_out).max(546); // At least dust limit
let chan_id = chan.channel_id;
let counterparty = chan.counterparty.node_id;
if let Ok(funding_template) = channelmanager.splice_channel(
&chan_id,
&counterparty,
FeeRate::from_sat_per_kwu(253),
FeeRate::MAX,
) {
if let Ok(funding_template) =
channelmanager.splice_channel(&chan_id, &counterparty)
{
let feerate = funding_template
.min_rbf_feerate()
.unwrap_or(FeeRate::from_sat_per_kwu(253));
let outputs = vec![TxOut {
value: Amount::from_sat(splice_out_sats),
script_pubkey: wallet.get_change_script().unwrap(),
}];
let wallet_sync = WalletSync::new(&wallet, Arc::clone(&logger));
if let Ok(contribution) =
funding_template.splice_out_sync(outputs, &wallet_sync)
funding_template.splice_out_sync(outputs, feerate, FeeRate::MAX, &wallet_sync)
{
let _ = channelmanager.funding_contributed(
&chan_id,
Expand Down
2 changes: 1 addition & 1 deletion lightning-tests/src/upgrade_downgrade_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ fn do_test_0_1_htlc_forward_after_splice(fail_htlc: bool) {
}

let splice_locked = get_event_msg!(nodes[0], MessageSendEvent::SendSpliceLocked, node_b_id);
lock_splice(&nodes[0], &nodes[1], &splice_locked, false);
lock_splice(&nodes[0], &nodes[1], &splice_locked, false, &[]);

for node in nodes.iter() {
connect_blocks(node, EXTRA_BLOCKS_BEFORE_FAIL - ANTI_REORG_DELAY);
Expand Down
13 changes: 10 additions & 3 deletions lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4039,9 +4039,16 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
}

if let Some(parent_funding_txid) = channel_parameters.splice_parent_funding_txid.as_ref() {
// Only one splice can be negotiated at a time after we've exchanged `channel_ready`
// (implying our funding is confirmed) that spends our currently locked funding.
if !self.pending_funding.is_empty() {
// Multiple RBF candidates for the same splice are allowed (they share the same
// parent funding txid). A new splice with a different parent while one is pending
// is not allowed. This also ensures a dual-funded channel has exchanged
// `channel_ready` (implying funding is confirmed) before allowing a splice,
// since unconfirmed initial funding has no splice parent.
let has_different_parent = self.pending_funding.iter().any(|funding| {
funding.channel_parameters.splice_parent_funding_txid.as_ref()
!= Some(parent_funding_txid)
});
if has_different_parent {
log_error!(
logger,
"Negotiated splice while channel is pending channel_ready/splice_locked"
Expand Down
Loading
Loading