-
Notifications
You must be signed in to change notification settings - Fork 421
Allow outgoing splice request while disconnected #4122
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
6
commits into
lightningdevkit:main
Choose a base branch
from
wpaulino:test-splice-while-disconnected
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.
+591
−124
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3a6eb74
Log broadcast of interactive funding transaction
wpaulino a889bac
Send 0conf splice_locked upon tx_signatures exchange
wpaulino a70375b
Allow outgoing splice request while disconnected
wpaulino 41de9c5
Attempt queued splice after existing pending splice becomes locked
wpaulino bc44a4e
Capture stfu send in reconnection tests
wpaulino 0095e2a
Test propose channel splice while disconnected
wpaulino 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 |
---|---|---|
|
@@ -8636,16 +8636,38 @@ where | |
} | ||
} | ||
|
||
fn on_tx_signatures_exchange(&mut self, funding_tx: Transaction) { | ||
fn on_tx_signatures_exchange<'a, L: Deref>( | ||
&mut self, funding_tx: Transaction, best_block_height: u32, | ||
logger: &WithChannelContext<'a, L>, | ||
) -> Option<msgs::SpliceLocked> | ||
where | ||
L::Target: Logger, | ||
{ | ||
debug_assert!(!self.context.channel_state.is_monitor_update_in_progress()); | ||
debug_assert!(!self.context.channel_state.is_awaiting_remote_revoke()); | ||
|
||
let mut splice_locked = None; | ||
if let Some(pending_splice) = self.pending_splice.as_mut() { | ||
if let Some(FundingNegotiation::AwaitingSignatures { mut funding }) = | ||
pending_splice.funding_negotiation.take() | ||
{ | ||
funding.funding_transaction = Some(funding_tx); | ||
pending_splice.negotiated_candidates.push(funding); | ||
splice_locked = pending_splice.check_get_splice_locked( | ||
&self.context, | ||
pending_splice.negotiated_candidates.len() - 1, | ||
best_block_height, | ||
); | ||
if let Some(splice_txid) = | ||
splice_locked.as_ref().map(|splice_locked| splice_locked.splice_txid) | ||
{ | ||
log_info!( | ||
logger, | ||
"Sending 0conf splice_locked txid {} to our peer for channel {}", | ||
splice_txid, | ||
&self.context.channel_id | ||
); | ||
} | ||
} else { | ||
debug_assert!(false); | ||
} | ||
|
@@ -8655,11 +8677,20 @@ where | |
self.context.channel_state = | ||
ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new()); | ||
} | ||
|
||
splice_locked | ||
} | ||
|
||
pub fn funding_transaction_signed( | ||
&mut self, funding_txid_signed: Txid, witnesses: Vec<Witness>, | ||
) -> Result<(Option<msgs::TxSignatures>, Option<Transaction>), APIError> { | ||
pub fn funding_transaction_signed<L: Deref>( | ||
&mut self, funding_txid_signed: Txid, witnesses: Vec<Witness>, best_block_height: u32, | ||
logger: &L, | ||
) -> Result< | ||
(Option<msgs::TxSignatures>, Option<msgs::SpliceLocked>, Option<Transaction>), | ||
APIError, | ||
> | ||
where | ||
L::Target: Logger, | ||
{ | ||
let signing_session = | ||
if let Some(signing_session) = self.context.interactive_tx_signing_session.as_mut() { | ||
if let Some(pending_splice) = self.pending_splice.as_ref() { | ||
|
@@ -8674,17 +8705,17 @@ where | |
} | ||
|
||
if signing_session.holder_tx_signatures().is_some() { | ||
// Our `tx_signatures` either should've been the first time we processed them, | ||
// or we're waiting for our counterparty to send theirs first. | ||
return Ok((None, None)); | ||
// Our `tx_signatures` either should've been sent the first time we processed | ||
// them, or we're waiting for our counterparty to send theirs first. | ||
return Ok((None, None, None)); | ||
} | ||
|
||
signing_session | ||
} else { | ||
if Some(funding_txid_signed) == self.funding.get_funding_txid() { | ||
// We may be handling a duplicate call and the funding was already locked so we | ||
// no longer have the signing session present. | ||
return Ok((None, None)); | ||
return Ok((None, None, None)); | ||
} | ||
let err = | ||
format!("Channel {} not expecting funding signatures", self.context.channel_id); | ||
|
@@ -8726,17 +8757,31 @@ where | |
.provide_holder_witnesses(tx_signatures, &self.context.secp_ctx) | ||
.map_err(|err| APIError::APIMisuseError { err })?; | ||
|
||
if let Some(funding_tx) = funding_tx_opt.clone() { | ||
debug_assert!(tx_signatures_opt.is_some()); | ||
self.on_tx_signatures_exchange(funding_tx); | ||
let logger = WithChannelContext::from(logger, &self.context, None); | ||
if tx_signatures_opt.is_some() { | ||
log_info!( | ||
logger, | ||
"Sending tx_signatures for interactive funding transaction {funding_txid_signed}" | ||
); | ||
} | ||
|
||
Ok((tx_signatures_opt, funding_tx_opt)) | ||
let splice_locked_opt = funding_tx_opt.clone().and_then(|funding_tx| { | ||
debug_assert!(tx_signatures_opt.is_some()); | ||
self.on_tx_signatures_exchange(funding_tx, best_block_height, &logger) | ||
}); | ||
|
||
Ok((tx_signatures_opt, splice_locked_opt, funding_tx_opt)) | ||
} | ||
|
||
pub fn tx_signatures( | ||
&mut self, msg: &msgs::TxSignatures, | ||
) -> Result<(Option<msgs::TxSignatures>, Option<Transaction>), ChannelError> { | ||
pub fn tx_signatures<L: Deref>( | ||
&mut self, msg: &msgs::TxSignatures, best_block_height: u32, logger: &L, | ||
) -> Result< | ||
(Option<msgs::TxSignatures>, Option<msgs::SpliceLocked>, Option<Transaction>), | ||
ChannelError, | ||
> | ||
where | ||
L::Target: Logger, | ||
{ | ||
let signing_session = if let Some(signing_session) = | ||
self.context.interactive_tx_signing_session.as_mut() | ||
{ | ||
|
@@ -8782,11 +8827,18 @@ where | |
let (holder_tx_signatures_opt, funding_tx_opt) = | ||
signing_session.received_tx_signatures(msg).map_err(|msg| ChannelError::Warn(msg))?; | ||
|
||
if let Some(funding_tx) = funding_tx_opt.clone() { | ||
self.on_tx_signatures_exchange(funding_tx); | ||
} | ||
let logger = WithChannelContext::from(logger, &self.context, None); | ||
log_info!( | ||
logger, | ||
"Received tx_signatures for interactive funding transaction {}", | ||
msg.tx_hash | ||
); | ||
|
||
let splice_locked_opt = funding_tx_opt.clone().and_then(|funding_tx| { | ||
self.on_tx_signatures_exchange(funding_tx, best_block_height, &logger) | ||
}); | ||
|
||
Ok((holder_tx_signatures_opt, funding_tx_opt)) | ||
Ok((holder_tx_signatures_opt, splice_locked_opt, funding_tx_opt)) | ||
} | ||
|
||
/// Queues up an outbound update fee by placing it in the holding cell. You should call | ||
|
@@ -10879,6 +10931,12 @@ where | |
let announcement_sigs = | ||
self.get_announcement_sigs(node_signer, chain_hash, user_config, block_height, logger); | ||
|
||
if let Some(quiescent_action) = self.quiescent_action.as_ref() { | ||
if matches!(quiescent_action, QuiescentAction::Splice(_)) { | ||
self.context.channel_state.set_awaiting_quiescence(); | ||
} | ||
} | ||
|
||
Some(SpliceFundingPromotion { | ||
funding_txo, | ||
monitor_update, | ||
|
@@ -11113,7 +11171,11 @@ where | |
confirmed_funding_index, | ||
height, | ||
) { | ||
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id); | ||
log_info!( | ||
logger, "Sending splice_locked txid {} to our peer for channel {}", | ||
splice_locked.splice_txid, | ||
&self.context.channel_id | ||
); | ||
|
||
let (funding_txo, monitor_update, announcement_sigs, discarded_funding) = chain_node_signer | ||
.and_then(|(chain_hash, node_signer, user_config)| { | ||
|
@@ -11546,10 +11608,10 @@ where | |
}); | ||
} | ||
|
||
if !self.context.is_live() { | ||
if !self.context.is_usable() { | ||
return Err(APIError::APIMisuseError { | ||
err: format!( | ||
"Channel {} cannot be spliced, as channel is not live", | ||
"Channel {} cannot be spliced as it is either pending open/close", | ||
self.context.channel_id() | ||
), | ||
}); | ||
|
@@ -12695,13 +12757,15 @@ where | |
|| self.context.channel_state.is_awaiting_quiescence() | ||
|| self.context.channel_state.is_local_stfu_sent() | ||
{ | ||
log_info!(logger, "Channel is either pending or already quiescent"); | ||
return Ok(None); | ||
} | ||
|
||
self.context.channel_state.set_awaiting_quiescence(); | ||
if self.context.is_live() { | ||
Ok(Some(self.send_stfu(logger)?)) | ||
} else { | ||
log_info!(logger, "Waiting for peer reconnection to send stfu"); | ||
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. Should this log and the one above be |
||
Ok(None) | ||
} | ||
} | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is meant by "pending" here? Shouldn't we only be able to reach here if the channel is funded?