Skip to content

Commit 21d0a95

Browse files
author
Antoine Riard
committed
Cleanup locally-selected-delay
Comment meaning of holder/counterparty Diverse chan_utils cleanups Cleanups post-cbindings merge Fix misusage of holder_selected_contest_delay instead of counterparty _selected_contest_delay in HolderCommitmentTransaction Fix old payment_point comment
1 parent 6133498 commit 21d0a95

File tree

6 files changed

+51
-48
lines changed

6 files changed

+51
-48
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ pub enum SpendableOutputDescriptor {
3737
/// it is an output from an old state which we broadcast (which should never happen).
3838
///
3939
/// To derive the delayed_payment key which is used to sign for this input, you must pass the
40-
/// local delayed_payment_base_key (ie the private key which corresponds to the pubkey in
40+
/// holder delayed_payment_base_key (ie the private key which corresponds to the pubkey in
4141
/// ChannelKeys::pubkeys().delayed_payment_basepoint) and the provided per_commitment_point to
4242
/// chan_utils::derive_private_key. The public key can be generated without the secret key
4343
/// using chan_utils::derive_public_key and only the delayed_payment_basepoint which appears in
4444
/// ChannelKeys::pubkeys().
4545
///
4646
/// To derive the revocation_pubkey provided here (which is used in the witness
47-
/// script generation), you must pass the remote revocation_basepoint (which appears in the
47+
/// script generation), you must pass the revocation_basepoint (which appears in the
4848
/// call to ChannelKeys::on_accept) and the provided per_commitment point
4949
/// to chan_utils::derive_public_revocation_key.
5050
///
@@ -351,7 +351,7 @@ pub struct ChannelKeys {
351351
/// protocol.
352352
#[must_use]
353353
pub sign_channel_announcement: extern "C" fn (this_arg: *const c_void, msg: &crate::ln::msgs::UnsignedChannelAnnouncement) -> crate::c_types::derived::CResult_SignatureNoneZ,
354-
/// Set the remote channel basepoints and remote/local to_self_delay.
354+
/// Set the counterparty channel basepoints and counterparty/local to_self_delay.
355355
/// This is done immediately on incoming channels and as soon as the channel is accepted on outgoing channels.
356356
///
357357
/// We bind local_to_self_delay late here for API convenience.
@@ -613,13 +613,13 @@ pub extern "C" fn InMemoryChannelKeys_get_revocation_base_key(this_ptr: &InMemor
613613
pub extern "C" fn InMemoryChannelKeys_set_revocation_base_key(this_ptr: &mut InMemoryChannelKeys, mut val: crate::c_types::SecretKey) {
614614
unsafe { &mut *this_ptr.inner }.revocation_base_key = val.into_rust();
615615
}
616-
/// Local secret key used for our balance in remote-broadcasted commitment transactions
616+
/// Local secret key used for our balance in counterparty-broadcasted commitment transactions
617617
#[no_mangle]
618618
pub extern "C" fn InMemoryChannelKeys_get_payment_key(this_ptr: &InMemoryChannelKeys) -> *const [u8; 32] {
619619
let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.payment_key;
620620
(*inner_val).as_ref()
621621
}
622-
/// Local secret key used for our balance in remote-broadcasted commitment transactions
622+
/// Local secret key used for our balance in counterparty-broadcasted commitment transactions
623623
#[no_mangle]
624624
pub extern "C" fn InMemoryChannelKeys_set_payment_key(this_ptr: &mut InMemoryChannelKeys, mut val: crate::c_types::SecretKey) {
625625
unsafe { &mut *this_ptr.inner }.payment_key = val.into_rust();
@@ -693,8 +693,8 @@ pub extern "C" fn InMemoryChannelKeys_counterparty_selected_contest_delay(this_a
693693
/// Will panic if on_accept wasn't called.
694694
#[must_use]
695695
#[no_mangle]
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();
696+
pub extern "C" fn InMemoryChannelKeys_holder_selected_contest_delay(this_arg: &InMemoryChannelKeys) -> u16 {
697+
let mut ret = unsafe { &*this_arg.inner }.holder_selected_contest_delay();
698698
ret
699699
}
700700

@@ -793,8 +793,8 @@ extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_channel_announcement(this_arg
793793
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) };
794794
local_ret
795795
}
796-
extern "C" fn InMemoryChannelKeys_ChannelKeys_on_accept(this_arg: *mut c_void, channel_pubkeys: &crate::ln::chan_utils::ChannelPublicKeys, mut remote_to_self_delay: u16, mut local_to_self_delay: u16) {
797-
unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.on_accept(unsafe { &*channel_pubkeys.inner }, remote_to_self_delay, local_to_self_delay)
796+
extern "C" fn InMemoryChannelKeys_ChannelKeys_on_accept(this_arg: *mut c_void, channel_pubkeys: &crate::ln::chan_utils::ChannelPublicKeys, mut counterparty_selected_contest_delay: u16, mut holder_selected_contest_delay: u16) {
797+
unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.on_accept(unsafe { &*channel_pubkeys.inner }, counterparty_selected_contest_delay, holder_selected_contest_delay)
798798
}
799799

800800
#[no_mangle]

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,15 @@ pub extern "C" fn ChannelPublicKeys_set_revocation_basepoint(this_ptr: &mut Chan
347347
unsafe { &mut *this_ptr.inner }.revocation_basepoint = val.into_rust();
348348
}
349349
/// The public key which receives our immediately spendable primary channel balance in
350-
/// remote-broadcasted commitment transactions. This key is static across every commitment
350+
/// counterparty-broadcasted commitment transactions. This key is static across every commitment
351351
/// transaction.
352352
#[no_mangle]
353353
pub extern "C" fn ChannelPublicKeys_get_payment_point(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
354354
let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.payment_point;
355355
crate::c_types::PublicKey::from_rust(&(*inner_val))
356356
}
357357
/// The public key which receives our immediately spendable primary channel balance in
358-
/// remote-broadcasted commitment transactions. This key is static across every commitment
358+
/// counterparty-broadcasted commitment transactions. This key is static across every commitment
359359
/// transaction.
360360
#[no_mangle]
361361
pub extern "C" fn ChannelPublicKeys_set_payment_point(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
@@ -484,7 +484,7 @@ pub(crate) extern "C" fn HTLCOutputInCommitment_clone_void(this_ptr: *const c_vo
484484
/// Whether the HTLC was \"offered\" (ie outbound in relation to this commitment transaction).
485485
/// Note that this is not the same as whether it is ountbound *from us*. To determine that you
486486
/// need to compare this value to whether the commitment transaction in question is that of
487-
/// the remote party or our own.
487+
/// the counterparty or our own.
488488
#[no_mangle]
489489
pub extern "C" fn HTLCOutputInCommitment_get_offered(this_ptr: &HTLCOutputInCommitment) -> bool {
490490
let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.offered;
@@ -493,7 +493,7 @@ pub extern "C" fn HTLCOutputInCommitment_get_offered(this_ptr: &HTLCOutputInComm
493493
/// Whether the HTLC was \"offered\" (ie outbound in relation to this commitment transaction).
494494
/// Note that this is not the same as whether it is ountbound *from us*. To determine that you
495495
/// need to compare this value to whether the commitment transaction in question is that of
496-
/// the remote party or our own.
496+
/// the counterparty or our own.
497497
#[no_mangle]
498498
pub extern "C" fn HTLCOutputInCommitment_set_offered(this_ptr: &mut HTLCOutputInCommitment, mut val: bool) {
499499
unsafe { &mut *this_ptr.inner }.offered = val;
@@ -573,7 +573,7 @@ pub extern "C" fn build_htlc_transaction(prev_hash: *const [u8; 32], mut feerate
573573
use lightning::ln::chan_utils::HolderCommitmentTransaction as nativeHolderCommitmentTransactionImport;
574574
type nativeHolderCommitmentTransaction = nativeHolderCommitmentTransactionImport;
575575

576-
/// We use this to track local commitment transactions and put off signing them until we are ready
576+
/// We use this to track holder commitment transactions and put off signing them until we are ready
577577
/// to broadcast. This class can be used inside a signer implementation to generate a signature
578578
/// given the relevant secret key.
579579
#[must_use]
@@ -658,29 +658,29 @@ pub extern "C" fn HolderCommitmentTransaction_get_feerate_per_kw(this_ptr: &Hold
658658
pub extern "C" fn HolderCommitmentTransaction_set_feerate_per_kw(this_ptr: &mut HolderCommitmentTransaction, mut val: u32) {
659659
unsafe { &mut *this_ptr.inner }.feerate_per_kw = val;
660660
}
661-
/// The HTLCs and remote htlc signatures which were included in this commitment transaction.
661+
/// The HTLCs and counterparty htlc signatures which were included in this commitment transaction.
662662
///
663663
/// Note that this includes all HTLCs, including ones which were considered dust and not
664664
/// actually included in the transaction as it appears on-chain, but who's value is burned as
665665
/// fees and not included in the to_local or to_remote outputs.
666666
///
667-
/// The remote HTLC signatures in the second element will always be set for non-dust HTLCs, ie
667+
/// The counterparty HTLC signatures in the second element will always be set for non-dust HTLCs, ie
668668
/// those for which transaction_output_index.is_some().
669669
#[no_mangle]
670670
pub extern "C" fn HolderCommitmentTransaction_set_per_htlc(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::derived::CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ) {
671671
let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { let (mut orig_val_0_0, mut orig_val_0_1) = item.to_rust(); let mut local_orig_val_0_1 = if orig_val_0_1.is_null() { None } else { Some( { orig_val_0_1.into_rust() }) }; let mut local_val_0 = (*unsafe { Box::from_raw(orig_val_0_0.take_ptr()) }, local_orig_val_0_1); local_val_0 }); };
672672
unsafe { &mut *this_ptr.inner }.per_htlc = local_val;
673673
}
674674
/// Generate a new HolderCommitmentTransaction based on a raw commitment transaction,
675-
/// remote signature and both parties keys.
675+
/// counterparty signature and both parties keys.
676676
///
677677
/// The unsigned transaction outputs must be consistent with htlc_data. This function
678678
/// only checks that the shape and amounts are consistent, but does not check the scriptPubkey.
679679
#[must_use]
680680
#[no_mangle]
681-
pub extern "C" fn HolderCommitmentTransaction_new_missing_holder_sig(mut unsigned_tx: crate::c_types::derived::CVec_u8Z, mut counterparty_sig: crate::c_types::Signature, our_funding_key: crate::c_types::PublicKey, their_funding_key: crate::c_types::PublicKey, mut local_keys: crate::ln::chan_utils::TxCreationKeys, mut feerate_per_kw: u32, mut htlc_data: crate::c_types::derived::CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ) -> crate::ln::chan_utils::HolderCommitmentTransaction {
682-
let mut local_htlc_data = Vec::new(); for mut item in htlc_data.into_rust().drain(..) { local_htlc_data.push( { let (mut orig_htlc_data_0_0, mut orig_htlc_data_0_1) = item.to_rust(); let mut local_orig_htlc_data_0_1 = if orig_htlc_data_0_1.is_null() { None } else { Some( { orig_htlc_data_0_1.into_rust() }) }; let mut local_htlc_data_0 = (*unsafe { Box::from_raw(orig_htlc_data_0_0.take_ptr()) }, local_orig_htlc_data_0_1); local_htlc_data_0 }); };
683-
let mut ret = lightning::ln::chan_utils::HolderCommitmentTransaction::new_missing_holder_sig(::bitcoin::consensus::encode::deserialize(&unsigned_tx.into_rust()[..]).unwrap(), counterparty_sig.into_rust(), &our_funding_key.into_rust(), &their_funding_key.into_rust(), *unsafe { Box::from_raw(local_keys.take_ptr()) }, feerate_per_kw, local_htlc_data);
681+
pub extern "C" fn HolderCommitmentTransaction_new_missing_holder_sig(mut unsigned_tx: crate::c_types::derived::CVec_u8Z, mut counterparty_sig: crate::c_types::Signature, holder_funding_key: crate::c_types::PublicKey, counterparty_funding_key: crate::c_types::PublicKey, mut keys: crate::ln::chan_utils::TxCreationKeys, mut feerate_per_kw: u32, mut htlc_data: crate::c_types::derived::CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ) -> crate::ln::chan_utils::HolderCommitmentTransaction {
682+
let mut holder_htlc_data = Vec::new(); for mut item in htlc_data.into_rust().drain(..) { holder_htlc_data.push( { let (mut orig_htlc_data_0_0, mut orig_htlc_data_0_1) = item.to_rust(); let mut holder_orig_htlc_data_0_1 = if orig_htlc_data_0_1.is_null() { None } else { Some( { orig_htlc_data_0_1.into_rust() }) }; let mut holder_htlc_data_0 = (*unsafe { Box::from_raw(orig_htlc_data_0_0.take_ptr()) }, holder_orig_htlc_data_0_1); holder_htlc_data_0 }); };
683+
let mut ret = lightning::ln::chan_utils::HolderCommitmentTransaction::new_missing_holder_sig(::bitcoin::consensus::encode::deserialize(&unsigned_tx.into_rust()[..]).unwrap(), counterparty_sig.into_rust(), &holder_funding_key.into_rust(), &counterparty_funding_key.into_rust(), *unsafe { Box::from_raw(keys.take_ptr()) }, feerate_per_kw, holder_htlc_data);
684684
crate::ln::chan_utils::HolderCommitmentTransaction { inner: Box::into_raw(Box::new(ret)), is_owned: true }
685685
}
686686

@@ -693,7 +693,7 @@ pub extern "C" fn HolderCommitmentTransaction_trust_key_derivation(this_arg: &Ho
693693
crate::ln::chan_utils::TxCreationKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
694694
}
695695

696-
/// Get the txid of the local commitment transaction contained in this
696+
/// Get the txid of the holder commitment transaction contained in this
697697
/// HolderCommitmentTransaction
698698
#[must_use]
699699
#[no_mangle]
@@ -708,7 +708,7 @@ pub extern "C" fn HolderCommitmentTransaction_txid(this_arg: &HolderCommitmentTr
708708
/// by your ChannelKeys.
709709
/// Funding redeemscript is script locking funding_outpoint. This is the mutlsig script
710710
/// between your own funding key and your counterparty's. Currently, this is provided in
711-
/// ChannelKeys::sign_local_commitment() calls directly.
711+
/// ChannelKeys::sign_holder_commitment() calls directly.
712712
/// Channel value is amount locked in funding_outpoint.
713713
#[must_use]
714714
#[no_mangle]
@@ -725,8 +725,8 @@ pub extern "C" fn HolderCommitmentTransaction_get_holder_sig(this_arg: &HolderCo
725725
/// included.
726726
#[must_use]
727727
#[no_mangle]
728-
pub extern "C" fn HolderCommitmentTransaction_get_htlc_sigs(this_arg: &HolderCommitmentTransaction, htlc_base_key: *const [u8; 32], mut local_csv: u16) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ {
729-
let mut ret = unsafe { &*this_arg.inner }.get_htlc_sigs(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *htlc_base_key}[..]).unwrap(), local_csv, &bitcoin::secp256k1::Secp256k1::new());
728+
pub extern "C" fn HolderCommitmentTransaction_get_htlc_sigs(this_arg: &HolderCommitmentTransaction, htlc_base_key: *const [u8; 32], mut counterparty_selected_contest_delay: u16) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ {
729+
let mut ret = unsafe { &*this_arg.inner }.get_htlc_sigs(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *htlc_base_key}[..]).unwrap(), counterparty_selected_contest_delay, &bitcoin::secp256k1::Secp256k1::new());
730730
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for item in o.drain(..) { local_ret_0.push( { let mut local_ret_0_0 = if item.is_none() { crate::c_types::Signature::null() } else { { crate::c_types::Signature::from_rust(&(item.unwrap())) } }; local_ret_0_0 }); }; local_ret_0.into() }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) };
731731
local_ret
732732
}

0 commit comments

Comments
 (0)