Skip to content

Commit de7ea81

Browse files
author
Antoine Riard
committed
Underscore TxCreationKeys ownership
A TxCreationKeys set represents the key which will be embedded in output scripts of a party's commitment tx state. Among them there is a always a key belonging to counter-party, the HTLC pubkey. To dissociate strongly, prefix keys with broadcaster/countersignatory. A revocation keypair is attributed to the broadcaster as it's used to punish a fraudulent broadcast while minding that such keypair derivation method will be always used by countersignatory as it's its task to enforce punishement thanks to the release secret.
1 parent e709270 commit de7ea81

File tree

9 files changed

+65
-63
lines changed

9 files changed

+65
-63
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -666,35 +666,35 @@ pub extern "C" fn InMemoryChannelKeys_new(mut funding_key: crate::c_types::Secre
666666
crate::chain::keysinterface::InMemoryChannelKeys { inner: Box::into_raw(Box::new(ret)), is_owned: true }
667667
}
668668

669-
/// Remote pubkeys.
669+
/// Counterparty pubkeys.
670670
/// Will panic if on_accept wasn't called.
671671
#[must_use]
672672
#[no_mangle]
673-
pub extern "C" fn InMemoryChannelKeys_remote_pubkeys(this_arg: &InMemoryChannelKeys) -> crate::ln::chan_utils::ChannelPublicKeys {
674-
let mut ret = unsafe { &*this_arg.inner }.remote_pubkeys();
673+
pub extern "C" fn InMemoryChannelKeys_counterparty_pubkeys(this_arg: &InMemoryChannelKeys) -> crate::ln::chan_utils::ChannelPublicKeys {
674+
let mut ret = unsafe { &*this_arg.inner }.counterparty_pubkeys();
675675
crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
676676
}
677677

678-
/// The to_self_delay value specified by our counterparty and applied on locally-broadcastable
678+
/// The contest delay value specified by our counterparty and applied on holder-broadcastable
679679
/// transactions, ie the amount of time that we have to wait to recover our funds if we
680680
/// broadcast a transaction. You'll likely want to pass this to the
681-
/// ln::chan_utils::build*_transaction functions when signing local transactions.
681+
/// ln::chan_utils::build*_transaction functions when signing holder transactions.
682682
/// Will panic if on_accept wasn't called.
683683
#[must_use]
684684
#[no_mangle]
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();
685+
pub extern "C" fn InMemoryChannelKeys_counterparty_selected_contest_delay(this_arg: &InMemoryChannelKeys) -> u16 {
686+
let mut ret = unsafe { &*this_arg.inner }.counterparty_selected_contest_delay();
687687
ret
688688
}
689689

690-
/// The to_self_delay value specified by us and applied on transactions broadcastable
690+
/// The to_contest delay value specified by us and applied on transactions broadcastable
691691
/// by our counterparty, ie the amount of time that they have to wait to recover their funds
692692
/// if they broadcast a transaction.
693693
/// Will panic if on_accept wasn't called.
694694
#[must_use]
695695
#[no_mangle]
696-
pub extern "C" fn InMemoryChannelKeys_local_to_self_delay(this_arg: &InMemoryChannelKeys) -> u16 {
697-
let mut ret = unsafe { &*this_arg.inner }.local_to_self_delay();
696+
pub extern "C" fn InMemoryChannelKeys_locally_selected_contest_delay(this_arg: &InMemoryChannelKeys) -> u16 {
697+
let mut ret = unsafe { &*this_arg.inner }.locally_selected_contest_delay();
698698
ret
699699
}
700700

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,24 +167,24 @@ pub extern "C" fn TxCreationKeys_set_countersignatory_htlc_key(this_ptr: &mut Tx
167167
}
168168
/// Payment Key (which isn't allowed to be spent from for some delay)
169169
#[no_mangle]
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;
170+
pub extern "C" fn TxCreationKeys_get_broadcaster_delayed_payment_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
171+
let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.broadcaster_delayed_payment_key;
172172
crate::c_types::PublicKey::from_rust(&(*inner_val))
173173
}
174174
/// Payment Key (which isn't allowed to be spent from for some delay)
175175
#[no_mangle]
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();
176+
pub extern "C" fn TxCreationKeys_set_broadcaster_delayed_payment_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
177+
unsafe { &mut *this_ptr.inner }.broadcaster_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 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 {
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 broadcaster_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(),
185185
broadcaster_htlc_key: broadcaster_htlc_key_arg.into_rust(),
186186
countersignatory_htlc_key: countersignatory_htlc_key_arg.into_rust(),
187-
delayed_payment_key: delayed_payment_key_arg.into_rust(),
187+
broadcaster_delayed_payment_key: broadcaster_delayed_payment_key_arg.into_rust(),
188188
})), is_owned: true }
189189
}
190190
#[no_mangle]
@@ -422,11 +422,11 @@ pub extern "C" fn TxCreationKeys_derive_new(per_commitment_point: crate::c_types
422422
}
423423

424424
/// A script either spendable by the revocation
425-
/// key or the delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
425+
/// key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
426426
/// Encumbering a `to_local` output on a commitment transaction or 2nd-stage HTLC transactions.
427427
#[no_mangle]
428-
pub extern "C" fn get_revokeable_redeemscript(revocation_key: crate::c_types::PublicKey, mut to_self_delay: u16, delayed_payment_key: crate::c_types::PublicKey) -> crate::c_types::derived::CVec_u8Z {
429-
let mut ret = lightning::ln::chan_utils::get_revokeable_redeemscript(&revocation_key.into_rust(), to_self_delay, &delayed_payment_key.into_rust());
428+
pub extern "C" fn get_revokeable_redeemscript(revocation_key: crate::c_types::PublicKey, mut to_self_delay: u16, broadcaster_delayed_payment_key: crate::c_types::PublicKey) -> crate::c_types::derived::CVec_u8Z {
429+
let mut ret = lightning::ln::chan_utils::get_revokeable_redeemscript(&revocation_key.into_rust(), to_self_delay, &broadcaster_delayed_payment_key.into_rust());
430430
ret.into_bytes().into()
431431
}
432432

@@ -563,8 +563,8 @@ pub extern "C" fn make_funding_redeemscript(a: crate::c_types::PublicKey, b: cra
563563

564564
/// panics if htlc.transaction_output_index.is_none()!
565565
#[no_mangle]
566-
pub extern "C" fn build_htlc_transaction(prev_hash: *const [u8; 32], mut feerate_per_kw: u32, mut to_self_delay: u16, htlc: &crate::ln::chan_utils::HTLCOutputInCommitment, a_delayed_payment_key: crate::c_types::PublicKey, revocation_key: crate::c_types::PublicKey) -> crate::c_types::derived::CVec_u8Z {
567-
let mut ret = lightning::ln::chan_utils::build_htlc_transaction(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*prev_hash }[..]).unwrap(), feerate_per_kw, to_self_delay, unsafe { &*htlc.inner }, &a_delayed_payment_key.into_rust(), &revocation_key.into_rust());
566+
pub extern "C" fn build_htlc_transaction(prev_hash: *const [u8; 32], mut feerate_per_kw: u32, mut to_self_delay: u16, htlc: &crate::ln::chan_utils::HTLCOutputInCommitment, broadcaster_delayed_payment_key: crate::c_types::PublicKey, revocation_key: crate::c_types::PublicKey) -> crate::c_types::derived::CVec_u8Z {
567+
let mut ret = lightning::ln::chan_utils::build_htlc_transaction(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*prev_hash }[..]).unwrap(), feerate_per_kw, to_self_delay, unsafe { &*htlc.inner }, &broadcaster_delayed_payment_key.into_rust(), &revocation_key.into_rust());
568568
let mut local_ret = ::bitcoin::consensus::encode::serialize(&ret);
569569
local_ret.into()
570570
}

lightning/src/chain/keysinterface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.locally_selected_contest_delay, htlc, &keys.delayed_payment_key, &keys.revocation_key);
488+
let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, feerate_per_kw, accepted_data.locally_selected_contest_delay, htlc, &keys.broadcaster_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) {

0 commit comments

Comments
 (0)