Skip to content

Commit 1f3d7d7

Browse files
committed
Drop requirement that all ChannelKeys expose the funding privkey
1 parent b1d536e commit 1f3d7d7

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ impl Readable for SpendableOutputDescriptor {
195195
// TODO: We should remove Clone by instead requesting a new ChannelKeys copy when we create
196196
// ChannelMonitors instead of expecting to clone the one out of the Channel into the monitors.
197197
pub trait ChannelKeys : Send+Clone {
198-
/// Gets the private key for the anchor tx
199-
fn funding_key<'a>(&'a self) -> &'a SecretKey;
200198
/// Gets the local secret key for blinded revocation pubkey
201199
fn revocation_base_key<'a>(&'a self) -> &'a SecretKey;
202200
/// Gets the local secret key used in the to_remote output of remote commitment tx (ie the
@@ -416,7 +414,6 @@ impl InMemoryChannelKeys {
416414
}
417415

418416
impl ChannelKeys for InMemoryChannelKeys {
419-
fn funding_key(&self) -> &SecretKey { &self.funding_key }
420417
fn revocation_base_key(&self) -> &SecretKey { &self.revocation_base_key }
421418
fn payment_key(&self) -> &SecretKey { &self.payment_key }
422419
fn delayed_payment_base_key(&self) -> &SecretKey { &self.delayed_payment_base_key }

lightning/src/ln/channel.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,8 +1120,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
11201120
/// pays to get_funding_redeemscript().to_v0_p2wsh()).
11211121
/// Panics if called before accept_channel/new_from_req
11221122
pub fn get_funding_redeemscript(&self) -> Script {
1123-
let our_funding_key = PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.funding_key());
1124-
make_funding_redeemscript(&our_funding_key, self.their_funding_pubkey())
1123+
make_funding_redeemscript(&self.local_keys.pubkeys().funding_pubkey, self.their_funding_pubkey())
11251124
}
11261125

11271126
/// Builds the htlc-success or htlc-timeout transaction which spends a given HTLC output
@@ -1455,7 +1454,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
14551454
log_trace!(logger, "Checking funding_created tx signature {} by key {} against tx {} (sighash {}) with redeemscript {}", log_bytes!(sig.serialize_compact()[..]), log_bytes!(self.their_funding_pubkey().serialize()), encode::serialize_hex(&local_initial_commitment_tx), log_bytes!(local_sighash[..]), encode::serialize_hex(&funding_script));
14561455
secp_check!(self.secp_ctx.verify(&local_sighash, &sig, self.their_funding_pubkey()), "Invalid funding_created signature from peer");
14571456

1458-
let localtx = LocalCommitmentTransaction::new_missing_local_sig(local_initial_commitment_tx, sig.clone(), &PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.funding_key()), self.their_funding_pubkey(), local_keys, self.feerate_per_kw, Vec::new());
1457+
let localtx = LocalCommitmentTransaction::new_missing_local_sig(local_initial_commitment_tx, sig.clone(), &self.local_keys.pubkeys().funding_pubkey, self.their_funding_pubkey(), local_keys, self.feerate_per_kw, Vec::new());
14591458

14601459
let remote_keys = self.build_remote_transaction_keys()?;
14611460
let remote_initial_commitment_tx = self.build_commitment_transaction(self.cur_remote_commitment_transaction_number, &remote_keys, false, false, self.feerate_per_kw, logger).0;
@@ -1568,7 +1567,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
15681567
let funding_txo_script = funding_redeemscript.to_v0_p2wsh();
15691568
macro_rules! create_monitor {
15701569
() => { {
1571-
let local_commitment_tx = LocalCommitmentTransaction::new_missing_local_sig(local_initial_commitment_tx.clone(), msg.signature.clone(), &PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.funding_key()), their_funding_pubkey, local_keys.clone(), self.feerate_per_kw, Vec::new());
1570+
let local_commitment_tx = LocalCommitmentTransaction::new_missing_local_sig(local_initial_commitment_tx.clone(), msg.signature.clone(), &self.local_keys.pubkeys().funding_pubkey, their_funding_pubkey, local_keys.clone(), self.feerate_per_kw, Vec::new());
15721571
let mut channel_monitor = ChannelMonitor::new(self.local_keys.clone(),
15731572
&self.shutdown_pubkey, self.our_to_self_delay,
15741573
&self.destination_script, (funding_txo.clone(), funding_txo_script.clone()),
@@ -1899,7 +1898,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
18991898
let mut monitor_update = ChannelMonitorUpdate {
19001899
update_id: self.latest_monitor_update_id,
19011900
updates: vec![ChannelMonitorUpdateStep::LatestLocalCommitmentTXInfo {
1902-
commitment_tx: LocalCommitmentTransaction::new_missing_local_sig(local_commitment_tx.0, msg.signature.clone(), &PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.funding_key()), &their_funding_pubkey, local_keys, self.feerate_per_kw, htlcs_without_source),
1901+
commitment_tx: LocalCommitmentTransaction::new_missing_local_sig(local_commitment_tx.0, msg.signature.clone(), &self.local_keys.pubkeys().funding_pubkey, &their_funding_pubkey, local_keys, self.feerate_per_kw, htlcs_without_source),
19031902
htlc_outputs: htlcs_and_sigs
19041903
}]
19051904
};
@@ -2825,7 +2824,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
28252824

28262825
tx.input[0].witness.push(Vec::new()); // First is the multisig dummy
28272826

2828-
let our_funding_key = PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.funding_key()).serialize();
2827+
let our_funding_key = self.local_keys.pubkeys().funding_pubkey.serialize();
28292828
let their_funding_key = self.their_funding_pubkey().serialize();
28302829
if our_funding_key[..] < their_funding_key[..] {
28312830
tx.input[0].witness.push(our_sig.serialize_der().to_vec());
@@ -3315,7 +3314,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
33153314
feerate_per_kw: fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::Background) as u32,
33163315
to_self_delay: self.our_to_self_delay,
33173316
max_accepted_htlcs: OUR_MAX_HTLCS,
3318-
funding_pubkey: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.funding_key()),
3317+
funding_pubkey: self.local_keys.pubkeys().funding_pubkey,
33193318
revocation_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.revocation_base_key()),
33203319
payment_point: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_key()),
33213320
delayed_payment_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.delayed_payment_base_key()),
@@ -3348,7 +3347,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
33483347
minimum_depth: self.minimum_depth,
33493348
to_self_delay: self.our_to_self_delay,
33503349
max_accepted_htlcs: OUR_MAX_HTLCS,
3351-
funding_pubkey: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.funding_key()),
3350+
funding_pubkey: self.local_keys.pubkeys().funding_pubkey,
33523351
revocation_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.revocation_base_key()),
33533352
payment_point: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_key()),
33543353
delayed_payment_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.delayed_payment_base_key()),
@@ -3431,16 +3430,15 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
34313430
}
34323431

34333432
let were_node_one = our_node_id.serialize()[..] < self.their_node_id.serialize()[..];
3434-
let our_bitcoin_key = PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.funding_key());
34353433

34363434
let msg = msgs::UnsignedChannelAnnouncement {
34373435
features: ChannelFeatures::known(),
34383436
chain_hash: chain_hash,
34393437
short_channel_id: self.get_short_channel_id().unwrap(),
34403438
node_id_1: if were_node_one { our_node_id } else { self.get_their_node_id() },
34413439
node_id_2: if were_node_one { self.get_their_node_id() } else { our_node_id },
3442-
bitcoin_key_1: if were_node_one { our_bitcoin_key } else { self.their_funding_pubkey().clone() },
3443-
bitcoin_key_2: if were_node_one { self.their_funding_pubkey().clone() } else { our_bitcoin_key },
3440+
bitcoin_key_1: if were_node_one { self.local_keys.pubkeys().funding_pubkey } else { self.their_funding_pubkey().clone() },
3441+
bitcoin_key_2: if were_node_one { self.their_funding_pubkey().clone() } else { self.local_keys.pubkeys().funding_pubkey },
34443442
excess_data: Vec::new(),
34453443
};
34463444

@@ -4442,7 +4440,7 @@ mod tests {
44424440
(0, 0)
44434441
);
44444442

4445-
assert_eq!(PublicKey::from_secret_key(&secp_ctx, chan_keys.funding_key()).serialize()[..],
4443+
assert_eq!(chan_keys.pubkeys().funding_pubkey.serialize()[..],
44464444
hex::decode("023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb").unwrap()[..]);
44474445
let keys_provider = Keys { chan_keys: chan_keys.clone() };
44484446

@@ -4512,7 +4510,7 @@ mod tests {
45124510
})*
45134511
assert_eq!(unsigned_tx.1.len(), per_htlc.len());
45144512

4515-
localtx = LocalCommitmentTransaction::new_missing_local_sig(unsigned_tx.0.clone(), their_signature.clone(), &PublicKey::from_secret_key(&secp_ctx, chan.local_keys.funding_key()), chan.their_funding_pubkey(), keys.clone(), chan.feerate_per_kw, per_htlc);
4513+
localtx = LocalCommitmentTransaction::new_missing_local_sig(unsigned_tx.0.clone(), their_signature.clone(), &chan_keys.pubkeys().funding_pubkey, chan.their_funding_pubkey(), keys.clone(), chan.feerate_per_kw, per_htlc);
45164514
let local_sig = chan_keys.sign_local_commitment(&localtx, &chan.secp_ctx).unwrap();
45174515
assert_eq!(Signature::from_der(&hex::decode($our_sig_hex).unwrap()[..]).unwrap(), local_sig);
45184516

lightning/src/ln/functional_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3850,8 +3850,8 @@ fn test_invalid_channel_announcement() {
38503850
macro_rules! sign_msg {
38513851
($unsigned_msg: expr) => {
38523852
let msghash = Message::from_slice(&Sha256dHash::hash(&$unsigned_msg.encode()[..])[..]).unwrap();
3853-
let as_bitcoin_sig = secp_ctx.sign(&msghash, &as_chan.get_local_keys().inner.funding_key());
3854-
let bs_bitcoin_sig = secp_ctx.sign(&msghash, &bs_chan.get_local_keys().inner.funding_key());
3853+
let as_bitcoin_sig = secp_ctx.sign(&msghash, &as_chan.get_local_keys().inner.funding_key);
3854+
let bs_bitcoin_sig = secp_ctx.sign(&msghash, &bs_chan.get_local_keys().inner.funding_key);
38553855
let as_node_sig = secp_ctx.sign(&msghash, &nodes[0].keys_manager.get_node_secret());
38563856
let bs_node_sig = secp_ctx.sign(&msghash, &nodes[1].keys_manager.get_node_secret());
38573857
chan_announcement = msgs::ChannelAnnouncement {

lightning/src/util/enforcing_trait_impls.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ impl EnforcingChannelKeys {
5151
}
5252

5353
impl ChannelKeys for EnforcingChannelKeys {
54-
fn funding_key(&self) -> &SecretKey { self.inner.funding_key() }
5554
fn revocation_base_key(&self) -> &SecretKey { self.inner.revocation_base_key() }
5655
fn payment_key(&self) -> &SecretKey { self.inner.payment_key() }
5756
fn delayed_payment_base_key(&self) -> &SecretKey { self.inner.delayed_payment_base_key() }

0 commit comments

Comments
 (0)