Skip to content

Commit 66b084a

Browse files
committed
Provide funding key tweak when signing channel announcements
We'll need to sign a new channel announcement after a channel has a splice locked, so provide the tweak necessary to generate a valid signature.
1 parent 60677cb commit 66b084a

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

lightning/src/ln/channel.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8160,7 +8160,11 @@ impl<SP: Deref> FundedChannel<SP> where
81608160
};
81618161
match &self.context.holder_signer {
81628162
ChannelSignerType::Ecdsa(ecdsa) => {
8163-
let our_bitcoin_sig = match ecdsa.sign_channel_announcement_with_funding_key(&announcement, &self.context.secp_ctx) {
8163+
let funding_key_tweak =
8164+
self.funding.channel_transaction_parameters.holder_pubkeys.funding_key_tweak;
8165+
let our_bitcoin_sig = match ecdsa.sign_channel_announcement_with_funding_key(
8166+
&announcement, funding_key_tweak, &self.context.secp_ctx,
8167+
) {
81648168
Err(_) => {
81658169
log_error!(logger, "Signer rejected channel_announcement signing. Channel will not be announced!");
81668170
return None;
@@ -8201,8 +8205,11 @@ impl<SP: Deref> FundedChannel<SP> where
82018205
.map_err(|_| ChannelError::Ignore("Failed to generate node signature for channel_announcement".to_owned()))?;
82028206
match &self.context.holder_signer {
82038207
ChannelSignerType::Ecdsa(ecdsa) => {
8204-
let our_bitcoin_sig = ecdsa.sign_channel_announcement_with_funding_key(&announcement, &self.context.secp_ctx)
8205-
.map_err(|_| ChannelError::Ignore("Signer rejected channel_announcement".to_owned()))?;
8208+
let funding_key_tweak =
8209+
self.funding.channel_transaction_parameters.holder_pubkeys.funding_key_tweak;
8210+
let our_bitcoin_sig = ecdsa.sign_channel_announcement_with_funding_key(
8211+
&announcement, funding_key_tweak, &self.context.secp_ctx,
8212+
).map_err(|_| ChannelError::Ignore("Signer rejected channel_announcement".to_owned()))?;
82068213
Ok(msgs::ChannelAnnouncement {
82078214
node_signature_1: if were_node_one { our_node_sig } else { their_node_sig },
82088215
node_signature_2: if were_node_one { their_node_sig } else { our_node_sig },

lightning/src/sign/ecdsa.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use bitcoin::transaction::Transaction;
44

55
use bitcoin::secp256k1;
66
use bitcoin::secp256k1::ecdsa::Signature;
7-
use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
7+
use bitcoin::secp256k1::{PublicKey, Scalar, Secp256k1, SecretKey};
88

99
use crate::ln::chan_utils::{
1010
ClosingTransaction, CommitmentTransaction, HTLCOutputInCommitment, HolderCommitmentTransaction,
@@ -227,7 +227,8 @@ pub trait EcdsaChannelSigner: ChannelSigner {
227227
input: usize, secp_ctx: &Secp256k1<secp256k1::All>,
228228
) -> Result<Signature, ()>;
229229
/// Signs a channel announcement message with our funding key proving it comes from one of the
230-
/// channel participants.
230+
/// channel participants. The `funding_key_tweak`, if set, must be added to the funding secret
231+
/// key prior to signing in order to arrive at the key found in the 2-of-2 multisig.
231232
///
232233
/// Channel announcements also require a signature from each node's network key. Our node
233234
/// signature is computed through [`NodeSigner::sign_gossip_message`].
@@ -238,7 +239,8 @@ pub trait EcdsaChannelSigner: ChannelSigner {
238239
///
239240
/// [`NodeSigner::sign_gossip_message`]: crate::sign::NodeSigner::sign_gossip_message
240241
fn sign_channel_announcement_with_funding_key(
241-
&self, msg: &UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<secp256k1::All>,
242+
&self, msg: &UnsignedChannelAnnouncement, funding_key_tweak: Option<Scalar>,
243+
secp_ctx: &Secp256k1<secp256k1::All>,
242244
) -> Result<Signature, ()>;
243245

244246
/// Signs the input of a splicing funding transaction with our funding key.

lightning/src/sign/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,10 +1603,11 @@ impl EcdsaChannelSigner for InMemorySigner {
16031603
}
16041604

16051605
fn sign_channel_announcement_with_funding_key(
1606-
&self, msg: &UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<secp256k1::All>,
1606+
&self, msg: &UnsignedChannelAnnouncement, funding_key_tweak: Option<Scalar>,
1607+
secp_ctx: &Secp256k1<secp256k1::All>,
16071608
) -> Result<Signature, ()> {
16081609
let msghash = hash_to_message!(&Sha256dHash::hash(&msg.encode()[..])[..]);
1609-
Ok(secp_ctx.sign_ecdsa(&msghash, &self.funding_key))
1610+
Ok(secp_ctx.sign_ecdsa(&msghash, &self.funding_key(funding_key_tweak)))
16101611
}
16111612

16121613
fn sign_splicing_funding_input(

lightning/src/util/test_channel_signer.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use bitcoin::secp256k1;
4040
#[cfg(taproot)]
4141
use bitcoin::secp256k1::All;
4242
use bitcoin::secp256k1::{ecdsa::Signature, Secp256k1};
43-
use bitcoin::secp256k1::{PublicKey, SecretKey};
43+
use bitcoin::secp256k1::{PublicKey, Scalar, SecretKey};
4444
#[cfg(taproot)]
4545
use musig2::types::{PartialSignature, PublicNonce};
4646

@@ -466,9 +466,10 @@ impl EcdsaChannelSigner for TestChannelSigner {
466466
}
467467

468468
fn sign_channel_announcement_with_funding_key(
469-
&self, msg: &msgs::UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<secp256k1::All>,
469+
&self, msg: &msgs::UnsignedChannelAnnouncement, funding_key_tweak: Option<Scalar>,
470+
secp_ctx: &Secp256k1<secp256k1::All>,
470471
) -> Result<Signature, ()> {
471-
self.inner.sign_channel_announcement_with_funding_key(msg, secp_ctx)
472+
self.inner.sign_channel_announcement_with_funding_key(msg, funding_key_tweak, secp_ctx)
472473
}
473474

474475
fn sign_splicing_funding_input(

0 commit comments

Comments
 (0)