-
Notifications
You must be signed in to change notification settings - Fork 452
Allow cancellation of pending splice funding negotiations #4490
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
wpaulino
wants to merge
2
commits into
lightningdevkit:main
Choose a base branch
from
wpaulino:cancel-splice
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1712,7 +1712,7 @@ where | |
| if matches!(chan.context.channel_state, ChannelState::ChannelReady(_)) { | ||
| chan.context.channel_state.clear_local_stfu_sent(); | ||
| chan.context.channel_state.clear_remote_stfu_sent(); | ||
| if chan.should_reset_pending_splice_state(false) { | ||
| if chan.should_reset_pending_splice_state(true) { | ||
| // If there was a pending splice negotiation that failed due to disconnecting, we | ||
| // also take the opportunity to clean up our state. | ||
| let splice_funding_failed = chan.reset_pending_splice_state(); | ||
|
|
@@ -1828,7 +1828,7 @@ where | |
| (None, false) | ||
| }, | ||
| ChannelPhase::Funded(funded_channel) => { | ||
| if funded_channel.should_reset_pending_splice_state(false) { | ||
| if funded_channel.should_reset_pending_splice_state(true) { | ||
| (funded_channel.reset_pending_splice_state(), true) | ||
| } else { | ||
| debug_assert!(false, "We should never fail an interactive funding negotiation once we're exchanging tx_signatures"); | ||
|
|
@@ -2020,7 +2020,7 @@ where | |
| "Received tx_abort while awaiting tx_signatures exchange".to_owned(), | ||
| )); | ||
| } | ||
| if funded_channel.should_reset_pending_splice_state(true) { | ||
| if funded_channel.should_reset_pending_splice_state(false) { | ||
| let has_funding_negotiation = funded_channel | ||
| .pending_splice | ||
| .as_ref() | ||
|
|
@@ -7156,7 +7156,7 @@ where | |
|
|
||
| fn maybe_fail_splice_negotiation(&mut self) -> Option<SpliceFundingFailed> { | ||
| if matches!(self.context.channel_state, ChannelState::ChannelReady(_)) { | ||
| if self.should_reset_pending_splice_state(false) { | ||
| if self.should_reset_pending_splice_state(true) { | ||
| self.reset_pending_splice_state() | ||
| } else { | ||
| self.abandon_quiescent_action() | ||
|
|
@@ -7213,7 +7213,7 @@ where | |
|
|
||
| /// Returns a boolean indicating whether we should reset the splice's | ||
| /// [`PendingFunding::funding_negotiation`]. | ||
| fn should_reset_pending_splice_state(&self, counterparty_aborted: bool) -> bool { | ||
| fn should_reset_pending_splice_state(&self, allow_resumption: bool) -> bool { | ||
| self.pending_splice | ||
| .as_ref() | ||
| .map(|pending_splice| { | ||
|
|
@@ -7225,16 +7225,18 @@ where | |
| funding_negotiation, | ||
| FundingNegotiation::AwaitingSignatures { .. } | ||
| ); | ||
| if counterparty_aborted { | ||
| if allow_resumption { | ||
| // If we want to resume the negotiation after reconnecting, we must be | ||
| // in [`FundingNegotiation::AwaitingSignatures`] to not reset our state. | ||
| !is_awaiting_signatures | ||
| } else { | ||
| !is_awaiting_signatures | ||
| || !self | ||
| .context() | ||
| .interactive_tx_signing_session | ||
| .as_ref() | ||
| .expect("We have a pending splice awaiting signatures") | ||
| .has_received_commitment_signed() | ||
| } else { | ||
| !is_awaiting_signatures | ||
| } | ||
| }) | ||
| .unwrap_or_else(|| { | ||
|
|
@@ -7248,7 +7250,7 @@ where | |
| } | ||
|
|
||
| fn reset_pending_splice_state(&mut self) -> Option<SpliceFundingFailed> { | ||
| debug_assert!(self.should_reset_pending_splice_state(true)); | ||
| debug_assert!(self.should_reset_pending_splice_state(false)); | ||
|
|
||
| // Only clear the signing session if the current round is mid-signing. When an earlier | ||
| // round completed signing and a later RBF round is in AwaitingAck or | ||
|
|
@@ -7308,7 +7310,7 @@ where | |
| } | ||
|
|
||
| pub(super) fn maybe_splice_funding_failed(&self) -> Option<SpliceFundingFailed> { | ||
| if !self.should_reset_pending_splice_state(false) { | ||
| if !self.should_reset_pending_splice_state(true) { | ||
| return None; | ||
| } | ||
|
|
||
|
|
@@ -12659,30 +12661,76 @@ where | |
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| pub fn abandon_splice( | ||
| &mut self, | ||
| ) -> Result<(msgs::TxAbort, Option<SpliceFundingFailed>), APIError> { | ||
| if self.should_reset_pending_splice_state(false) { | ||
| let tx_abort = | ||
| msgs::TxAbort { channel_id: self.context.channel_id(), data: Vec::new() }; | ||
| let splice_funding_failed = self.reset_pending_splice_state(); | ||
| Ok((tx_abort, splice_funding_failed)) | ||
| } else if self.has_pending_splice_awaiting_signatures() { | ||
| Err(APIError::APIMisuseError { | ||
| pub fn cancel_funding_contributed(&mut self) -> Result<InteractiveTxMsgError, APIError> { | ||
| let funding_negotiation = self | ||
| .pending_splice | ||
| .as_ref() | ||
| .and_then(|pending_splice| pending_splice.funding_negotiation.as_ref()); | ||
| let Some(funding_negotiation) = funding_negotiation else { | ||
| return Err(APIError::APIMisuseError { | ||
| err: format!( | ||
| "Channel {} splice cannot be abandoned; already awaiting signatures", | ||
| self.context.channel_id(), | ||
| "Channel {} does not have a pending splice negotiation", | ||
| self.context.channel_id() | ||
| ), | ||
| }) | ||
| } else { | ||
| Err(APIError::APIMisuseError { | ||
| }); | ||
| }; | ||
|
|
||
| let made_contribution = match funding_negotiation { | ||
| FundingNegotiation::AwaitingAck { context, .. } => { | ||
| context.contributed_inputs().next().is_some() | ||
| || context.contributed_outputs().next().is_some() | ||
| }, | ||
| FundingNegotiation::ConstructingTransaction { interactive_tx_constructor, .. } => { | ||
| interactive_tx_constructor.contributed_inputs().next().is_some() | ||
| || interactive_tx_constructor.contributed_outputs().next().is_some() | ||
| }, | ||
| FundingNegotiation::AwaitingSignatures { .. } => self | ||
| .context | ||
| .interactive_tx_signing_session | ||
| .as_ref() | ||
| .expect("We have a pending splice awaiting signatures") | ||
| .has_local_contribution(), | ||
wpaulino marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
| if !made_contribution { | ||
| return Err(APIError::APIMisuseError { | ||
| err: format!( | ||
| "Channel {} splice cannot be abandoned; no pending splice", | ||
| self.context.channel_id(), | ||
| "Channel {} has a pending splice negotiation with no contribution made", | ||
| self.context.channel_id() | ||
| ), | ||
| }) | ||
| }); | ||
| } | ||
|
|
||
| // We typically don't reset the pending funding negotiation when we're in | ||
| // [`FundingNegotiation::AwaitingSignatures`] since we're able to resume it on | ||
| // re-establishment, so we still need to handle this case separately if the user wishes to | ||
| // cancel. If they've yet to call [`Channel::funding_transaction_signed`], then we can | ||
| // guarantee to never have sent any signatures to the counterparty, or have processed any | ||
| // signatures from them. | ||
| if matches!(funding_negotiation, FundingNegotiation::AwaitingSignatures { .. }) { | ||
| let already_signed = self | ||
| .context | ||
| .interactive_tx_signing_session | ||
| .as_ref() | ||
| .expect("We have a pending splice awaiting signatures") | ||
| .has_holder_tx_signatures(); | ||
| if already_signed { | ||
| return Err(APIError::APIMisuseError { | ||
| err: format!( | ||
| "Channel {} has pending splice negotiation that was already signed", | ||
| self.context.channel_id(), | ||
| ), | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| debug_assert!(self.context.channel_state.is_quiescent()); | ||
| let splice_funding_failed = self.reset_pending_splice_state(); | ||
wpaulino marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to worry about updating
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already fixed in a547960. |
||
| debug_assert!(splice_funding_failed.is_some()); | ||
| Ok(InteractiveTxMsgError { | ||
| err: ChannelError::Abort(AbortReason::ManualIntervention), | ||
| splice_funding_failed, | ||
| exited_quiescence: true, | ||
| }) | ||
| } | ||
|
|
||
| /// Checks during handling splice_init | ||
|
|
@@ -15377,7 +15425,7 @@ impl<SP: SignerProvider> Writeable for FundedChannel<SP> { | |
| ChannelState::ChannelReady(_) => { | ||
| channel_state.clear_local_stfu_sent(); | ||
| channel_state.clear_remote_stfu_sent(); | ||
| if self.should_reset_pending_splice_state(false) | ||
| if self.should_reset_pending_splice_state(true) | ||
| || !self.has_pending_splice_awaiting_signatures() | ||
| { | ||
| // We shouldn't be quiescent anymore upon reconnecting if: | ||
|
|
@@ -15767,7 +15815,7 @@ impl<SP: SignerProvider> Writeable for FundedChannel<SP> { | |
| // We don't have to worry about resetting the pending `FundingNegotiation` because we | ||
| // can only read `FundingNegotiation::AwaitingSignatures` variants anyway. | ||
| let pending_splice = | ||
| self.pending_splice.as_ref().filter(|_| !self.should_reset_pending_splice_state(false)); | ||
| self.pending_splice.as_ref().filter(|_| !self.should_reset_pending_splice_state(true)); | ||
|
|
||
| let monitor_pending_tx_signatures = | ||
| self.context.monitor_pending_tx_signatures.then_some(()); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.