Skip to content

Commit 575990a

Browse files
committed
f - rotate funding pubkey
1 parent 07190d1 commit 575990a

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

lightning/src/ln/channel.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,14 +2253,10 @@ impl FundingScope {
22532253
debug_assert!(post_value_to_self_msat_signed >= 0);
22542254
let post_value_to_self_msat = post_value_to_self_msat_signed as u64;
22552255

2256+
// Rotate the pubkeys using the prev_funding_txid as a tweak
22562257
let prev_funding_txid = prev_funding.get_funding_txid();
2257-
// Update the splicing 'tweak', this will rotate the keys in the signer
2258-
let holder_pubkeys = match &context.holder_signer {
2259-
ChannelSignerType::Ecdsa(ecdsa) => ecdsa.pubkeys(prev_funding_txid, &context.secp_ctx),
2260-
// TODO (taproot|arik)
2261-
#[cfg(taproot)]
2262-
_ => todo!(),
2263-
};
2258+
let holder_pubkeys = context.holder_pubkeys(prev_funding_txid);
2259+
22642260
let channel_parameters = &prev_funding.channel_transaction_parameters;
22652261
let mut post_channel_transaction_parameters = ChannelTransactionParameters {
22662262
holder_pubkeys,
@@ -2280,7 +2276,7 @@ impl FundingScope {
22802276
.pubkeys
22812277
.funding_pubkey = counterparty_funding_pubkey;
22822278

2283-
// New reserve values are based on the new channel value, and v2-specific
2279+
// New reserve values are based on the new channel value and are v2-specific
22842280
let counterparty_selected_channel_reserve_satoshis = Some(get_v2_channel_reserve_satoshis(
22852281
post_channel_value,
22862282
context.counterparty_dust_limit_satoshis,
@@ -3759,6 +3755,16 @@ where
37593755
return &mut self.holder_signer;
37603756
}
37613757

3758+
/// Returns holder pubkeys to use for the channel.
3759+
fn holder_pubkeys(&self, prev_funding_txid: Option<Txid>) -> ChannelPublicKeys {
3760+
match &self.holder_signer {
3761+
ChannelSignerType::Ecdsa(ecdsa) => ecdsa.pubkeys(prev_funding_txid, &self.secp_ctx),
3762+
// TODO (taproot|arik)
3763+
#[cfg(taproot)]
3764+
_ => todo!(),
3765+
}
3766+
}
3767+
37623768
/// Only allowed immediately after deserialization if get_outbound_scid_alias returns 0,
37633769
/// indicating we were written by LDK prior to 0.0.106 which did not set outbound SCID aliases
37643770
/// or prior to any channel actions during `Channel` initialization.
@@ -10405,9 +10411,10 @@ where
1040510411
fn get_splice_init(
1040610412
&self, our_funding_contribution_satoshis: i64, funding_feerate_per_kw: u32, locktime: u32,
1040710413
) -> msgs::SpliceInit {
10408-
// TODO(splicing): The exisiting pubkey is reused, but a new one should be generated. See #3542.
10409-
// Note that channel_keys_id is supposed NOT to change
10410-
let funding_pubkey = self.funding.get_holder_pubkeys().funding_pubkey.clone();
10414+
// Rotate the pubkeys using the prev_funding_txid as a tweak
10415+
let prev_funding_txid = self.funding.get_funding_txid();
10416+
let funding_pubkey = self.context.holder_pubkeys(prev_funding_txid).funding_pubkey;
10417+
1041110418
msgs::SpliceInit {
1041210419
channel_id: self.context.channel_id,
1041310420
funding_contribution_satoshis: our_funding_contribution_satoshis,
@@ -10539,6 +10546,8 @@ where
1053910546
// FIXME: Propagate message
1054010547
let _msg = interactive_tx_constructor.take_initiator_first_message();
1054110548

10549+
let funding_pubkey = splice_funding.get_holder_pubkeys().funding_pubkey.clone();
10550+
1054210551
self.pending_splice = Some(PendingSplice {
1054310552
funding_negotiation: Some(FundingNegotiation::Pending(
1054410553
splice_funding,
@@ -10548,22 +10557,12 @@ where
1054810557
sent_funding_txid: None,
1054910558
});
1055010559

10551-
Ok(splice_ack_msg)
10552-
}
10553-
10554-
/// Get the splice_ack message that can be sent in response to splice initiation.
10555-
#[cfg(splicing)]
10556-
pub fn get_splice_ack(&self, our_funding_contribution_satoshis: i64) -> msgs::SpliceAck {
10557-
// TODO(splicing): The exisiting pubkey is reused, but a new one should be generated. See #3542.
10558-
// Note that channel_keys_id is supposed NOT to change
10559-
let splice_ack_msg = msgs::SpliceAck {
10560+
Ok(msgs::SpliceAck {
1056010561
channel_id: self.context.channel_id,
1056110562
funding_contribution_satoshis: our_funding_contribution_satoshis,
10562-
funding_pubkey: self.funding.get_holder_pubkeys().funding_pubkey,
10563+
funding_pubkey,
1056310564
require_confirmed_inputs: None,
10564-
};
10565-
// TODO(splicing): start interactive funding negotiation
10566-
splice_ack_msg
10565+
})
1056710566
}
1056810567

1056910568
/// Handle splice_ack

lightning/src/ln/splicing_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ fn test_v1_splice_in() {
4343
assert_eq!(channel_id.to_string(), expected_funded_channel_id);
4444

4545
let expected_initiator_funding_key =
46-
"03c21e841cbc0b48197d060c71e116c185fa0ac281b7d0aa5924f535154437ca3b";
46+
"020abf01c18d5a2543124a12150d698ebf3a8e17df9993521151a49e115678ceea";
4747
let expected_acceptor_funding_key =
48-
"039481c28b904cbe12681e79937373fc76245c1b29871028ae60ba3152162c319b";
48+
"036b47248c628fca98159f30f6b03a6cf0be0c4808cff17c75dc855fe94a244766";
4949

5050
// ==== Channel is now ready for normal operation
5151

0 commit comments

Comments
 (0)