-
Notifications
You must be signed in to change notification settings - Fork 416
Support splice shared input signing #4024
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
base: main
Are you sure you want to change the base?
Changes from all commits
a07eb85
dfd7779
bbe590d
712b385
1170e1b
e664b7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2192,6 +2192,11 @@ impl FundingScope { | |
self.channel_transaction_parameters.make_funding_redeemscript() | ||
} | ||
|
||
#[cfg(splicing)] | ||
fn holder_funding_pubkey(&self) -> &PublicKey { | ||
&self.get_holder_pubkeys().funding_pubkey | ||
} | ||
|
||
fn counterparty_funding_pubkey(&self) -> &PublicKey { | ||
&self.get_counterparty_pubkeys().funding_pubkey | ||
} | ||
|
@@ -2335,8 +2340,16 @@ impl FundingScope { | |
}; | ||
|
||
let local_owned = self.value_to_self_msat / 1000; | ||
|
||
SharedOwnedInput::new(input, prev_output, local_owned) | ||
let holder_sig_first = self.holder_funding_pubkey().serialize()[..] | ||
< self.counterparty_funding_pubkey().serialize()[..]; | ||
|
||
SharedOwnedInput::new( | ||
input, | ||
prev_output, | ||
local_owned, | ||
holder_sig_first, | ||
self.get_funding_redeemscript(), | ||
) | ||
} | ||
} | ||
|
||
|
@@ -7969,9 +7982,38 @@ where | |
} | ||
|
||
pub fn funding_transaction_signed( | ||
&mut self, witnesses: Vec<Witness>, | ||
&mut self, funding_txid_signed: Txid, witnesses: Vec<Witness>, | ||
) -> Result<(Option<msgs::TxSignatures>, Option<Transaction>), APIError> { | ||
let (funding_tx_opt, tx_signatures_opt) = self | ||
if !self.context.channel_state.is_interactive_signing() { | ||
let err = | ||
format!("Channel {} not expecting funding signatures", self.context.channel_id); | ||
return Err(APIError::APIMisuseError { err }); | ||
} | ||
if self.context.channel_state.is_our_tx_signatures_ready() { | ||
let err = | ||
format!("Channel {} already received funding signatures", self.context.channel_id); | ||
return Err(APIError::APIMisuseError { err }); | ||
} | ||
#[cfg(splicing)] | ||
if let Some(pending_splice) = self.pending_splice.as_ref() { | ||
if !pending_splice | ||
.funding_negotiation | ||
.as_ref() | ||
.map(|funding_negotiation| { | ||
matches!(funding_negotiation, FundingNegotiation::AwaitingSignatures(_)) | ||
}) | ||
.unwrap_or(false) | ||
{ | ||
debug_assert!(false); | ||
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. Can't this be reached? 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. I guess it could? I was thinking it was already covered by the state checks above, so the assert here is really to make sure we catch a mismatch in the splice state. |
||
let err = format!( | ||
"Channel {} with pending splice is not expecting funding signatures yet", | ||
self.context.channel_id | ||
); | ||
return Err(APIError::APIMisuseError { err }); | ||
} | ||
} | ||
|
||
let (tx_signatures_opt, funding_tx_opt) = self | ||
.interactive_tx_signing_session | ||
.as_mut() | ||
.ok_or_else(|| APIError::APIMisuseError { | ||
|
@@ -7981,12 +8023,41 @@ where | |
), | ||
}) | ||
.and_then(|signing_session| { | ||
let tx = signing_session.unsigned_tx().build_unsigned_tx(); | ||
if funding_txid_signed != tx.compute_txid() { | ||
return Err(APIError::APIMisuseError { | ||
err: "Transaction was malleated prior to signing".to_owned(), | ||
}); | ||
} | ||
|
||
let shared_input_signature = if let Some(splice_input_index) = | ||
signing_session.unsigned_tx().shared_input_index() | ||
{ | ||
let sig = match &self.context.holder_signer { | ||
ChannelSignerType::Ecdsa(signer) => signer.sign_splice_shared_input( | ||
&self.funding.channel_transaction_parameters, | ||
&tx, | ||
splice_input_index as usize, | ||
&self.context.secp_ctx, | ||
), | ||
#[cfg(taproot)] | ||
ChannelSignerType::Taproot(_) => todo!(), | ||
}; | ||
Some(sig) | ||
} else { | ||
None | ||
}; | ||
#[cfg(splicing)] | ||
debug_assert_eq!(self.pending_splice.is_some(), shared_input_signature.is_some()); | ||
|
||
let tx_signatures = msgs::TxSignatures { | ||
channel_id: self.context.channel_id, | ||
tx_hash: funding_txid_signed, | ||
witnesses, | ||
shared_input_signature, | ||
}; | ||
signing_session | ||
.provide_holder_witnesses( | ||
&self.context.secp_ctx, | ||
self.context.channel_id, | ||
witnesses, | ||
) | ||
.provide_holder_witnesses(tx_signatures, &self.context.secp_ctx) | ||
.map_err(|err| APIError::APIMisuseError { err }) | ||
})?; | ||
|
||
|
@@ -8004,7 +8075,7 @@ where | |
} | ||
|
||
#[rustfmt::skip] | ||
pub fn tx_signatures(&mut self, msg: &msgs::TxSignatures) -> Result<(Option<Transaction>, Option<msgs::TxSignatures>), ChannelError> { | ||
pub fn tx_signatures(&mut self, msg: &msgs::TxSignatures) -> Result<(Option<msgs::TxSignatures>, Option<Transaction>), ChannelError> { | ||
if !self.context.channel_state.is_interactive_signing() | ||
|| self.context.channel_state.is_their_tx_signatures_sent() | ||
{ | ||
|
@@ -8035,7 +8106,7 @@ where | |
} | ||
} | ||
|
||
let (holder_tx_signatures_opt, funding_tx_opt) = signing_session.received_tx_signatures(msg.clone()) | ||
let (holder_tx_signatures_opt, funding_tx_opt) = signing_session.received_tx_signatures(msg) | ||
.map_err(|msg| ChannelError::Warn(msg))?; | ||
|
||
// Set `THEIR_TX_SIGNATURES_SENT` flag after all potential errors. | ||
|
@@ -8050,7 +8121,7 @@ where | |
self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new()); | ||
} | ||
|
||
Ok((funding_tx_opt, holder_tx_signatures_opt)) | ||
Ok((holder_tx_signatures_opt, funding_tx_opt)) | ||
} else { | ||
let msg = "Unexpected tx_signatures. No funding transaction awaiting signatures"; | ||
let reason = ClosureReason::ProcessingError { err: msg.to_owned() }; | ||
|
Uh oh!
There was an error while loading. Please reload this page.