@@ -7422,6 +7422,18 @@ where
7422
7422
assert!(self.context.channel_state.is_monitor_update_in_progress());
7423
7423
self.context.channel_state.clear_monitor_update_in_progress();
7424
7424
7425
+ // For channels established with V2 establishment we won't send a `tx_signatures` when we're in
7426
+ // MonitorUpdateInProgress (and we assume the user will never directly broadcast the funding
7427
+ // transaction and waits for us to do it).
7428
+ let tx_signatures = self.context.monitor_pending_tx_signatures.take();
7429
+ if tx_signatures.is_some() {
7430
+ if self.context.channel_state.is_their_tx_signatures_sent() {
7431
+ self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
7432
+ } else {
7433
+ self.context.channel_state.set_our_tx_signatures_ready();
7434
+ }
7435
+ }
7436
+
7425
7437
// If we're past (or at) the AwaitingChannelReady stage on an outbound (or V2-established) channel,
7426
7438
// try to (re-)broadcast the funding transaction as we may have declined to broadcast it when we
7427
7439
// first received the funding_signed.
@@ -7461,17 +7473,6 @@ where
7461
7473
mem::swap(&mut finalized_claimed_htlcs, &mut self.context.monitor_pending_finalized_fulfills);
7462
7474
let mut pending_update_adds = Vec::new();
7463
7475
mem::swap(&mut pending_update_adds, &mut self.context.monitor_pending_update_adds);
7464
- // For channels established with V2 establishment we won't send a `tx_signatures` when we're in
7465
- // MonitorUpdateInProgress (and we assume the user will never directly broadcast the funding
7466
- // transaction and waits for us to do it).
7467
- let tx_signatures = self.context.monitor_pending_tx_signatures.take();
7468
- if tx_signatures.is_some() {
7469
- if self.context.channel_state.is_their_tx_signatures_sent() {
7470
- self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
7471
- } else {
7472
- self.context.channel_state.set_our_tx_signatures_ready();
7473
- }
7474
- }
7475
7476
7476
7477
if self.context.channel_state.is_peer_disconnected() {
7477
7478
self.context.monitor_pending_revoke_and_ack = false;
@@ -8760,7 +8761,7 @@ where
8760
8761
#[rustfmt::skip]
8761
8762
pub fn is_awaiting_initial_mon_persist(&self) -> bool {
8762
8763
if !self.is_awaiting_monitor_update() { return false; }
8763
- if matches!(
8764
+ if self.context.channel_state.is_interactive_signing() || matches!(
8764
8765
self.context.channel_state, ChannelState::AwaitingChannelReady(flags)
8765
8766
if flags.clone().clear(AwaitingChannelReadyFlags::THEIR_CHANNEL_READY | FundedStateFlags::PEER_DISCONNECTED | FundedStateFlags::MONITOR_UPDATE_IN_PROGRESS | AwaitingChannelReadyFlags::WAITING_FOR_BATCH).is_empty()
8766
8767
) {
@@ -11117,6 +11118,31 @@ where
11117
11118
our_funding_inputs: our_funding_inputs.clone(),
11118
11119
};
11119
11120
11121
+ // Optionally add change output
11122
+ let change_script = signer_provider.get_destination_script(context.channel_keys_id)
11123
+ .map_err(|_| ChannelError::close("Error getting change destination script".to_string()))?;
11124
+ let change_value_opt = calculate_change_output_value(
11125
+ funding.is_outbound(), dual_funding_context.our_funding_satoshis,
11126
+ &our_funding_inputs, &vec![],
11127
+ dual_funding_context.funding_feerate_sat_per_1000_weight,
11128
+ change_script.minimal_non_dust().to_sat(),
11129
+ ).map_err(|_| ChannelError::close("Error calculating change output value".to_string()))?;
11130
+ let mut our_funding_outputs = vec![];
11131
+ if let Some(change_value) = change_value_opt {
11132
+ let mut change_output = TxOut {
11133
+ value: Amount::from_sat(change_value),
11134
+ script_pubkey: change_script,
11135
+ };
11136
+ let change_output_weight = get_output_weight(&change_output.script_pubkey).to_wu();
11137
+ let change_output_fee = fee_for_weight(dual_funding_context.funding_feerate_sat_per_1000_weight, change_output_weight);
11138
+ let change_value_decreased_with_fee = change_value.saturating_sub(change_output_fee);
11139
+ // Check dust limit again
11140
+ if change_value_decreased_with_fee > context.holder_dust_limit_satoshis {
11141
+ change_output.value = Amount::from_sat(change_value_decreased_with_fee);
11142
+ our_funding_outputs.push(OutputOwned::Single(change_output));
11143
+ }
11144
+ }
11145
+
11120
11146
let interactive_tx_constructor = Some(InteractiveTxConstructor::new(
11121
11147
InteractiveTxConstructorArgs {
11122
11148
entropy_source,
@@ -11127,7 +11153,7 @@ where
11127
11153
funding_tx_locktime: dual_funding_context.funding_tx_locktime,
11128
11154
is_initiator: false,
11129
11155
inputs_to_contribute: our_funding_inputs,
11130
- outputs_to_contribute: Vec::new() ,
11156
+ outputs_to_contribute: our_funding_outputs ,
11131
11157
expected_remote_shared_funding_output: Some((funding.get_funding_redeemscript().to_p2wsh(), funding.get_value_satoshis())),
11132
11158
}
11133
11159
).map_err(|_| ChannelError::Close((
0 commit comments