@@ -7411,6 +7411,18 @@ where
7411
7411
assert!(self.context.channel_state.is_monitor_update_in_progress());
7412
7412
self.context.channel_state.clear_monitor_update_in_progress();
7413
7413
7414
+ // For channels established with V2 establishment we won't send a `tx_signatures` when we're in
7415
+ // MonitorUpdateInProgress (and we assume the user will never directly broadcast the funding
7416
+ // transaction and waits for us to do it).
7417
+ let tx_signatures = self.context.monitor_pending_tx_signatures.take();
7418
+ if tx_signatures.is_some() {
7419
+ if self.context.channel_state.is_their_tx_signatures_sent() {
7420
+ self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
7421
+ } else {
7422
+ self.context.channel_state.set_our_tx_signatures_ready();
7423
+ }
7424
+ }
7425
+
7414
7426
// If we're past (or at) the AwaitingChannelReady stage on an outbound (or V2-established) channel,
7415
7427
// try to (re-)broadcast the funding transaction as we may have declined to broadcast it when we
7416
7428
// first received the funding_signed.
@@ -7450,17 +7462,6 @@ where
7450
7462
mem::swap(&mut finalized_claimed_htlcs, &mut self.context.monitor_pending_finalized_fulfills);
7451
7463
let mut pending_update_adds = Vec::new();
7452
7464
mem::swap(&mut pending_update_adds, &mut self.context.monitor_pending_update_adds);
7453
- // For channels established with V2 establishment we won't send a `tx_signatures` when we're in
7454
- // MonitorUpdateInProgress (and we assume the user will never directly broadcast the funding
7455
- // transaction and waits for us to do it).
7456
- let tx_signatures = self.context.monitor_pending_tx_signatures.take();
7457
- if tx_signatures.is_some() {
7458
- if self.context.channel_state.is_their_tx_signatures_sent() {
7459
- self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
7460
- } else {
7461
- self.context.channel_state.set_our_tx_signatures_ready();
7462
- }
7463
- }
7464
7465
7465
7466
if self.context.channel_state.is_peer_disconnected() {
7466
7467
self.context.monitor_pending_revoke_and_ack = false;
@@ -8749,7 +8750,7 @@ where
8749
8750
#[rustfmt::skip]
8750
8751
pub fn is_awaiting_initial_mon_persist(&self) -> bool {
8751
8752
if !self.is_awaiting_monitor_update() { return false; }
8752
- if matches!(
8753
+ if self.context.channel_state.is_interactive_signing() || matches!(
8753
8754
self.context.channel_state, ChannelState::AwaitingChannelReady(flags)
8754
8755
if flags.clone().clear(AwaitingChannelReadyFlags::THEIR_CHANNEL_READY | FundedStateFlags::PEER_DISCONNECTED | FundedStateFlags::MONITOR_UPDATE_IN_PROGRESS | AwaitingChannelReadyFlags::WAITING_FOR_BATCH).is_empty()
8755
8756
) {
@@ -11110,6 +11111,31 @@ where
11110
11111
script_pubkey: funding.get_funding_redeemscript().to_p2wsh(),
11111
11112
};
11112
11113
11114
+ // Optionally add change output
11115
+ let change_script = signer_provider.get_destination_script(context.channel_keys_id)
11116
+ .map_err(|_| ChannelError::close("Error getting change destination script".to_string()))?;
11117
+ let change_value_opt = calculate_change_output_value(
11118
+ funding.is_outbound(), dual_funding_context.our_funding_satoshis,
11119
+ &our_funding_inputs, None, &shared_funding_output.script_pubkey, &vec![],
11120
+ dual_funding_context.funding_feerate_sat_per_1000_weight,
11121
+ change_script.minimal_non_dust().to_sat(),
11122
+ ).map_err(|_| ChannelError::close("Error calculating change output value".to_string()))?;
11123
+ let mut our_funding_outputs = vec![];
11124
+ if let Some(change_value) = change_value_opt {
11125
+ let mut change_output = TxOut {
11126
+ value: Amount::from_sat(change_value),
11127
+ script_pubkey: change_script,
11128
+ };
11129
+ let change_output_weight = get_output_weight(&change_output.script_pubkey).to_wu();
11130
+ let change_output_fee = fee_for_weight(dual_funding_context.funding_feerate_sat_per_1000_weight, change_output_weight);
11131
+ let change_value_decreased_with_fee = change_value.saturating_sub(change_output_fee);
11132
+ // Check dust limit again
11133
+ if change_value_decreased_with_fee > context.holder_dust_limit_satoshis {
11134
+ change_output.value = Amount::from_sat(change_value_decreased_with_fee);
11135
+ our_funding_outputs.push(change_output);
11136
+ }
11137
+ }
11138
+
11113
11139
let interactive_tx_constructor = Some(InteractiveTxConstructor::new(
11114
11140
InteractiveTxConstructorArgs {
11115
11141
entropy_source,
@@ -11122,7 +11148,7 @@ where
11122
11148
inputs_to_contribute: our_funding_inputs,
11123
11149
shared_funding_input: None,
11124
11150
shared_funding_output: (shared_funding_output, our_funding_satoshis),
11125
- outputs_to_contribute: Vec::new() ,
11151
+ outputs_to_contribute: our_funding_outputs ,
11126
11152
}
11127
11153
).map_err(|_| ChannelError::Close((
11128
11154
"V2 channel rejected due to sender error".into(),
0 commit comments