Skip to content

Commit c059e03

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 a93ea54 commit c059e03

File tree

4 files changed

+303
-72
lines changed

4 files changed

+303
-72
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::{
@@ -10120,7 +10119,7 @@ where
1012010119
#[rustfmt::skip]
1012110120
pub fn is_awaiting_initial_mon_persist(&self) -> bool {
1012210121
if !self.is_awaiting_monitor_update() { return false; }
10123-
if matches!(
10122+
if self.context.channel_state.is_interactive_signing() || matches!(
1012410123
self.context.channel_state, ChannelState::AwaitingChannelReady(flags)
1012510124
if flags.clone().clear(AwaitingChannelReadyFlags::THEIR_CHANNEL_READY | FundedStateFlags::PEER_DISCONNECTED | FundedStateFlags::MONITOR_UPDATE_IN_PROGRESS | AwaitingChannelReadyFlags::WAITING_FOR_BATCH).is_empty()
1012610125
) {
@@ -13135,6 +13134,30 @@ where
1313513134
})
1313613135
.collect();
1313713136

13137+
// Optionally add change output
13138+
let change_script = signer_provider.get_destination_script(context.channel_keys_id)
13139+
.map_err(|_| ChannelError::close("Error getting change destination script".to_string()))?;
13140+
let change_value_opt = if our_funding_contribution > SignedAmount::ZERO {
13141+
calculate_change_output_value(
13142+
&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 {
13143+
None
13144+
};
13145+
let mut our_funding_outputs = vec![];
13146+
if let Some(change_value) = change_value_opt {
13147+
let mut change_output = TxOut {
13148+
value: Amount::from_sat(change_value),
13149+
script_pubkey: change_script,
13150+
};
13151+
let change_output_weight = get_output_weight(&change_output.script_pubkey).to_wu();
13152+
let change_output_fee = fee_for_weight(funding_negotiation_context.funding_feerate_sat_per_1000_weight, change_output_weight);
13153+
let change_value_decreased_with_fee = change_value.saturating_sub(change_output_fee);
13154+
// Check dust limit again
13155+
if change_value_decreased_with_fee > context.holder_dust_limit_satoshis {
13156+
change_output.value = Amount::from_sat(change_value_decreased_with_fee);
13157+
our_funding_outputs.push(change_output);
13158+
}
13159+
}
13160+
1313813161
let interactive_tx_constructor = Some(InteractiveTxConstructor::new(
1313913162
InteractiveTxConstructorArgs {
1314013163
entropy_source,
@@ -13147,7 +13170,7 @@ where
1314713170
inputs_to_contribute,
1314813171
shared_funding_input: None,
1314913172
shared_funding_output: SharedOwnedOutput::new(shared_funding_output, our_funding_contribution_sats),
13150-
outputs_to_contribute: funding_negotiation_context.our_funding_outputs.clone(),
13173+
outputs_to_contribute: our_funding_outputs,
1315113174
}
1315213175
).map_err(|err| {
1315313176
let reason = ClosureReason::ProcessingError { err: err.to_string() };

0 commit comments

Comments
 (0)