Skip to content

Commit 2fb8a21

Browse files
author
Antoine Riard
committed
Change variable nomenclature in chan_utils
Variables should be named according to the script semantic which is an invariant with regards to generating a local or remote commitment transaction. I.e a owner_htlc_key will always guard a HTLC to the owner of the commitment transaction whereas contributor_htlc_key will guard HTLC to a contributor of the commitment transaction.
1 parent d0b4f52 commit 2fb8a21

File tree

7 files changed

+94
-91
lines changed

7 files changed

+94
-91
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,13 @@ pub trait ChannelKeys : Send+Clone {
318318
/// protocol.
319319
fn sign_channel_announcement<T: secp256k1::Signing>(&self, msg: &msgs::UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()>;
320320

321-
/// Set the remote channel basepoints and remote/local to_self_delay.
321+
/// Set the remote channel basepoints and counterparty/our to_self_delay.
322322
/// This is done immediately on incoming channels and as soon as the channel is accepted on outgoing channels.
323323
///
324-
/// We bind local_to_self_delay late here for API convenience.
324+
/// We bind to_self_delay late here for API convenience.
325325
///
326326
/// Will be called before any signatures are applied.
327-
fn on_accept(&mut self, channel_points: &ChannelPublicKeys, remote_to_self_delay: u16, local_to_self_delay: u16);
327+
fn on_accept(&mut self, channel_points: &ChannelPublicKeys, counterparty_to_self_delay: u16, to_self_delay: u16);
328328
}
329329

330330
/// A trait to describe an object which can get user secrets and key material.
@@ -361,11 +361,11 @@ struct AcceptedChannelData {
361361
/// transactions, ie the amount of time that we have to wait to recover our funds if we
362362
/// broadcast a transaction. You'll likely want to pass this to the
363363
/// ln::chan_utils::build*_transaction functions when signing local transactions.
364-
remote_to_self_delay: u16,
364+
counterparty_to_self_delay: u16,
365365
/// The to_self_delay value specified by us and applied on transactions broadcastable
366366
/// by our counterparty, ie the amount of time that they have to wait to recover their funds
367367
/// if they broadcast a transaction.
368-
local_to_self_delay: u16,
368+
to_self_delay: u16,
369369
}
370370

371371
#[derive(Clone)]
@@ -448,13 +448,13 @@ impl InMemoryChannelKeys {
448448
/// broadcast a transaction. You'll likely want to pass this to the
449449
/// ln::chan_utils::build*_transaction functions when signing local transactions.
450450
/// Will panic if on_accept wasn't called.
451-
pub fn remote_to_self_delay(&self) -> u16 { self.accepted_channel_data.as_ref().unwrap().remote_to_self_delay }
451+
pub fn counterparty_to_self_delay(&self) -> u16 { self.accepted_channel_data.as_ref().unwrap().counterparty_to_self_delay }
452452

453453
/// The to_self_delay value specified by us and applied on transactions broadcastable
454454
/// by our counterparty, ie the amount of time that they have to wait to recover their funds
455455
/// if they broadcast a transaction.
456456
/// Will panic if on_accept wasn't called.
457-
pub fn local_to_self_delay(&self) -> u16 { self.accepted_channel_data.as_ref().unwrap().local_to_self_delay }
457+
pub fn to_self_delay(&self) -> u16 { self.accepted_channel_data.as_ref().unwrap().to_self_delay }
458458
}
459459

460460
impl ChannelKeys for InMemoryChannelKeys {
@@ -486,7 +486,7 @@ impl ChannelKeys for InMemoryChannelKeys {
486486
let mut htlc_sigs = Vec::with_capacity(htlcs.len());
487487
for ref htlc in htlcs {
488488
if let Some(_) = htlc.transaction_output_index {
489-
let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, feerate_per_kw, accepted_data.local_to_self_delay, htlc, &keys.a_delayed_payment_key, &keys.revocation_key);
489+
let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, feerate_per_kw, accepted_data.to_self_delay, htlc, &keys.delayed_payment_key, &keys.revocation_key);
490490
let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, &keys);
491491
let htlc_sighash = hash_to_message!(&bip143::SighashComponents::new(&htlc_tx).sighash_all(&htlc_tx.input[0], &htlc_redeemscript, htlc.amount_msat / 1000)[..]);
492492
let our_htlc_key = match chan_utils::derive_private_key(&secp_ctx, &keys.per_commitment_point, &self.htlc_base_key) {
@@ -518,7 +518,7 @@ impl ChannelKeys for InMemoryChannelKeys {
518518
}
519519

520520
fn sign_local_commitment_htlc_transactions<T: secp256k1::Signing + secp256k1::Verification>(&self, local_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Vec<Option<Signature>>, ()> {
521-
let local_csv = self.accepted_channel_data.as_ref().unwrap().remote_to_self_delay;
521+
let local_csv = self.accepted_channel_data.as_ref().unwrap().counterparty_to_self_delay;
522522
local_commitment_tx.get_htlc_sigs(&self.htlc_base_key, local_csv, secp_ctx)
523523
}
524524

@@ -533,21 +533,21 @@ impl ChannelKeys for InMemoryChannelKeys {
533533
Err(_) => return Err(())
534534
};
535535
let witness_script = if let &Some(ref htlc) = htlc {
536-
let remote_htlcpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().htlc_basepoint) {
537-
Ok(remote_htlcpubkey) => remote_htlcpubkey,
536+
let counterparty_htlcpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().htlc_basepoint) {
537+
Ok(counterparty_htlcpubkey) => counterparty_htlcpubkey,
538538
Err(_) => return Err(())
539539
};
540-
let local_htlcpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.pubkeys().htlc_basepoint) {
541-
Ok(local_htlcpubkey) => local_htlcpubkey,
540+
let htlcpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.pubkeys().htlc_basepoint) {
541+
Ok(htlcpubkey) => htlcpubkey,
542542
Err(_) => return Err(())
543543
};
544-
chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &remote_htlcpubkey, &local_htlcpubkey, &revocation_pubkey)
544+
chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &counterparty_htlcpubkey, &htlcpubkey, &revocation_pubkey)
545545
} else {
546-
let remote_delayedpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().delayed_payment_basepoint) {
547-
Ok(remote_delayedpubkey) => remote_delayedpubkey,
546+
let counterparty_delayedpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().delayed_payment_basepoint) {
547+
Ok(counterparty_delayedpubkey) => counterparty_delayedpubkey,
548548
Err(_) => return Err(())
549549
};
550-
chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.local_to_self_delay(), &remote_delayedpubkey)
550+
chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.to_self_delay(), &counterparty_delayedpubkey)
551551
};
552552
let sighash_parts = bip143::SighashComponents::new(&justice_tx);
553553
let sighash = hash_to_message!(&sighash_parts.sighash_all(&justice_tx.input[input], &witness_script, amount)[..]);
@@ -557,9 +557,9 @@ impl ChannelKeys for InMemoryChannelKeys {
557557
fn sign_remote_htlc_transaction<T: secp256k1::Signing + secp256k1::Verification>(&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
558558
if let Ok(htlc_key) = chan_utils::derive_private_key(&secp_ctx, &per_commitment_point, &self.htlc_base_key) {
559559
let witness_script = if let Ok(revocation_pubkey) = chan_utils::derive_public_revocation_key(&secp_ctx, &per_commitment_point, &self.pubkeys().revocation_basepoint) {
560-
if let Ok(remote_htlcpubkey) = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().htlc_basepoint) {
561-
if let Ok(local_htlcpubkey) = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.pubkeys().htlc_basepoint) {
562-
chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &remote_htlcpubkey, &local_htlcpubkey, &revocation_pubkey)
560+
if let Ok(counterparty_htlcpubkey) = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().htlc_basepoint) {
561+
if let Ok(htlcpubkey) = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.pubkeys().htlc_basepoint) {
562+
chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &counterparty_htlcpubkey, &htlcpubkey, &revocation_pubkey)
563563
} else { return Err(()) }
564564
} else { return Err(()) }
565565
} else { return Err(()) };
@@ -589,18 +589,18 @@ impl ChannelKeys for InMemoryChannelKeys {
589589
Ok(secp_ctx.sign(&msghash, &self.funding_key))
590590
}
591591

592-
fn on_accept(&mut self, channel_pubkeys: &ChannelPublicKeys, remote_to_self_delay: u16, local_to_self_delay: u16) {
592+
fn on_accept(&mut self, channel_pubkeys: &ChannelPublicKeys, counterparty_to_self_delay: u16, to_self_delay: u16) {
593593
assert!(self.accepted_channel_data.is_none(), "Already accepted");
594594
self.accepted_channel_data = Some(AcceptedChannelData {
595595
remote_channel_pubkeys: channel_pubkeys.clone(),
596-
remote_to_self_delay,
597-
local_to_self_delay,
596+
counterparty_to_self_delay,
597+
to_self_delay,
598598
});
599599
}
600600
}
601601

602602
impl_writeable!(AcceptedChannelData, 0,
603-
{ remote_channel_pubkeys, remote_to_self_delay, local_to_self_delay });
603+
{ remote_channel_pubkeys, counterparty_to_self_delay, to_self_delay });
604604

605605
impl Writeable for InMemoryChannelKeys {
606606
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {

0 commit comments

Comments
 (0)