@@ -59,14 +59,13 @@ use crate::ln::channelmanager::{
59
59
use crate::ln::funding::FundingTxInput;
60
60
#[cfg(splicing)]
61
61
use crate::ln::funding::SpliceContribution;
62
- #[cfg(splicing)]
63
- use crate::ln::interactivetxs::{
64
- calculate_change_output_value, AbortReason, InteractiveTxMessageSend,
65
- };
66
62
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,
69
66
};
67
+ #[cfg(splicing)]
68
+ use crate::ln::interactivetxs::{AbortReason, InteractiveTxMessageSend};
70
69
use crate::ln::msgs;
71
70
use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError, OnionErrorPacket};
72
71
use crate::ln::onion_utils::{
@@ -10116,7 +10115,7 @@ where
10116
10115
#[rustfmt::skip]
10117
10116
pub fn is_awaiting_initial_mon_persist(&self) -> bool {
10118
10117
if !self.is_awaiting_monitor_update() { return false; }
10119
- if matches!(
10118
+ if self.context.channel_state.is_interactive_signing() || matches!(
10120
10119
self.context.channel_state, ChannelState::AwaitingChannelReady(flags)
10121
10120
if flags.clone().clear(AwaitingChannelReadyFlags::THEIR_CHANNEL_READY | FundedStateFlags::PEER_DISCONNECTED | FundedStateFlags::MONITOR_UPDATE_IN_PROGRESS | AwaitingChannelReadyFlags::WAITING_FOR_BATCH).is_empty()
10122
10121
) {
@@ -13131,6 +13130,30 @@ where
13131
13130
})
13132
13131
.collect();
13133
13132
13133
+ // Optionally add change output
13134
+ let change_script = signer_provider.get_destination_script(context.channel_keys_id)
13135
+ .map_err(|_| ChannelError::close("Error getting change destination script".to_string()))?;
13136
+ let change_value_opt = if our_funding_contribution > SignedAmount::ZERO {
13137
+ calculate_change_output_value(
13138
+ &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 {
13139
+ None
13140
+ };
13141
+ let mut our_funding_outputs = vec![];
13142
+ if let Some(change_value) = change_value_opt {
13143
+ let mut change_output = TxOut {
13144
+ value: Amount::from_sat(change_value),
13145
+ script_pubkey: change_script,
13146
+ };
13147
+ let change_output_weight = get_output_weight(&change_output.script_pubkey).to_wu();
13148
+ let change_output_fee = fee_for_weight(funding_negotiation_context.funding_feerate_sat_per_1000_weight, change_output_weight);
13149
+ let change_value_decreased_with_fee = change_value.saturating_sub(change_output_fee);
13150
+ // Check dust limit again
13151
+ if change_value_decreased_with_fee > context.holder_dust_limit_satoshis {
13152
+ change_output.value = Amount::from_sat(change_value_decreased_with_fee);
13153
+ our_funding_outputs.push(change_output);
13154
+ }
13155
+ }
13156
+
13134
13157
let interactive_tx_constructor = Some(InteractiveTxConstructor::new(
13135
13158
InteractiveTxConstructorArgs {
13136
13159
entropy_source,
@@ -13143,7 +13166,7 @@ where
13143
13166
inputs_to_contribute,
13144
13167
shared_funding_input: None,
13145
13168
shared_funding_output: SharedOwnedOutput::new(shared_funding_output, our_funding_contribution_sats),
13146
- outputs_to_contribute: funding_negotiation_context. our_funding_outputs.clone() ,
13169
+ outputs_to_contribute: our_funding_outputs,
13147
13170
}
13148
13171
).map_err(|err| {
13149
13172
let reason = ClosureReason::ProcessingError { err: err.to_string() };
0 commit comments