Skip to content

Commit 35e1689

Browse files
committed
Test acceptor contributions in dual-funding functional tests
We can now run through the case where the acceptor contributes to an inbound channel, with either more value in inputs, or less value, leading to a different `tx_signatures` exchange order. We also cannot use dummy P2WPKH funding inputs and witnesses anymore as `funding_transaction_signed` internally verifies signatures. Hence, we create external keypairs that we can create outputs for and sign with.
1 parent f97658b commit 35e1689

File tree

3 files changed

+289
-71
lines changed

3 files changed

+289
-71
lines changed

lightning/src/ln/channel.rs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,13 @@ use crate::ln::channelmanager::{
5959
use crate::ln::funding::FundingTxInput;
6060
#[cfg(splicing)]
6161
use crate::ln::funding::SpliceContribution;
62-
#[cfg(splicing)]
63-
use crate::ln::interactivetxs::{
64-
calculate_change_output_value, AbortReason, InteractiveTxMessageSend,
65-
};
6662
use crate::ln::interactivetxs::{
67-
get_output_weight, InteractiveTxConstructor, InteractiveTxConstructorArgs,
68-
InteractiveTxSigningSession, SharedOwnedInput, SharedOwnedOutput, TX_COMMON_FIELDS_WEIGHT,
63+
calculate_change_output_value, get_output_weight, InteractiveTxConstructor,
64+
InteractiveTxConstructorArgs, InteractiveTxSigningSession, SharedOwnedInput, SharedOwnedOutput,
65+
TX_COMMON_FIELDS_WEIGHT,
6966
};
67+
#[cfg(splicing)]
68+
use crate::ln::interactivetxs::{AbortReason, InteractiveTxMessageSend};
7069
use crate::ln::msgs;
7170
use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError, OnionErrorPacket};
7271
use crate::ln::onion_utils::{
@@ -10116,7 +10115,7 @@ where
1011610115
#[rustfmt::skip]
1011710116
pub fn is_awaiting_initial_mon_persist(&self) -> bool {
1011810117
if !self.is_awaiting_monitor_update() { return false; }
10119-
if matches!(
10118+
if self.context.channel_state.is_interactive_signing() || matches!(
1012010119
self.context.channel_state, ChannelState::AwaitingChannelReady(flags)
1012110120
if flags.clone().clear(AwaitingChannelReadyFlags::THEIR_CHANNEL_READY | FundedStateFlags::PEER_DISCONNECTED | FundedStateFlags::MONITOR_UPDATE_IN_PROGRESS | AwaitingChannelReadyFlags::WAITING_FOR_BATCH).is_empty()
1012210121
) {
@@ -13131,6 +13130,30 @@ where
1313113130
})
1313213131
.collect();
1313313132

13133+
// Optionally add change output
13134+
let change_script = signer_provider.get_destination_script(context.channel_keys_id)
13135+
.map_err(|_| ChannelError::close("Error getting change destination script".to_string()))?;
13136+
let change_value_opt = if our_funding_contribution > SignedAmount::ZERO {
13137+
calculate_change_output_value(
13138+
&funding_negotiation_context, false, &shared_funding_output.script_pubkey, context.holder_dust_limit_satoshis).map_err(|_| ChannelError::close("Error calculating change output value".to_string()))? } else {
13139+
None
13140+
};
13141+
let mut our_funding_outputs = vec![];
13142+
if let Some(change_value) = change_value_opt {
13143+
let mut change_output = TxOut {
13144+
value: Amount::from_sat(change_value),
13145+
script_pubkey: change_script,
13146+
};
13147+
let change_output_weight = get_output_weight(&change_output.script_pubkey).to_wu();
13148+
let change_output_fee = fee_for_weight(funding_negotiation_context.funding_feerate_sat_per_1000_weight, change_output_weight);
13149+
let change_value_decreased_with_fee = change_value.saturating_sub(change_output_fee);
13150+
// Check dust limit again
13151+
if change_value_decreased_with_fee > context.holder_dust_limit_satoshis {
13152+
change_output.value = Amount::from_sat(change_value_decreased_with_fee);
13153+
our_funding_outputs.push(change_output);
13154+
}
13155+
}
13156+
1313413157
let interactive_tx_constructor = Some(InteractiveTxConstructor::new(
1313513158
InteractiveTxConstructorArgs {
1313613159
entropy_source,
@@ -13143,7 +13166,7 @@ where
1314313166
inputs_to_contribute,
1314413167
shared_funding_input: None,
1314513168
shared_funding_output: SharedOwnedOutput::new(shared_funding_output, our_funding_contribution_sats),
13146-
outputs_to_contribute: funding_negotiation_context.our_funding_outputs.clone(),
13169+
outputs_to_contribute: our_funding_outputs,
1314713170
}
1314813171
).map_err(|err| {
1314913172
let reason = ClosureReason::ProcessingError { err: err.to_string() };

0 commit comments

Comments
 (0)