Skip to content

Commit 21cb883

Browse files
committed
Use CoinSelection::change_output when splicing
Now that CoinSelection is used to fund a splice funding transaction, use that for determining of a change output should be used. Previously, the initiator could either provide a change script upfront or let LDK generate one using SignerProvider::get_destination_script. Since older versions may have serialized a SpliceInstruction without a change script while waiting on quiescence, LDK must still generate a change output in this case.
1 parent 2fc1fdb commit 21cb883

File tree

7 files changed

+306
-278
lines changed

7 files changed

+306
-278
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 124 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,80 +2079,104 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
20792079
0xa0 => {
20802080
let feerate_sat_per_kw = fee_estimators[0].ret_val.load(atomic::Ordering::Acquire);
20812081
let feerate = FeeRate::from_sat_per_kwu(feerate_sat_per_kw as u64);
2082-
match nodes[0].splice_channel(
2083-
&chan_a_id,
2084-
&nodes[1].get_our_node_id(),
2085-
None,
2086-
feerate,
2087-
) {
2082+
match nodes[0].splice_channel(&chan_a_id, &nodes[1].get_our_node_id(), feerate) {
20882083
Ok(funding_template) => {
20892084
let wallet = WalletSync::new(&wallets[0], Arc::clone(&loggers[0]));
2090-
if let Ok(contribution) = funding_template.splice_in_sync(None, Amount::from_sat(10_000), &wallet) {
2091-
let _ = nodes[0].funding_contributed(&chan_a_id, &nodes[1].get_our_node_id(), contribution, None);
2085+
if let Ok(contribution) =
2086+
funding_template.splice_in_sync(Amount::from_sat(10_000), &wallet)
2087+
{
2088+
let _ = nodes[0].funding_contributed(
2089+
&chan_a_id,
2090+
&nodes[1].get_our_node_id(),
2091+
contribution,
2092+
None,
2093+
);
20922094
}
20932095
},
20942096
Err(e) => {
2095-
assert!(matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")), "{:?}", e);
2097+
assert!(
2098+
matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")),
2099+
"{:?}",
2100+
e
2101+
);
20962102
},
20972103
}
20982104
},
20992105
0xa1 => {
21002106
let feerate_sat_per_kw = fee_estimators[1].ret_val.load(atomic::Ordering::Acquire);
21012107
let feerate = FeeRate::from_sat_per_kwu(feerate_sat_per_kw as u64);
2102-
match nodes[1].splice_channel(
2103-
&chan_a_id,
2104-
&nodes[0].get_our_node_id(),
2105-
None,
2106-
feerate,
2107-
) {
2108+
match nodes[1].splice_channel(&chan_a_id, &nodes[0].get_our_node_id(), feerate) {
21082109
Ok(funding_template) => {
21092110
let wallet = WalletSync::new(&wallets[1], Arc::clone(&loggers[1]));
2110-
if let Ok(contribution) = funding_template.splice_in_sync(None, Amount::from_sat(10_000), &wallet) {
2111-
let _ = nodes[1].funding_contributed(&chan_a_id, &nodes[0].get_our_node_id(), contribution, None);
2111+
if let Ok(contribution) =
2112+
funding_template.splice_in_sync(Amount::from_sat(10_000), &wallet)
2113+
{
2114+
let _ = nodes[1].funding_contributed(
2115+
&chan_a_id,
2116+
&nodes[0].get_our_node_id(),
2117+
contribution,
2118+
None,
2119+
);
21122120
}
21132121
},
21142122
Err(e) => {
2115-
assert!(matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")), "{:?}", e);
2123+
assert!(
2124+
matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")),
2125+
"{:?}",
2126+
e
2127+
);
21162128
},
21172129
}
21182130
},
21192131
0xa2 => {
21202132
let feerate_sat_per_kw = fee_estimators[1].ret_val.load(atomic::Ordering::Acquire);
21212133
let feerate = FeeRate::from_sat_per_kwu(feerate_sat_per_kw as u64);
2122-
match nodes[1].splice_channel(
2123-
&chan_b_id,
2124-
&nodes[2].get_our_node_id(),
2125-
None,
2126-
feerate,
2127-
) {
2134+
match nodes[1].splice_channel(&chan_b_id, &nodes[2].get_our_node_id(), feerate) {
21282135
Ok(funding_template) => {
21292136
let wallet = WalletSync::new(&wallets[1], Arc::clone(&loggers[1]));
2130-
if let Ok(contribution) = funding_template.splice_in_sync(None, Amount::from_sat(10_000), &wallet) {
2131-
let _ = nodes[1].funding_contributed(&chan_b_id, &nodes[2].get_our_node_id(), contribution, None);
2137+
if let Ok(contribution) =
2138+
funding_template.splice_in_sync(Amount::from_sat(10_000), &wallet)
2139+
{
2140+
let _ = nodes[1].funding_contributed(
2141+
&chan_b_id,
2142+
&nodes[2].get_our_node_id(),
2143+
contribution,
2144+
None,
2145+
);
21322146
}
21332147
},
21342148
Err(e) => {
2135-
assert!(matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")), "{:?}", e);
2149+
assert!(
2150+
matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")),
2151+
"{:?}",
2152+
e
2153+
);
21362154
},
21372155
}
21382156
},
21392157
0xa3 => {
21402158
let feerate_sat_per_kw = fee_estimators[2].ret_val.load(atomic::Ordering::Acquire);
21412159
let feerate = FeeRate::from_sat_per_kwu(feerate_sat_per_kw as u64);
2142-
match nodes[2].splice_channel(
2143-
&chan_b_id,
2144-
&nodes[1].get_our_node_id(),
2145-
None,
2146-
feerate,
2147-
) {
2160+
match nodes[2].splice_channel(&chan_b_id, &nodes[1].get_our_node_id(), feerate) {
21482161
Ok(funding_template) => {
21492162
let wallet = WalletSync::new(&wallets[2], Arc::clone(&loggers[2]));
2150-
if let Ok(contribution) = funding_template.splice_in_sync(None, Amount::from_sat(10_000), &wallet) {
2151-
let _ = nodes[2].funding_contributed(&chan_b_id, &nodes[1].get_our_node_id(), contribution, None);
2163+
if let Ok(contribution) =
2164+
funding_template.splice_in_sync(Amount::from_sat(10_000), &wallet)
2165+
{
2166+
let _ = nodes[2].funding_contributed(
2167+
&chan_b_id,
2168+
&nodes[1].get_our_node_id(),
2169+
contribution,
2170+
None,
2171+
);
21522172
}
21532173
},
21542174
Err(e) => {
2155-
assert!(matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")), "{:?}", e);
2175+
assert!(
2176+
matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")),
2177+
"{:?}",
2178+
e
2179+
);
21562180
},
21572181
}
21582182
},
@@ -2171,24 +2195,31 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
21712195
let feerate_sat_per_kw =
21722196
fee_estimators[0].ret_val.load(atomic::Ordering::Acquire);
21732197
let feerate = FeeRate::from_sat_per_kwu(feerate_sat_per_kw as u64);
2174-
match nodes[0].splice_channel(
2175-
&chan_a_id,
2176-
&nodes[1].get_our_node_id(),
2177-
None,
2178-
feerate,
2179-
) {
2198+
match nodes[0].splice_channel(&chan_a_id, &nodes[1].get_our_node_id(), feerate)
2199+
{
21802200
Ok(funding_template) => {
21812201
let outputs = vec![TxOut {
21822202
value: Amount::from_sat(MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS),
21832203
script_pubkey: coinbase_tx.output[0].script_pubkey.clone(),
21842204
}];
21852205
let wallet = WalletSync::new(&wallets[0], Arc::clone(&loggers[0]));
2186-
if let Ok(contribution) = funding_template.splice_out_sync(outputs, &wallet) {
2187-
let _ = nodes[0].funding_contributed(&chan_a_id, &nodes[1].get_our_node_id(), contribution, None);
2206+
if let Ok(contribution) =
2207+
funding_template.splice_out_sync(outputs, &wallet)
2208+
{
2209+
let _ = nodes[0].funding_contributed(
2210+
&chan_a_id,
2211+
&nodes[1].get_our_node_id(),
2212+
contribution,
2213+
None,
2214+
);
21882215
}
21892216
},
21902217
Err(e) => {
2191-
assert!(matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")), "{:?}", e);
2218+
assert!(
2219+
matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")),
2220+
"{:?}",
2221+
e
2222+
);
21922223
},
21932224
}
21942225
}
@@ -2204,24 +2235,31 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
22042235
let feerate_sat_per_kw =
22052236
fee_estimators[1].ret_val.load(atomic::Ordering::Acquire);
22062237
let feerate = FeeRate::from_sat_per_kwu(feerate_sat_per_kw as u64);
2207-
match nodes[1].splice_channel(
2208-
&chan_a_id,
2209-
&nodes[0].get_our_node_id(),
2210-
None,
2211-
feerate,
2212-
) {
2238+
match nodes[1].splice_channel(&chan_a_id, &nodes[0].get_our_node_id(), feerate)
2239+
{
22132240
Ok(funding_template) => {
22142241
let outputs = vec![TxOut {
22152242
value: Amount::from_sat(MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS),
22162243
script_pubkey: coinbase_tx.output[1].script_pubkey.clone(),
22172244
}];
22182245
let wallet = WalletSync::new(&wallets[1], Arc::clone(&loggers[1]));
2219-
if let Ok(contribution) = funding_template.splice_out_sync(outputs, &wallet) {
2220-
let _ = nodes[1].funding_contributed(&chan_a_id, &nodes[0].get_our_node_id(), contribution, None);
2246+
if let Ok(contribution) =
2247+
funding_template.splice_out_sync(outputs, &wallet)
2248+
{
2249+
let _ = nodes[1].funding_contributed(
2250+
&chan_a_id,
2251+
&nodes[0].get_our_node_id(),
2252+
contribution,
2253+
None,
2254+
);
22212255
}
22222256
},
22232257
Err(e) => {
2224-
assert!(matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")), "{:?}", e);
2258+
assert!(
2259+
matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")),
2260+
"{:?}",
2261+
e
2262+
);
22252263
},
22262264
}
22272265
}
@@ -2237,24 +2275,31 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
22372275
let feerate_sat_per_kw =
22382276
fee_estimators[1].ret_val.load(atomic::Ordering::Acquire);
22392277
let feerate = FeeRate::from_sat_per_kwu(feerate_sat_per_kw as u64);
2240-
match nodes[1].splice_channel(
2241-
&chan_b_id,
2242-
&nodes[2].get_our_node_id(),
2243-
None,
2244-
feerate,
2245-
) {
2278+
match nodes[1].splice_channel(&chan_b_id, &nodes[2].get_our_node_id(), feerate)
2279+
{
22462280
Ok(funding_template) => {
22472281
let outputs = vec![TxOut {
22482282
value: Amount::from_sat(MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS),
22492283
script_pubkey: coinbase_tx.output[1].script_pubkey.clone(),
22502284
}];
22512285
let wallet = WalletSync::new(&wallets[1], Arc::clone(&loggers[1]));
2252-
if let Ok(contribution) = funding_template.splice_out_sync(outputs, &wallet) {
2253-
let _ = nodes[1].funding_contributed(&chan_b_id, &nodes[2].get_our_node_id(), contribution, None);
2286+
if let Ok(contribution) =
2287+
funding_template.splice_out_sync(outputs, &wallet)
2288+
{
2289+
let _ = nodes[1].funding_contributed(
2290+
&chan_b_id,
2291+
&nodes[2].get_our_node_id(),
2292+
contribution,
2293+
None,
2294+
);
22542295
}
22552296
},
22562297
Err(e) => {
2257-
assert!(matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")), "{:?}", e);
2298+
assert!(
2299+
matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")),
2300+
"{:?}",
2301+
e
2302+
);
22582303
},
22592304
}
22602305
}
@@ -2270,24 +2315,31 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
22702315
let feerate_sat_per_kw =
22712316
fee_estimators[2].ret_val.load(atomic::Ordering::Acquire);
22722317
let feerate = FeeRate::from_sat_per_kwu(feerate_sat_per_kw as u64);
2273-
match nodes[2].splice_channel(
2274-
&chan_b_id,
2275-
&nodes[1].get_our_node_id(),
2276-
None,
2277-
feerate,
2278-
) {
2318+
match nodes[2].splice_channel(&chan_b_id, &nodes[1].get_our_node_id(), feerate)
2319+
{
22792320
Ok(funding_template) => {
22802321
let outputs = vec![TxOut {
22812322
value: Amount::from_sat(MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS),
22822323
script_pubkey: coinbase_tx.output[2].script_pubkey.clone(),
22832324
}];
22842325
let wallet = WalletSync::new(&wallets[2], Arc::clone(&loggers[2]));
2285-
if let Ok(contribution) = funding_template.splice_out_sync(outputs, &wallet) {
2286-
let _ = nodes[2].funding_contributed(&chan_b_id, &nodes[1].get_our_node_id(), contribution, None);
2326+
if let Ok(contribution) =
2327+
funding_template.splice_out_sync(outputs, &wallet)
2328+
{
2329+
let _ = nodes[2].funding_contributed(
2330+
&chan_b_id,
2331+
&nodes[1].get_our_node_id(),
2332+
contribution,
2333+
None,
2334+
);
22872335
}
22882336
},
22892337
Err(e) => {
2290-
assert!(matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")), "{:?}", e);
2338+
assert!(
2339+
matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")),
2340+
"{:?}",
2341+
e
2342+
);
22912343
},
22922344
}
22932345
}

fuzz/src/full_stack.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,12 +1035,10 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger + MaybeSend + MaybeSync>
10351035
if let Ok(funding_template) = channelmanager.splice_channel(
10361036
&chan_id,
10371037
&counterparty,
1038-
None,
10391038
FeeRate::from_sat_per_kwu(253),
10401039
) {
10411040
let wallet_sync = WalletSync::new(&wallet, Arc::clone(&logger));
10421041
if let Ok(contribution) = funding_template.splice_in_sync(
1043-
None,
10441042
Amount::from_sat(splice_in_sats.min(900_000)),
10451043
&wallet_sync,
10461044
) {
@@ -1078,15 +1076,16 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger + MaybeSend + MaybeSync>
10781076
if let Ok(funding_template) = channelmanager.splice_channel(
10791077
&chan_id,
10801078
&counterparty,
1081-
None,
10821079
FeeRate::from_sat_per_kwu(253),
10831080
) {
10841081
let outputs = vec![TxOut {
10851082
value: Amount::from_sat(splice_out_sats),
10861083
script_pubkey: wallet.get_change_script().unwrap(),
10871084
}];
10881085
let wallet_sync = WalletSync::new(&wallet, Arc::clone(&logger));
1089-
if let Ok(contribution) = funding_template.splice_out_sync(outputs, &wallet_sync) {
1086+
if let Ok(contribution) =
1087+
funding_template.splice_out_sync(outputs, &wallet_sync)
1088+
{
10901089
let _ = channelmanager.funding_contributed(
10911090
&chan_id,
10921091
&counterparty,

lightning-tests/src/upgrade_downgrade_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ fn do_test_0_1_htlc_forward_after_splice(fail_htlc: bool) {
458458
}];
459459
let channel_id = ChannelId(chan_id_bytes_a);
460460
let funding_contribution = initiate_splice_out(&nodes[0], &nodes[1], channel_id, outputs);
461-
let splice_tx = splice_channel(&nodes[0], &nodes[1], channel_id, funding_contribution);
461+
let (splice_tx, _) = splice_channel(&nodes[0], &nodes[1], channel_id, funding_contribution);
462462
for node in nodes.iter() {
463463
mine_transaction(node, &splice_tx);
464464
connect_blocks(node, ANTI_REORG_DELAY - 1);

0 commit comments

Comments
 (0)