Skip to content

Commit e664b7e

Browse files
committed
Sign splice shared input when producing holder tx_signatures
We also remove the `Result` to make it clear that this method does not support async operations yet and rename the method to clarify that it is only intended to be used for the shared input of a splice.
1 parent 1170e1b commit e664b7e

File tree

6 files changed

+64
-16
lines changed

6 files changed

+64
-16
lines changed

lightning/src/ln/channel.rs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7984,6 +7984,35 @@ where
79847984
pub fn funding_transaction_signed(
79857985
&mut self, funding_txid_signed: Txid, witnesses: Vec<Witness>,
79867986
) -> Result<(Option<msgs::TxSignatures>, Option<Transaction>), APIError> {
7987+
if !self.context.channel_state.is_interactive_signing() {
7988+
let err =
7989+
format!("Channel {} not expecting funding signatures", self.context.channel_id);
7990+
return Err(APIError::APIMisuseError { err });
7991+
}
7992+
if self.context.channel_state.is_our_tx_signatures_ready() {
7993+
let err =
7994+
format!("Channel {} already received funding signatures", self.context.channel_id);
7995+
return Err(APIError::APIMisuseError { err });
7996+
}
7997+
#[cfg(splicing)]
7998+
if let Some(pending_splice) = self.pending_splice.as_ref() {
7999+
if !pending_splice
8000+
.funding_negotiation
8001+
.as_ref()
8002+
.map(|funding_negotiation| {
8003+
matches!(funding_negotiation, FundingNegotiation::AwaitingSignatures(_))
8004+
})
8005+
.unwrap_or(false)
8006+
{
8007+
debug_assert!(false);
8008+
let err = format!(
8009+
"Channel {} with pending splice is not expecting funding signatures yet",
8010+
self.context.channel_id
8011+
);
8012+
return Err(APIError::APIMisuseError { err });
8013+
}
8014+
}
8015+
79878016
let (tx_signatures_opt, funding_tx_opt) = self
79888017
.interactive_tx_signing_session
79898018
.as_mut()
@@ -8001,11 +8030,31 @@ where
80018030
});
80028031
}
80038032

8033+
let shared_input_signature = if let Some(splice_input_index) =
8034+
signing_session.unsigned_tx().shared_input_index()
8035+
{
8036+
let sig = match &self.context.holder_signer {
8037+
ChannelSignerType::Ecdsa(signer) => signer.sign_splice_shared_input(
8038+
&self.funding.channel_transaction_parameters,
8039+
&tx,
8040+
splice_input_index as usize,
8041+
&self.context.secp_ctx,
8042+
),
8043+
#[cfg(taproot)]
8044+
ChannelSignerType::Taproot(_) => todo!(),
8045+
};
8046+
Some(sig)
8047+
} else {
8048+
None
8049+
};
8050+
#[cfg(splicing)]
8051+
debug_assert_eq!(self.pending_splice.is_some(), shared_input_signature.is_some());
8052+
80048053
let tx_signatures = msgs::TxSignatures {
80058054
channel_id: self.context.channel_id,
80068055
tx_hash: funding_txid_signed,
80078056
witnesses,
8008-
shared_input_signature: None,
8057+
shared_input_signature,
80098058
};
80108059
signing_session
80118060
.provide_holder_witnesses(tx_signatures, &self.context.secp_ctx)

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9044,7 +9044,9 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
90449044
Ok((None, _)) => {
90459045
debug_assert!(false, "If our tx_signatures is empty, then we should send it first!");
90469046
},
9047-
Err(err) => debug_assert!(false, "We should not error here but we got: {:?}", err),
9047+
Err(err) => {
9048+
log_warn!(logger, "Failed signing interactive funding transaction: {err:?}");
9049+
},
90489050
}
90499051
}
90509052
}

lightning/src/sign/ecdsa.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ pub trait EcdsaChannelSigner: ChannelSigner {
242242
msg: &UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<secp256k1::All>,
243243
) -> Result<Signature, ()>;
244244

245-
/// Signs the input of a splicing funding transaction with our funding key.
245+
/// Signs the shared input of a splice transaction with our funding key.
246246
///
247247
/// In splicing, the previous funding transaction output is spent as the input of
248248
/// the new funding transaction, and is a 2-of-2 multisig.
@@ -253,11 +253,8 @@ pub trait EcdsaChannelSigner: ChannelSigner {
253253
///
254254
/// `input_index`: The index of the input within the new funding transaction `tx`,
255255
/// spending the previous funding transaction's output
256-
///
257-
/// This method is *not* asynchronous. If an `Err` is returned, the channel will be immediately
258-
/// closed.
259-
fn sign_splicing_funding_input(
256+
fn sign_splice_shared_input(
260257
&self, channel_parameters: &ChannelTransactionParameters, tx: &Transaction,
261258
input_index: usize, secp_ctx: &Secp256k1<secp256k1::All>,
262-
) -> Result<Signature, ()>;
259+
) -> Signature;
263260
}

lightning/src/sign/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,10 +1753,10 @@ impl EcdsaChannelSigner for InMemorySigner {
17531753
Ok(secp_ctx.sign_ecdsa(&msghash, &funding_key))
17541754
}
17551755

1756-
fn sign_splicing_funding_input(
1756+
fn sign_splice_shared_input(
17571757
&self, channel_parameters: &ChannelTransactionParameters, tx: &Transaction,
17581758
input_index: usize, secp_ctx: &Secp256k1<secp256k1::All>,
1759-
) -> Result<Signature, ()> {
1759+
) -> Signature {
17601760
assert!(channel_parameters.is_populated(), "Channel parameters must be fully populated");
17611761
assert_eq!(
17621762
tx.input[input_index].previous_output,
@@ -1782,7 +1782,7 @@ impl EcdsaChannelSigner for InMemorySigner {
17821782
)
17831783
.unwrap()[..];
17841784
let msg = hash_to_message!(sighash);
1785-
Ok(sign(secp_ctx, &msg, &funding_key))
1785+
sign(secp_ctx, &msg, &funding_key)
17861786
}
17871787
}
17881788

lightning/src/util/dyn_signer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ delegate!(DynSigner, EcdsaChannelSigner, inner,
159159
secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()>,
160160
fn sign_holder_htlc_transaction(, htlc_tx: &Transaction, input: usize,
161161
htlc_descriptor: &HTLCDescriptor, secp_ctx: &Secp256k1<All>) -> Result<Signature, ()>,
162-
fn sign_splicing_funding_input(, channel_parameters: &ChannelTransactionParameters,
163-
tx: &Transaction, input_index: usize, secp_ctx: &Secp256k1<All>) -> Result<Signature, ()>
162+
fn sign_splice_shared_input(, channel_parameters: &ChannelTransactionParameters,
163+
tx: &Transaction, input_index: usize, secp_ctx: &Secp256k1<All>) -> Signature
164164
);
165165

166166
delegate!(DynSigner, ChannelSigner,

lightning/src/util/test_channel_signer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,11 @@ impl EcdsaChannelSigner for TestChannelSigner {
484484
self.inner.sign_channel_announcement_with_funding_key(channel_parameters, msg, secp_ctx)
485485
}
486486

487-
fn sign_splicing_funding_input(
487+
fn sign_splice_shared_input(
488488
&self, channel_parameters: &ChannelTransactionParameters, tx: &Transaction,
489489
input_index: usize, secp_ctx: &Secp256k1<secp256k1::All>,
490-
) -> Result<Signature, ()> {
491-
self.inner.sign_splicing_funding_input(channel_parameters, tx, input_index, secp_ctx)
490+
) -> Signature {
491+
self.inner.sign_splice_shared_input(channel_parameters, tx, input_index, secp_ctx)
492492
}
493493
}
494494

0 commit comments

Comments
 (0)