Skip to content

Commit e21a7a5

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 e6e80fc commit e21a7a5

File tree

7 files changed

+308
-282
lines changed

7 files changed

+308
-282
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 124 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,80 +1847,104 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
18471847
0xa0 => {
18481848
let feerate_sat_per_kw = fee_estimators[0].ret_val.load(atomic::Ordering::Acquire);
18491849
let feerate = FeeRate::from_sat_per_kwu(feerate_sat_per_kw as u64);
1850-
match nodes[0].splice_channel(
1851-
&chan_a_id,
1852-
&nodes[1].get_our_node_id(),
1853-
None,
1854-
feerate,
1855-
) {
1850+
match nodes[0].splice_channel(&chan_a_id, &nodes[1].get_our_node_id(), feerate) {
18561851
Ok(funding_template) => {
18571852
let wallet = WalletSync::new(&wallets[0], Arc::clone(&loggers[0]));
1858-
if let Ok(contribution) = funding_template.splice_in_sync(None, Amount::from_sat(10_000), &wallet) {
1859-
let _ = nodes[0].funding_contributed(&chan_a_id, &nodes[1].get_our_node_id(), contribution, None);
1853+
if let Ok(contribution) =
1854+
funding_template.splice_in_sync(Amount::from_sat(10_000), &wallet)
1855+
{
1856+
let _ = nodes[0].funding_contributed(
1857+
&chan_a_id,
1858+
&nodes[1].get_our_node_id(),
1859+
contribution,
1860+
None,
1861+
);
18601862
}
18611863
},
18621864
Err(e) => {
1863-
assert!(matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")), "{:?}", e);
1865+
assert!(
1866+
matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")),
1867+
"{:?}",
1868+
e
1869+
);
18641870
},
18651871
}
18661872
},
18671873
0xa1 => {
18681874
let feerate_sat_per_kw = fee_estimators[1].ret_val.load(atomic::Ordering::Acquire);
18691875
let feerate = FeeRate::from_sat_per_kwu(feerate_sat_per_kw as u64);
1870-
match nodes[1].splice_channel(
1871-
&chan_a_id,
1872-
&nodes[0].get_our_node_id(),
1873-
None,
1874-
feerate,
1875-
) {
1876+
match nodes[1].splice_channel(&chan_a_id, &nodes[0].get_our_node_id(), feerate) {
18761877
Ok(funding_template) => {
18771878
let wallet = WalletSync::new(&wallets[1], Arc::clone(&loggers[1]));
1878-
if let Ok(contribution) = funding_template.splice_in_sync(None, Amount::from_sat(10_000), &wallet) {
1879-
let _ = nodes[1].funding_contributed(&chan_a_id, &nodes[0].get_our_node_id(), contribution, None);
1879+
if let Ok(contribution) =
1880+
funding_template.splice_in_sync(Amount::from_sat(10_000), &wallet)
1881+
{
1882+
let _ = nodes[1].funding_contributed(
1883+
&chan_a_id,
1884+
&nodes[0].get_our_node_id(),
1885+
contribution,
1886+
None,
1887+
);
18801888
}
18811889
},
18821890
Err(e) => {
1883-
assert!(matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")), "{:?}", e);
1891+
assert!(
1892+
matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")),
1893+
"{:?}",
1894+
e
1895+
);
18841896
},
18851897
}
18861898
},
18871899
0xa2 => {
18881900
let feerate_sat_per_kw = fee_estimators[1].ret_val.load(atomic::Ordering::Acquire);
18891901
let feerate = FeeRate::from_sat_per_kwu(feerate_sat_per_kw as u64);
1890-
match nodes[1].splice_channel(
1891-
&chan_b_id,
1892-
&nodes[2].get_our_node_id(),
1893-
None,
1894-
feerate,
1895-
) {
1902+
match nodes[1].splice_channel(&chan_b_id, &nodes[2].get_our_node_id(), feerate) {
18961903
Ok(funding_template) => {
18971904
let wallet = WalletSync::new(&wallets[1], Arc::clone(&loggers[1]));
1898-
if let Ok(contribution) = funding_template.splice_in_sync(None, Amount::from_sat(10_000), &wallet) {
1899-
let _ = nodes[1].funding_contributed(&chan_b_id, &nodes[2].get_our_node_id(), contribution, None);
1905+
if let Ok(contribution) =
1906+
funding_template.splice_in_sync(Amount::from_sat(10_000), &wallet)
1907+
{
1908+
let _ = nodes[1].funding_contributed(
1909+
&chan_b_id,
1910+
&nodes[2].get_our_node_id(),
1911+
contribution,
1912+
None,
1913+
);
19001914
}
19011915
},
19021916
Err(e) => {
1903-
assert!(matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")), "{:?}", e);
1917+
assert!(
1918+
matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")),
1919+
"{:?}",
1920+
e
1921+
);
19041922
},
19051923
}
19061924
},
19071925
0xa3 => {
19081926
let feerate_sat_per_kw = fee_estimators[2].ret_val.load(atomic::Ordering::Acquire);
19091927
let feerate = FeeRate::from_sat_per_kwu(feerate_sat_per_kw as u64);
1910-
match nodes[2].splice_channel(
1911-
&chan_b_id,
1912-
&nodes[1].get_our_node_id(),
1913-
None,
1914-
feerate,
1915-
) {
1928+
match nodes[2].splice_channel(&chan_b_id, &nodes[1].get_our_node_id(), feerate) {
19161929
Ok(funding_template) => {
19171930
let wallet = WalletSync::new(&wallets[2], Arc::clone(&loggers[2]));
1918-
if let Ok(contribution) = funding_template.splice_in_sync(None, Amount::from_sat(10_000), &wallet) {
1919-
let _ = nodes[2].funding_contributed(&chan_b_id, &nodes[1].get_our_node_id(), contribution, None);
1931+
if let Ok(contribution) =
1932+
funding_template.splice_in_sync(Amount::from_sat(10_000), &wallet)
1933+
{
1934+
let _ = nodes[2].funding_contributed(
1935+
&chan_b_id,
1936+
&nodes[1].get_our_node_id(),
1937+
contribution,
1938+
None,
1939+
);
19201940
}
19211941
},
19221942
Err(e) => {
1923-
assert!(matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")), "{:?}", e);
1943+
assert!(
1944+
matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")),
1945+
"{:?}",
1946+
e
1947+
);
19241948
},
19251949
}
19261950
},
@@ -1939,24 +1963,31 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
19391963
let feerate_sat_per_kw =
19401964
fee_estimators[0].ret_val.load(atomic::Ordering::Acquire);
19411965
let feerate = FeeRate::from_sat_per_kwu(feerate_sat_per_kw as u64);
1942-
match nodes[0].splice_channel(
1943-
&chan_a_id,
1944-
&nodes[1].get_our_node_id(),
1945-
None,
1946-
feerate,
1947-
) {
1966+
match nodes[0].splice_channel(&chan_a_id, &nodes[1].get_our_node_id(), feerate)
1967+
{
19481968
Ok(funding_template) => {
19491969
let outputs = vec![TxOut {
19501970
value: Amount::from_sat(MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS),
19511971
script_pubkey: coinbase_tx.output[0].script_pubkey.clone(),
19521972
}];
19531973
let wallet = WalletSync::new(&wallets[0], Arc::clone(&loggers[0]));
1954-
if let Ok(contribution) = funding_template.splice_out_sync(outputs, &wallet) {
1955-
let _ = nodes[0].funding_contributed(&chan_a_id, &nodes[1].get_our_node_id(), contribution, None);
1974+
if let Ok(contribution) =
1975+
funding_template.splice_out_sync(outputs, &wallet)
1976+
{
1977+
let _ = nodes[0].funding_contributed(
1978+
&chan_a_id,
1979+
&nodes[1].get_our_node_id(),
1980+
contribution,
1981+
None,
1982+
);
19561983
}
19571984
},
19581985
Err(e) => {
1959-
assert!(matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")), "{:?}", e);
1986+
assert!(
1987+
matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")),
1988+
"{:?}",
1989+
e
1990+
);
19601991
},
19611992
}
19621993
}
@@ -1972,24 +2003,31 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
19722003
let feerate_sat_per_kw =
19732004
fee_estimators[1].ret_val.load(atomic::Ordering::Acquire);
19742005
let feerate = FeeRate::from_sat_per_kwu(feerate_sat_per_kw as u64);
1975-
match nodes[1].splice_channel(
1976-
&chan_a_id,
1977-
&nodes[0].get_our_node_id(),
1978-
None,
1979-
feerate,
1980-
) {
2006+
match nodes[1].splice_channel(&chan_a_id, &nodes[0].get_our_node_id(), feerate)
2007+
{
19812008
Ok(funding_template) => {
19822009
let outputs = vec![TxOut {
19832010
value: Amount::from_sat(MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS),
19842011
script_pubkey: coinbase_tx.output[1].script_pubkey.clone(),
19852012
}];
19862013
let wallet = WalletSync::new(&wallets[1], Arc::clone(&loggers[1]));
1987-
if let Ok(contribution) = funding_template.splice_out_sync(outputs, &wallet) {
1988-
let _ = nodes[1].funding_contributed(&chan_a_id, &nodes[0].get_our_node_id(), contribution, None);
2014+
if let Ok(contribution) =
2015+
funding_template.splice_out_sync(outputs, &wallet)
2016+
{
2017+
let _ = nodes[1].funding_contributed(
2018+
&chan_a_id,
2019+
&nodes[0].get_our_node_id(),
2020+
contribution,
2021+
None,
2022+
);
19892023
}
19902024
},
19912025
Err(e) => {
1992-
assert!(matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")), "{:?}", e);
2026+
assert!(
2027+
matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")),
2028+
"{:?}",
2029+
e
2030+
);
19932031
},
19942032
}
19952033
}
@@ -2005,24 +2043,31 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
20052043
let feerate_sat_per_kw =
20062044
fee_estimators[1].ret_val.load(atomic::Ordering::Acquire);
20072045
let feerate = FeeRate::from_sat_per_kwu(feerate_sat_per_kw as u64);
2008-
match nodes[1].splice_channel(
2009-
&chan_b_id,
2010-
&nodes[2].get_our_node_id(),
2011-
None,
2012-
feerate,
2013-
) {
2046+
match nodes[1].splice_channel(&chan_b_id, &nodes[2].get_our_node_id(), feerate)
2047+
{
20142048
Ok(funding_template) => {
20152049
let outputs = vec![TxOut {
20162050
value: Amount::from_sat(MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS),
20172051
script_pubkey: coinbase_tx.output[1].script_pubkey.clone(),
20182052
}];
20192053
let wallet = WalletSync::new(&wallets[1], Arc::clone(&loggers[1]));
2020-
if let Ok(contribution) = funding_template.splice_out_sync(outputs, &wallet) {
2021-
let _ = nodes[1].funding_contributed(&chan_b_id, &nodes[2].get_our_node_id(), contribution, None);
2054+
if let Ok(contribution) =
2055+
funding_template.splice_out_sync(outputs, &wallet)
2056+
{
2057+
let _ = nodes[1].funding_contributed(
2058+
&chan_b_id,
2059+
&nodes[2].get_our_node_id(),
2060+
contribution,
2061+
None,
2062+
);
20222063
}
20232064
},
20242065
Err(e) => {
2025-
assert!(matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")), "{:?}", e);
2066+
assert!(
2067+
matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")),
2068+
"{:?}",
2069+
e
2070+
);
20262071
},
20272072
}
20282073
}
@@ -2038,24 +2083,31 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
20382083
let feerate_sat_per_kw =
20392084
fee_estimators[2].ret_val.load(atomic::Ordering::Acquire);
20402085
let feerate = FeeRate::from_sat_per_kwu(feerate_sat_per_kw as u64);
2041-
match nodes[2].splice_channel(
2042-
&chan_b_id,
2043-
&nodes[1].get_our_node_id(),
2044-
None,
2045-
feerate,
2046-
) {
2086+
match nodes[2].splice_channel(&chan_b_id, &nodes[1].get_our_node_id(), feerate)
2087+
{
20472088
Ok(funding_template) => {
20482089
let outputs = vec![TxOut {
20492090
value: Amount::from_sat(MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS),
20502091
script_pubkey: coinbase_tx.output[2].script_pubkey.clone(),
20512092
}];
20522093
let wallet = WalletSync::new(&wallets[2], Arc::clone(&loggers[2]));
2053-
if let Ok(contribution) = funding_template.splice_out_sync(outputs, &wallet) {
2054-
let _ = nodes[2].funding_contributed(&chan_b_id, &nodes[1].get_our_node_id(), contribution, None);
2094+
if let Ok(contribution) =
2095+
funding_template.splice_out_sync(outputs, &wallet)
2096+
{
2097+
let _ = nodes[2].funding_contributed(
2098+
&chan_b_id,
2099+
&nodes[1].get_our_node_id(),
2100+
contribution,
2101+
None,
2102+
);
20552103
}
20562104
},
20572105
Err(e) => {
2058-
assert!(matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")), "{:?}", e);
2106+
assert!(
2107+
matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")),
2108+
"{:?}",
2109+
e
2110+
);
20592111
},
20602112
}
20612113
}

fuzz/src/full_stack.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@ use lightning::chain::{BestBlock, ChannelMonitorUpdateStatus, Confirm, Listen};
4141
use lightning::events::bump_transaction::sync::{WalletSourceSync, WalletSync};
4242
use lightning::events::Event;
4343
use lightning::ln::channel_state::ChannelDetails;
44-
use lightning::ln::channelmanager::{
45-
ChainParameters, ChannelManager, InterceptId, PaymentId,
46-
};
44+
use lightning::ln::channelmanager::{ChainParameters, ChannelManager, InterceptId, PaymentId};
4745
use lightning::ln::functional_test_utils::*;
4846
use lightning::ln::inbound_payment::ExpandedKey;
47+
use lightning::ln::outbound_payment::{RecipientOnionFields, Retry};
4948
use lightning::ln::peer_handler::{
5049
IgnoringMessageHandler, MessageHandler, PeerManager, SocketDescriptor,
5150
};
52-
use lightning::ln::outbound_payment::{RecipientOnionFields, Retry};
5351
use lightning::ln::script::ShutdownScript;
5452
use lightning::ln::types::ChannelId;
5553
use lightning::offers::invoice::UnsignedBolt12Invoice;
@@ -1035,12 +1033,10 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger + MaybeSend + MaybeSync>
10351033
if let Ok(funding_template) = channelmanager.splice_channel(
10361034
&chan_id,
10371035
&counterparty,
1038-
None,
10391036
FeeRate::from_sat_per_kwu(253),
10401037
) {
10411038
let wallet_sync = WalletSync::new(&wallet, Arc::clone(&logger));
10421039
if let Ok(contribution) = funding_template.splice_in_sync(
1043-
None,
10441040
Amount::from_sat(splice_in_sats.min(900_000)),
10451041
&wallet_sync,
10461042
) {
@@ -1078,15 +1074,16 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger + MaybeSend + MaybeSync>
10781074
if let Ok(funding_template) = channelmanager.splice_channel(
10791075
&chan_id,
10801076
&counterparty,
1081-
None,
10821077
FeeRate::from_sat_per_kwu(253),
10831078
) {
10841079
let outputs = vec![TxOut {
10851080
value: Amount::from_sat(splice_out_sats),
10861081
script_pubkey: wallet.get_change_script().unwrap(),
10871082
}];
10881083
let wallet_sync = WalletSync::new(&wallet, Arc::clone(&logger));
1089-
if let Ok(contribution) = funding_template.splice_out_sync(outputs, &wallet_sync) {
1084+
if let Ok(contribution) =
1085+
funding_template.splice_out_sync(outputs, &wallet_sync)
1086+
{
10901087
let _ = channelmanager.funding_contributed(
10911088
&chan_id,
10921089
&counterparty,

lightning-tests/src/upgrade_downgrade_tests.rs

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

0 commit comments

Comments
 (0)