Skip to content

Additional closing cleanups post-#3881 #3899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 20 additions & 27 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8642,10 +8642,7 @@ where

pub fn maybe_propose_closing_signed<F: Deref, L: Deref>(
&mut self, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
) -> Result<
(Option<msgs::ClosingSigned>, Option<Transaction>, Option<ShutdownResult>),
ChannelError,
>
) -> Result<(Option<msgs::ClosingSigned>, Option<(Transaction, ShutdownResult)>), ChannelError>
where
F::Target: FeeEstimator,
L::Target: Logger,
Expand All @@ -8655,20 +8652,20 @@ where
// initiate `closing_signed` negotiation until we're clear of all pending messages. Note
// that closing_negotiation_ready checks this case (as well as a few others).
if self.context.last_sent_closing_fee.is_some() || !self.closing_negotiation_ready() {
return Ok((None, None, None));
return Ok((None, None));
}

if !self.funding.is_outbound() {
if let Some(msg) = &self.context.pending_counterparty_closing_signed.take() {
return self.closing_signed(fee_estimator, &msg, logger);
}
return Ok((None, None, None));
return Ok((None, None));
}

// If we're waiting on a counterparty `commitment_signed` to clear some updates from our
// local commitment transaction, we can't yet initiate `closing_signed` negotiation.
if self.context.expecting_peer_commitment_signed {
return Ok((None, None, None));
return Ok((None, None));
}

let (our_min_fee, our_max_fee) = self.calculate_closing_fee_limits(fee_estimator);
Expand All @@ -8687,7 +8684,7 @@ where
our_max_fee,
logger,
);
Ok((closing_signed, None, None))
Ok((closing_signed, None))
}

fn mark_response_received(&mut self) {
Expand Down Expand Up @@ -8950,10 +8947,7 @@ where
pub fn closing_signed<F: Deref, L: Deref>(
&mut self, fee_estimator: &LowerBoundedFeeEstimator<F>, msg: &msgs::ClosingSigned,
logger: &L,
) -> Result<
(Option<msgs::ClosingSigned>, Option<Transaction>, Option<ShutdownResult>),
ChannelError,
>
) -> Result<(Option<msgs::ClosingSigned>, Option<(Transaction, ShutdownResult)>), ChannelError>
where
F::Target: FeeEstimator,
L::Target: Logger,
Expand Down Expand Up @@ -8993,7 +8987,7 @@ where

if self.context.channel_state.is_monitor_update_in_progress() {
self.context.pending_counterparty_closing_signed = Some(msg.clone());
return Ok((None, None, None));
return Ok((None, None));
}

let funding_redeemscript = self.funding.get_funding_redeemscript();
Expand Down Expand Up @@ -9047,7 +9041,7 @@ where
self.build_signed_closing_transaction(&mut closing_tx, &msg.signature, &sig);
self.context.channel_state = ChannelState::ShutdownComplete;
self.context.update_time_counter += 1;
return Ok((None, Some(tx), Some(shutdown_result)));
return Ok((None, Some((tx, shutdown_result))));
}
}

Expand All @@ -9070,26 +9064,25 @@ where
our_max_fee,
logger,
);
let (signed_tx, shutdown_result) = if $new_fee == msg.fee_satoshis {
let shutdown_result =
closing_signed.as_ref().map(|_| self.shutdown_result_coop_close());
if closing_signed.is_some() {
self.context.channel_state = ChannelState::ShutdownComplete;
}
let signed_tx_shutdown = if $new_fee == msg.fee_satoshis {
self.context.update_time_counter += 1;
self.context.last_received_closing_sig = Some(msg.signature.clone());
let tx = closing_signed.as_ref().map(|ClosingSigned { signature, .. }| {
self.build_signed_closing_transaction(
if let Some(ClosingSigned { signature, .. }) = &closing_signed {
let shutdown_result = self.shutdown_result_coop_close();
self.context.channel_state = ChannelState::ShutdownComplete;
let tx = self.build_signed_closing_transaction(
&closing_tx,
&msg.signature,
signature,
)
});
(tx, shutdown_result)
);
Some((tx, shutdown_result))
} else {
None
}
} else {
(None, None)
None
};
return Ok((closing_signed, signed_tx, shutdown_result))
return Ok((closing_signed, signed_tx_shutdown))
};
}

Expand Down
Loading
Loading