@@ -8254,6 +8254,20 @@ where
8254
8254
self.context.channel_state.clear_monitor_update_in_progress();
8255
8255
assert_eq!(self.blocked_monitor_updates_pending(), 0);
8256
8256
8257
+ // For channels established with V2 establishment we won't send a `tx_signatures` when we're in
8258
+ // MonitorUpdateInProgress (and we assume the user will never directly broadcast the funding
8259
+ // transaction and waits for us to do it).
8260
+ let tx_signatures_ready = self.context.monitor_pending_tx_signatures;
8261
+ self.context.monitor_pending_tx_signatures = false;
8262
+ let tx_signatures = if tx_signatures_ready {
8263
+ if self.context.channel_state.is_their_tx_signatures_sent() {
8264
+ self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
8265
+ } else {
8266
+ self.context.channel_state.set_our_tx_signatures_ready();
8267
+ }
8268
+ self.interactive_tx_signing_session.as_ref().and_then(|session| session.holder_tx_signatures().clone())
8269
+ } else { None };
8270
+
8257
8271
// If we're past (or at) the AwaitingChannelReady stage on an outbound (or V2-established) channel,
8258
8272
// try to (re-)broadcast the funding transaction as we may have declined to broadcast it when we
8259
8273
// first received the funding_signed.
@@ -9714,7 +9728,7 @@ where
9714
9728
#[rustfmt::skip]
9715
9729
pub fn is_awaiting_initial_mon_persist(&self) -> bool {
9716
9730
if !self.is_awaiting_monitor_update() { return false; }
9717
- if matches!(
9731
+ if self.context.channel_state.is_interactive_signing() || matches!(
9718
9732
self.context.channel_state, ChannelState::AwaitingChannelReady(flags)
9719
9733
if flags.clone().clear(AwaitingChannelReadyFlags::THEIR_CHANNEL_READY | FundedStateFlags::PEER_DISCONNECTED | FundedStateFlags::MONITOR_UPDATE_IN_PROGRESS | AwaitingChannelReadyFlags::WAITING_FOR_BATCH).is_empty()
9720
9734
) {
@@ -12615,6 +12629,31 @@ where
12615
12629
script_pubkey: funding.get_funding_redeemscript().to_p2wsh(),
12616
12630
};
12617
12631
12632
+ // Optionally add change output
12633
+ let change_script = signer_provider.get_destination_script(context.channel_keys_id)
12634
+ .map_err(|_| ChannelError::close("Error getting change destination script".to_string()))?;
12635
+ let change_value_opt = calculate_change_output_value(
12636
+ funding.is_outbound(), dual_funding_context.our_funding_satoshis,
12637
+ &our_funding_inputs, None, &shared_funding_output.script_pubkey, &vec![],
12638
+ dual_funding_context.funding_feerate_sat_per_1000_weight,
12639
+ change_script.minimal_non_dust().to_sat(),
12640
+ ).map_err(|_| ChannelError::close("Error calculating change output value".to_string()))?;
12641
+ let mut our_funding_outputs = vec![];
12642
+ if let Some(change_value) = change_value_opt {
12643
+ let mut change_output = TxOut {
12644
+ value: Amount::from_sat(change_value),
12645
+ script_pubkey: change_script,
12646
+ };
12647
+ let change_output_weight = get_output_weight(&change_output.script_pubkey).to_wu();
12648
+ let change_output_fee = fee_for_weight(dual_funding_context.funding_feerate_sat_per_1000_weight, change_output_weight);
12649
+ let change_value_decreased_with_fee = change_value.saturating_sub(change_output_fee);
12650
+ // Check dust limit again
12651
+ if change_value_decreased_with_fee > context.holder_dust_limit_satoshis {
12652
+ change_output.value = Amount::from_sat(change_value_decreased_with_fee);
12653
+ our_funding_outputs.push(change_output);
12654
+ }
12655
+ }
12656
+
12618
12657
let interactive_tx_constructor = Some(InteractiveTxConstructor::new(
12619
12658
InteractiveTxConstructorArgs {
12620
12659
entropy_source,
@@ -12627,7 +12666,7 @@ where
12627
12666
inputs_to_contribute: our_funding_inputs,
12628
12667
shared_funding_input: None,
12629
12668
shared_funding_output: SharedOwnedOutput::new(shared_funding_output, our_funding_satoshis),
12630
- outputs_to_contribute: Vec::new() ,
12669
+ outputs_to_contribute: our_funding_outputs ,
12631
12670
}
12632
12671
).map_err(|err| {
12633
12672
let reason = ClosureReason::ProcessingError { err: err.to_string() };
0 commit comments