Skip to content

Commit 1d7c4f6

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 broadcaster_htlc_key will always guard a HTLC to the party able to broadcast the computed transactions whereas countersignatory_htlc_key will guard HTLC to a countersignatory of the commitment transaction.
1 parent 253af8d commit 1d7c4f6

File tree

9 files changed

+133
-120
lines changed

9 files changed

+133
-120
lines changed

lightning-c-bindings/src/chain/keysinterface.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ pub struct ChannelKeys {
357357
/// We bind local_to_self_delay late here for API convenience.
358358
///
359359
/// Will be called before any signatures are applied.
360-
pub on_accept: extern "C" fn (this_arg: *mut c_void, channel_points: &crate::ln::chan_utils::ChannelPublicKeys, remote_to_self_delay: u16, local_to_self_delay: u16),
360+
pub on_accept: extern "C" fn (this_arg: *mut c_void, channel_points: &crate::ln::chan_utils::ChannelPublicKeys, counterparty_to_self_delay: u16, local_to_self_delay: u16),
361361
pub clone: Option<extern "C" fn (this_arg: *const c_void) -> *mut c_void>,
362362
pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
363363
}
@@ -447,8 +447,8 @@ impl rustChannelKeys for ChannelKeys {
447447
let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(ret.contents.result.take_ptr()) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(ret.contents.err.take_ptr()) })*/ })};
448448
local_ret
449449
}
450-
fn on_accept(&mut self, channel_points: &lightning::ln::chan_utils::ChannelPublicKeys, remote_to_self_delay: u16, local_to_self_delay: u16) {
451-
(self.on_accept)(self.this_arg, &crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { (channel_points as *const _) as *mut _ }, is_owned: false }, remote_to_self_delay, local_to_self_delay)
450+
fn on_accept(&mut self, channel_points: &lightning::ln::chan_utils::ChannelPublicKeys, counterparty_to_self_delay: u16, local_to_self_delay: u16) {
451+
(self.on_accept)(self.this_arg, &crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { (channel_points as *const _) as *mut _ }, is_owned: false }, counterparty_to_self_delay, local_to_self_delay)
452452
}
453453
}
454454

@@ -682,8 +682,8 @@ pub extern "C" fn InMemoryChannelKeys_remote_pubkeys(this_arg: &InMemoryChannelK
682682
/// Will panic if on_accept wasn't called.
683683
#[must_use]
684684
#[no_mangle]
685-
pub extern "C" fn InMemoryChannelKeys_remote_to_self_delay(this_arg: &InMemoryChannelKeys) -> u16 {
686-
let mut ret = unsafe { &*this_arg.inner }.remote_to_self_delay();
685+
pub extern "C" fn InMemoryChannelKeys_counterparty_to_self_delay(this_arg: &InMemoryChannelKeys) -> u16 {
686+
let mut ret = unsafe { &*this_arg.inner }.counterparty_to_self_delay();
687687
ret
688688
}
689689

lightning-c-bindings/src/ln/chan_utils.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -143,48 +143,48 @@ pub extern "C" fn TxCreationKeys_get_revocation_key(this_ptr: &TxCreationKeys) -
143143
pub extern "C" fn TxCreationKeys_set_revocation_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
144144
unsafe { &mut *this_ptr.inner }.revocation_key = val.into_rust();
145145
}
146-
/// A's HTLC Key
146+
/// Broadcaster's HTLC Key
147147
#[no_mangle]
148-
pub extern "C" fn TxCreationKeys_get_a_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
149-
let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.a_htlc_key;
148+
pub extern "C" fn TxCreationKeys_get_broadcaster_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
149+
let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.broadcaster_htlc_key;
150150
crate::c_types::PublicKey::from_rust(&(*inner_val))
151151
}
152-
/// A's HTLC Key
152+
/// Broadcaster's HTLC Key
153153
#[no_mangle]
154-
pub extern "C" fn TxCreationKeys_set_a_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
155-
unsafe { &mut *this_ptr.inner }.a_htlc_key = val.into_rust();
154+
pub extern "C" fn TxCreationKeys_set_broadcaster_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
155+
unsafe { &mut *this_ptr.inner }.broadcaster_htlc_key = val.into_rust();
156156
}
157-
/// B's HTLC Key
157+
/// Countersignatory's HTLC Key
158158
#[no_mangle]
159-
pub extern "C" fn TxCreationKeys_get_b_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
160-
let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.b_htlc_key;
159+
pub extern "C" fn TxCreationKeys_get_countersignatory_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
160+
let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.countersignatory_htlc_key;
161161
crate::c_types::PublicKey::from_rust(&(*inner_val))
162162
}
163-
/// B's HTLC Key
163+
/// Countersignatory's HTLC Key
164164
#[no_mangle]
165-
pub extern "C" fn TxCreationKeys_set_b_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
166-
unsafe { &mut *this_ptr.inner }.b_htlc_key = val.into_rust();
165+
pub extern "C" fn TxCreationKeys_set_countersignatory_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
166+
unsafe { &mut *this_ptr.inner }.countersignatory_htlc_key = val.into_rust();
167167
}
168-
/// A's Payment Key (which isn't allowed to be spent from for some delay)
168+
/// Payment Key (which isn't allowed to be spent from for some delay)
169169
#[no_mangle]
170-
pub extern "C" fn TxCreationKeys_get_a_delayed_payment_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
171-
let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.a_delayed_payment_key;
170+
pub extern "C" fn TxCreationKeys_get_delayed_payment_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
171+
let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.delayed_payment_key;
172172
crate::c_types::PublicKey::from_rust(&(*inner_val))
173173
}
174-
/// A's Payment Key (which isn't allowed to be spent from for some delay)
174+
/// Payment Key (which isn't allowed to be spent from for some delay)
175175
#[no_mangle]
176-
pub extern "C" fn TxCreationKeys_set_a_delayed_payment_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
177-
unsafe { &mut *this_ptr.inner }.a_delayed_payment_key = val.into_rust();
176+
pub extern "C" fn TxCreationKeys_set_delayed_payment_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
177+
unsafe { &mut *this_ptr.inner }.delayed_payment_key = val.into_rust();
178178
}
179179
#[must_use]
180180
#[no_mangle]
181-
pub extern "C" fn TxCreationKeys_new(mut per_commitment_point_arg: crate::c_types::PublicKey, mut revocation_key_arg: crate::c_types::PublicKey, mut a_htlc_key_arg: crate::c_types::PublicKey, mut b_htlc_key_arg: crate::c_types::PublicKey, mut a_delayed_payment_key_arg: crate::c_types::PublicKey) -> TxCreationKeys {
181+
pub extern "C" fn TxCreationKeys_new(mut per_commitment_point_arg: crate::c_types::PublicKey, mut revocation_key_arg: crate::c_types::PublicKey, mut broadcaster_htlc_key_arg: crate::c_types::PublicKey, mut countersignatory_htlc_key_arg: crate::c_types::PublicKey, mut delayed_payment_key_arg: crate::c_types::PublicKey) -> TxCreationKeys {
182182
TxCreationKeys { inner: Box::into_raw(Box::new(nativeTxCreationKeys {
183183
per_commitment_point: per_commitment_point_arg.into_rust(),
184184
revocation_key: revocation_key_arg.into_rust(),
185-
a_htlc_key: a_htlc_key_arg.into_rust(),
186-
b_htlc_key: b_htlc_key_arg.into_rust(),
187-
a_delayed_payment_key: a_delayed_payment_key_arg.into_rust(),
185+
broadcaster_htlc_key: broadcaster_htlc_key_arg.into_rust(),
186+
countersignatory_htlc_key: countersignatory_htlc_key_arg.into_rust(),
187+
delayed_payment_key: delayed_payment_key_arg.into_rust(),
188188
})), is_owned: true }
189189
}
190190
#[no_mangle]

lightning/src/chain/keysinterface.rs

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

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

331331
/// A trait to describe an object which can get user secrets and key material.
@@ -360,7 +360,7 @@ struct AcceptedChannelData {
360360
/// transactions, ie the amount of time that we have to wait to recover our funds if we
361361
/// broadcast a transaction. You'll likely want to pass this to the
362362
/// ln::chan_utils::build*_transaction functions when signing local transactions.
363-
remote_to_self_delay: u16,
363+
counterparty_to_self_delay: u16,
364364
/// The to_self_delay value specified by us and applied on transactions broadcastable
365365
/// by our counterparty, ie the amount of time that they have to wait to recover their funds
366366
/// if they broadcast a transaction.
@@ -384,7 +384,7 @@ pub struct InMemoryChannelKeys {
384384
pub commitment_seed: [u8; 32],
385385
/// Local public keys and basepoints
386386
pub(crate) local_channel_pubkeys: ChannelPublicKeys,
387-
/// Remote public keys and remote/local to_self_delay, populated on channel acceptance
387+
/// Remote public keys and counterparty/local to_self_delay, populated on channel acceptance
388388
accepted_channel_data: Option<AcceptedChannelData>,
389389
/// The total value of this channel
390390
channel_value_satoshis: u64,
@@ -447,7 +447,7 @@ impl InMemoryChannelKeys {
447447
/// broadcast a transaction. You'll likely want to pass this to the
448448
/// ln::chan_utils::build*_transaction functions when signing local transactions.
449449
/// Will panic if on_accept wasn't called.
450-
pub fn remote_to_self_delay(&self) -> u16 { self.accepted_channel_data.as_ref().unwrap().remote_to_self_delay }
450+
pub fn counterparty_to_self_delay(&self) -> u16 { self.accepted_channel_data.as_ref().unwrap().counterparty_to_self_delay }
451451

452452
/// The to_self_delay value specified by us and applied on transactions broadcastable
453453
/// by our counterparty, ie the amount of time that they have to wait to recover their funds
@@ -485,7 +485,7 @@ impl ChannelKeys for InMemoryChannelKeys {
485485
let mut htlc_sigs = Vec::with_capacity(htlcs.len());
486486
for ref htlc in htlcs {
487487
if let Some(_) = htlc.transaction_output_index {
488-
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);
488+
let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, feerate_per_kw, accepted_data.local_to_self_delay, htlc, &keys.delayed_payment_key, &keys.revocation_key);
489489
let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, &keys);
490490
let htlc_sighash = hash_to_message!(&bip143::SigHashCache::new(&htlc_tx).signature_hash(0, &htlc_redeemscript, htlc.amount_msat / 1000, SigHashType::All)[..]);
491491
let our_htlc_key = match chan_utils::derive_private_key(&secp_ctx, &keys.per_commitment_point, &self.htlc_base_key) {
@@ -517,7 +517,7 @@ impl ChannelKeys for InMemoryChannelKeys {
517517
}
518518

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

@@ -532,21 +532,21 @@ impl ChannelKeys for InMemoryChannelKeys {
532532
Err(_) => return Err(())
533533
};
534534
let witness_script = if let &Some(ref htlc) = htlc {
535-
let remote_htlcpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().htlc_basepoint) {
536-
Ok(remote_htlcpubkey) => remote_htlcpubkey,
535+
let counterparty_htlcpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().htlc_basepoint) {
536+
Ok(counterparty_htlcpubkey) => counterparty_htlcpubkey,
537537
Err(_) => return Err(())
538538
};
539539
let local_htlcpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.pubkeys().htlc_basepoint) {
540540
Ok(local_htlcpubkey) => local_htlcpubkey,
541541
Err(_) => return Err(())
542542
};
543-
chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &remote_htlcpubkey, &local_htlcpubkey, &revocation_pubkey)
543+
chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &counterparty_htlcpubkey, &local_htlcpubkey, &revocation_pubkey)
544544
} else {
545-
let remote_delayedpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().delayed_payment_basepoint) {
546-
Ok(remote_delayedpubkey) => remote_delayedpubkey,
545+
let counterparty_delayedpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().delayed_payment_basepoint) {
546+
Ok(counterparty_delayedpubkey) => counterparty_delayedpubkey,
547547
Err(_) => return Err(())
548548
};
549-
chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.local_to_self_delay(), &remote_delayedpubkey)
549+
chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.local_to_self_delay(), &counterparty_delayedpubkey)
550550
};
551551
let mut sighash_parts = bip143::SigHashCache::new(justice_tx);
552552
let sighash = hash_to_message!(&sighash_parts.signature_hash(input, &witness_script, amount, SigHashType::All)[..]);
@@ -556,9 +556,9 @@ impl ChannelKeys for InMemoryChannelKeys {
556556
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, ()> {
557557
if let Ok(htlc_key) = chan_utils::derive_private_key(&secp_ctx, &per_commitment_point, &self.htlc_base_key) {
558558
let witness_script = if let Ok(revocation_pubkey) = chan_utils::derive_public_revocation_key(&secp_ctx, &per_commitment_point, &self.pubkeys().revocation_basepoint) {
559-
if let Ok(remote_htlcpubkey) = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().htlc_basepoint) {
560-
if let Ok(local_htlcpubkey) = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.pubkeys().htlc_basepoint) {
561-
chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &remote_htlcpubkey, &local_htlcpubkey, &revocation_pubkey)
559+
if let Ok(counterparty_htlcpubkey) = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().htlc_basepoint) {
560+
if let Ok(htlcpubkey) = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.pubkeys().htlc_basepoint) {
561+
chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &counterparty_htlcpubkey, &htlcpubkey, &revocation_pubkey)
562562
} else { return Err(()) }
563563
} else { return Err(()) }
564564
} else { return Err(()) };
@@ -588,18 +588,18 @@ impl ChannelKeys for InMemoryChannelKeys {
588588
Ok(secp_ctx.sign(&msghash, &self.funding_key))
589589
}
590590

591-
fn on_accept(&mut self, channel_pubkeys: &ChannelPublicKeys, remote_to_self_delay: u16, local_to_self_delay: u16) {
591+
fn on_accept(&mut self, channel_pubkeys: &ChannelPublicKeys, counterparty_to_self_delay: u16, local_to_self_delay: u16) {
592592
assert!(self.accepted_channel_data.is_none(), "Already accepted");
593593
self.accepted_channel_data = Some(AcceptedChannelData {
594594
remote_channel_pubkeys: channel_pubkeys.clone(),
595-
remote_to_self_delay,
595+
counterparty_to_self_delay,
596596
local_to_self_delay,
597597
});
598598
}
599599
}
600600

601601
impl_writeable!(AcceptedChannelData, 0,
602-
{ remote_channel_pubkeys, remote_to_self_delay, local_to_self_delay });
602+
{ remote_channel_pubkeys, counterparty_to_self_delay, local_to_self_delay });
603603

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

0 commit comments

Comments
 (0)