Skip to content
Open
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
91 changes: 46 additions & 45 deletions fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use lightning::ln::channelmanager::{
ChainParameters, ChannelManager, ChannelManagerReadArgs, PaymentId, RecentPaymentDetails,
};
use lightning::ln::functional_test_utils::*;
use lightning::ln::funding::{FundingContribution, FundingTemplate};
use lightning::ln::funding::{FundingContribution, FundingContributionError, FundingTemplate};
use lightning::ln::inbound_payment::ExpandedKey;
use lightning::ln::msgs::{
self, BaseMessageHandler, ChannelMessageHandler, CommitmentUpdate, Init, MessageSendEvent,
Expand Down Expand Up @@ -1388,36 +1388,31 @@ 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,
) {
Ok(funding_template) => {
if let Ok(contribution) = f(funding_template) {
let _ = node.funding_contributed(
channel_id,
counterparty_node_id,
contribution,
None,
let splice_channel =
|node: &ChanMan,
counterparty_node_id: &PublicKey,
channel_id: &ChannelId,
f: &dyn Fn(FundingTemplate) -> Result<FundingContribution, FundingContributionError>| {
match node.splice_channel(channel_id, counterparty_node_id) {
Ok(funding_template) => {
if let Ok(contribution) = f(funding_template) {
let _ = node.funding_contributed(
channel_id,
counterparty_node_id,
contribution,
None,
);
}
},
Err(e) => {
assert!(
matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")),
"{:?}",
e
);
}
},
Err(e) => {
assert!(
matches!(e, APIError::APIMisuseError { ref err } if err.contains("splice")),
"{:?}",
e
);
},
}
};
},
}
};

let splice_in =
|node: &ChanMan,
Expand All @@ -1430,9 +1425,15 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
counterparty_node_id,
channel_id,
&move |funding_template: FundingTemplate| {
funding_template.splice_in_sync(Amount::from_sat(10_000), wallet)
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,
)
},
funding_feerate_sat_per_kw,
);
};

Expand All @@ -1454,19 +1455,19 @@ 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
40 changes: 22 additions & 18 deletions fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,16 +1032,18 @@ 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,20 +1075,22 @@ 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)
{
if let Ok(contribution) = funding_template.splice_out_sync(
outputs,
feerate,
FeeRate::MAX,
&wallet_sync,
) {
let _ = channelmanager.funding_contributed(
&chan_id,
&counterparty,
Expand Down
Loading
Loading