Skip to content

Commit fe940d6

Browse files
dunxenjkczyz
authored andcommitted
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 f9a51e8 commit fe940d6

File tree

4 files changed

+489
-7
lines changed

4 files changed

+489
-7
lines changed

lightning/src/ln/channel.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6314,6 +6314,19 @@ where
63146314
}
63156315
}
63166316

6317+
#[cfg(all(test))]
6318+
pub fn get_initial_counterparty_commitment_signatures_for_test<L: Deref>(
6319+
&mut self, funding: &mut FundingScope, logger: &L,
6320+
counterparty_next_commitment_point_override: PublicKey,
6321+
) -> Option<(Signature, Vec<Signature>)>
6322+
where
6323+
SP::Target: SignerProvider,
6324+
L::Target: Logger,
6325+
{
6326+
self.counterparty_next_commitment_point = Some(counterparty_next_commitment_point_override);
6327+
self.get_initial_counterparty_commitment_signatures(funding, logger)
6328+
}
6329+
63176330
fn check_funding_meets_minimum_depth(&self, funding: &FundingScope, height: u32) -> bool {
63186331
let minimum_depth = self
63196332
.minimum_depth(funding)
@@ -10955,7 +10968,7 @@ where
1095510968
#[rustfmt::skip]
1095610969
pub fn is_awaiting_initial_mon_persist(&self) -> bool {
1095710970
if !self.is_awaiting_monitor_update() { return false; }
10958-
if matches!(
10971+
if self.context.interactive_tx_signing_session.is_some() || matches!(
1095910972
self.context.channel_state, ChannelState::AwaitingChannelReady(flags)
1096010973
if flags.clone().clear(AwaitingChannelReadyFlags::THEIR_CHANNEL_READY | FundedStateFlags::PEER_DISCONNECTED | FundedStateFlags::MONITOR_UPDATE_IN_PROGRESS | AwaitingChannelReadyFlags::WAITING_FOR_BATCH).is_empty()
1096110974
) {
@@ -14176,6 +14189,30 @@ where
1417614189
script_pubkey: funding.get_funding_redeemscript().to_p2wsh(),
1417714190
};
1417814191

14192+
// Optionally add change output
14193+
let change_script = signer_provider.get_destination_script(context.channel_keys_id)
14194+
.map_err(|_| ChannelError::close("Error getting change destination script".to_string()))?;
14195+
let change_value_opt = if our_funding_contribution > SignedAmount::ZERO {
14196+
calculate_change_output_value(
14197+
&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 {
14198+
None
14199+
};
14200+
let mut our_funding_outputs = vec![];
14201+
if let Some(change_value) = change_value_opt {
14202+
let mut change_output = TxOut {
14203+
value: Amount::from_sat(change_value),
14204+
script_pubkey: change_script,
14205+
};
14206+
let change_output_weight = get_output_weight(&change_output.script_pubkey).to_wu();
14207+
let change_output_fee = fee_for_weight(funding_negotiation_context.funding_feerate_sat_per_1000_weight, change_output_weight);
14208+
let change_value_decreased_with_fee = change_value.saturating_sub(change_output_fee);
14209+
// Check dust limit again
14210+
if change_value_decreased_with_fee > context.holder_dust_limit_satoshis {
14211+
change_output.value = Amount::from_sat(change_value_decreased_with_fee);
14212+
our_funding_outputs.push(change_output);
14213+
}
14214+
}
14215+
1417914216
let interactive_tx_constructor = Some(InteractiveTxConstructor::new(
1418014217
InteractiveTxConstructorArgs {
1418114218
entropy_source,
@@ -14188,7 +14225,7 @@ where
1418814225
inputs_to_contribute: our_funding_inputs,
1418914226
shared_funding_input: None,
1419014227
shared_funding_output: SharedOwnedOutput::new(shared_funding_output, our_funding_contribution_sats),
14191-
outputs_to_contribute: funding_negotiation_context.our_funding_outputs.clone(),
14228+
outputs_to_contribute: our_funding_outputs,
1419214229
}
1419314230
).map_err(|err| {
1419414231
let reason = ClosureReason::ProcessingError { err: err.reason.to_string() };

0 commit comments

Comments
 (0)