Overhaul LocalCommitmentTx to new nomenclature
authorAntoine Riard <ariard@student.42.fr>
Mon, 7 Sep 2020 00:07:11 +0000 (20:07 -0400)
committerAntoine Riard <ariard@student.42.fr>
Mon, 14 Sep 2020 18:39:47 +0000 (14:39 -0400)
lightning-c-bindings/src/chain/keysinterface.rs
lightning-c-bindings/src/ln/chan_utils.rs
lightning/src/chain/keysinterface.rs
lightning/src/ln/chan_utils.rs
lightning/src/ln/channel.rs
lightning/src/ln/channelmonitor.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/onchaintx.rs
lightning/src/util/enforcing_trait_impls.rs

index 11e35f246da5b0f503bb53700d3d94231b3bf8c6..53a951e8005cf8d4e055ed20c2ac14e22dd4e8f5 100644 (file)
@@ -43,7 +43,7 @@ pub enum SpendableOutputDescriptor {
        /// using chan_utils::derive_public_key and only the delayed_payment_basepoint which appears in
        /// ChannelKeys::pubkeys().
        ///
-       /// To derive the counterparty_revocation_pubkey provided here (which is used in the witness
+       /// To derive the revocation_pubkey provided here (which is used in the witness
        /// script generation), you must pass the remote revocation_basepoint (which appears in the
        /// call to ChannelKeys::on_accept) and the provided per_commitment point
        /// to chan_utils::derive_public_revocation_key.
@@ -58,7 +58,7 @@ pub enum SpendableOutputDescriptor {
                to_self_delay: u16,
                output: crate::c_types::TxOut,
                key_derivation_params: crate::c_types::derived::C2Tuple_u64u64Z,
-               counterparty_revocation_pubkey: crate::c_types::PublicKey,
+               revocation_pubkey: crate::c_types::PublicKey,
        },
        /// An output to a P2WPKH, spendable exclusively by our payment key (ie the private key which
        /// corresponds to the public key in ChannelKeys::pubkeys().payment_point).
@@ -86,21 +86,21 @@ impl SpendableOutputDescriptor {
                                        output: output_nonref.into_rust(),
                                }
                        },
-                       SpendableOutputDescriptor::DynamicOutputP2WSH {ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref key_derivation_params, ref counterparty_revocation_pubkey, } => {
+                       SpendableOutputDescriptor::DynamicOutputP2WSH {ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref key_derivation_params, ref revocation_pubkey, } => {
                                let mut outpoint_nonref = (*outpoint).clone();
                                let mut per_commitment_point_nonref = (*per_commitment_point).clone();
                                let mut to_self_delay_nonref = (*to_self_delay).clone();
                                let mut output_nonref = (*output).clone();
                                let mut key_derivation_params_nonref = (*key_derivation_params).clone();
                                let (mut orig_key_derivation_params_nonref_0, mut orig_key_derivation_params_nonref_1) = key_derivation_params_nonref.to_rust(); let mut local_key_derivation_params_nonref = (orig_key_derivation_params_nonref_0, orig_key_derivation_params_nonref_1);
-                               let mut counterparty_revocation_pubkey_nonref = (*counterparty_revocation_pubkey).clone();
+                               let mut revocation_pubkey_nonref = (*revocation_pubkey).clone();
                                nativeSpendableOutputDescriptor::DynamicOutputP2WSH {
                                        outpoint: *unsafe { Box::from_raw(outpoint_nonref.take_ptr()) },
                                        per_commitment_point: per_commitment_point_nonref.into_rust(),
                                        to_self_delay: to_self_delay_nonref,
                                        output: output_nonref.into_rust(),
                                        key_derivation_params: local_key_derivation_params_nonref,
-                                       counterparty_revocation_pubkey: counterparty_revocation_pubkey_nonref.into_rust(),
+                                       revocation_pubkey: revocation_pubkey_nonref.into_rust(),
                                }
                        },
                        SpendableOutputDescriptor::StaticOutputCounterpartyPayment {ref outpoint, ref output, ref key_derivation_params, } => {
@@ -125,7 +125,7 @@ impl SpendableOutputDescriptor {
                                        output: output.into_rust(),
                                }
                        },
-                       SpendableOutputDescriptor::DynamicOutputP2WSH {mut outpoint, mut per_commitment_point, mut to_self_delay, mut output, mut key_derivation_params, mut counterparty_revocation_pubkey, } => {
+                       SpendableOutputDescriptor::DynamicOutputP2WSH {mut outpoint, mut per_commitment_point, mut to_self_delay, mut output, mut key_derivation_params, mut revocation_pubkey, } => {
                                let (mut orig_key_derivation_params_0, mut orig_key_derivation_params_1) = key_derivation_params.to_rust(); let mut local_key_derivation_params = (orig_key_derivation_params_0, orig_key_derivation_params_1);
                                nativeSpendableOutputDescriptor::DynamicOutputP2WSH {
                                        outpoint: *unsafe { Box::from_raw(outpoint.take_ptr()) },
@@ -133,7 +133,7 @@ impl SpendableOutputDescriptor {
                                        to_self_delay: to_self_delay,
                                        output: output.into_rust(),
                                        key_derivation_params: local_key_derivation_params,
-                                       counterparty_revocation_pubkey: counterparty_revocation_pubkey.into_rust(),
+                                       revocation_pubkey: revocation_pubkey.into_rust(),
                                }
                        },
                        SpendableOutputDescriptor::StaticOutputCounterpartyPayment {mut outpoint, mut output, mut key_derivation_params, } => {
@@ -157,21 +157,21 @@ impl SpendableOutputDescriptor {
                                        output: crate::c_types::TxOut::from_rust(output_nonref),
                                }
                        },
-                       nativeSpendableOutputDescriptor::DynamicOutputP2WSH {ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref key_derivation_params, ref counterparty_revocation_pubkey, } => {
+                       nativeSpendableOutputDescriptor::DynamicOutputP2WSH {ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref key_derivation_params, ref revocation_pubkey, } => {
                                let mut outpoint_nonref = (*outpoint).clone();
                                let mut per_commitment_point_nonref = (*per_commitment_point).clone();
                                let mut to_self_delay_nonref = (*to_self_delay).clone();
                                let mut output_nonref = (*output).clone();
                                let mut key_derivation_params_nonref = (*key_derivation_params).clone();
                                let (mut orig_key_derivation_params_nonref_0, mut orig_key_derivation_params_nonref_1) = key_derivation_params_nonref; let mut local_key_derivation_params_nonref = (orig_key_derivation_params_nonref_0, orig_key_derivation_params_nonref_1).into();
-                               let mut counterparty_revocation_pubkey_nonref = (*counterparty_revocation_pubkey).clone();
+                               let mut revocation_pubkey_nonref = (*revocation_pubkey).clone();
                                SpendableOutputDescriptor::DynamicOutputP2WSH {
                                        outpoint: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(outpoint_nonref)), is_owned: true },
                                        per_commitment_point: crate::c_types::PublicKey::from_rust(&per_commitment_point_nonref),
                                        to_self_delay: to_self_delay_nonref,
                                        output: crate::c_types::TxOut::from_rust(output_nonref),
                                        key_derivation_params: local_key_derivation_params_nonref,
-                                       counterparty_revocation_pubkey: crate::c_types::PublicKey::from_rust(&counterparty_revocation_pubkey_nonref),
+                                       revocation_pubkey: crate::c_types::PublicKey::from_rust(&revocation_pubkey_nonref),
                                }
                        },
                        nativeSpendableOutputDescriptor::StaticOutputCounterpartyPayment {ref outpoint, ref output, ref key_derivation_params, } => {
@@ -196,7 +196,7 @@ impl SpendableOutputDescriptor {
                                        output: crate::c_types::TxOut::from_rust(output),
                                }
                        },
-                       nativeSpendableOutputDescriptor::DynamicOutputP2WSH {mut outpoint, mut per_commitment_point, mut to_self_delay, mut output, mut key_derivation_params, mut counterparty_revocation_pubkey, } => {
+                       nativeSpendableOutputDescriptor::DynamicOutputP2WSH {mut outpoint, mut per_commitment_point, mut to_self_delay, mut output, mut key_derivation_params, mut revocation_pubkey, } => {
                                let (mut orig_key_derivation_params_0, mut orig_key_derivation_params_1) = key_derivation_params; let mut local_key_derivation_params = (orig_key_derivation_params_0, orig_key_derivation_params_1).into();
                                SpendableOutputDescriptor::DynamicOutputP2WSH {
                                        outpoint: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(outpoint)), is_owned: true },
@@ -204,7 +204,7 @@ impl SpendableOutputDescriptor {
                                        to_self_delay: to_self_delay,
                                        output: crate::c_types::TxOut::from_rust(output),
                                        key_derivation_params: local_key_derivation_params,
-                                       counterparty_revocation_pubkey: crate::c_types::PublicKey::from_rust(&counterparty_revocation_pubkey),
+                                       revocation_pubkey: crate::c_types::PublicKey::from_rust(&revocation_pubkey),
                                }
                        },
                        nativeSpendableOutputDescriptor::StaticOutputCounterpartyPayment {mut outpoint, mut output, mut key_derivation_params, } => {
@@ -282,7 +282,7 @@ pub struct ChannelKeys {
        /// that it will not be called multiple times.
        /// An external signer implementation should check that the commitment has not been revoked.
        #[must_use]
-       pub sign_holder_commitment: extern "C" fn (this_arg: *const c_void, holder_commitment_tx: &crate::ln::chan_utils::LocalCommitmentTransaction) -> crate::c_types::derived::CResult_SignatureNoneZ,
+       pub sign_holder_commitment: extern "C" fn (this_arg: *const c_void, holder_commitment_tx: &crate::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_SignatureNoneZ,
        /// Create a signature for each HTLC transaction spending a holder commitment transaction.
        ///
        /// Unlike sign_holder_commitment, this may be called multiple times with *different*
@@ -297,7 +297,7 @@ pub struct ChannelKeys {
        /// a corresponding None should be included in the return value. All other positions in the
        /// return value must contain a signature.
        #[must_use]
-       pub sign_holder_commitment_htlc_transactions: extern "C" fn (this_arg: *const c_void, holder_commitment_tx: &crate::ln::chan_utils::LocalCommitmentTransaction) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ,
+       pub sign_holder_commitment_htlc_transactions: extern "C" fn (this_arg: *const c_void, holder_commitment_tx: &crate::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ,
        /// Create a signature for the given input in a transaction spending an HTLC or commitment
        /// transaction output when our counterparty broadcasts an old state.
        ///
@@ -413,13 +413,13 @@ impl rustChannelKeys for ChannelKeys {
                let mut local_ret = match ret.result_ok { true => Ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = (*unsafe { Box::from_raw(ret.contents.result.take_ptr()) }).to_rust(); let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.into_rust().drain(..) { local_orig_ret_0_1.push( { item.into_rust() }); }; let mut local_ret_0 = (orig_ret_0_0.into_rust(), local_orig_ret_0_1); local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(ret.contents.err.take_ptr()) })*/ })};
                local_ret
        }
-       fn sign_holder_commitment<T:bitcoin::secp256k1::Signing + bitcoin::secp256k1::Verification>(&self, local_commitment_tx: &lightning::ln::chan_utils::LocalCommitmentTransaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1<T>) -> Result<bitcoin::secp256k1::Signature, ()> {
-               let mut ret = (self.sign_holder_commitment)(self.this_arg, &crate::ln::chan_utils::LocalCommitmentTransaction { inner: unsafe { (local_commitment_tx as *const _) as *mut _ }, is_owned: false });
+       fn sign_holder_commitment<T:bitcoin::secp256k1::Signing + bitcoin::secp256k1::Verification>(&self, local_commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1<T>) -> Result<bitcoin::secp256k1::Signature, ()> {
+               let mut ret = (self.sign_holder_commitment)(self.this_arg, &crate::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { (local_commitment_tx as *const _) as *mut _ }, is_owned: false });
                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()) })*/ })};
                local_ret
        }
-       fn sign_holder_commitment_htlc_transactions<T:bitcoin::secp256k1::Signing + bitcoin::secp256k1::Verification>(&self, local_commitment_tx: &lightning::ln::chan_utils::LocalCommitmentTransaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1<T>) -> Result<Vec<Option<bitcoin::secp256k1::Signature>>, ()> {
-               let mut ret = (self.sign_holder_commitment_htlc_transactions)(self.this_arg, &crate::ln::chan_utils::LocalCommitmentTransaction { inner: unsafe { (local_commitment_tx as *const _) as *mut _ }, is_owned: false });
+       fn sign_holder_commitment_htlc_transactions<T:bitcoin::secp256k1::Signing + bitcoin::secp256k1::Verification>(&self, local_commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1<T>) -> Result<Vec<Option<bitcoin::secp256k1::Signature>>, ()> {
+               let mut ret = (self.sign_holder_commitment_htlc_transactions)(self.this_arg, &crate::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { (local_commitment_tx as *const _) as *mut _ }, is_owned: false });
                let mut local_ret = match ret.result_ok { true => Ok( { let mut local_ret_0 = Vec::new(); for mut item in (*unsafe { Box::from_raw(ret.contents.result.take_ptr()) }).into_rust().drain(..) { local_ret_0.push( { let mut local_ret_0_0 = if item.is_null() { None } else { Some( { item.into_rust() }) }; local_ret_0_0 }); }; local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(ret.contents.err.take_ptr()) })*/ })};
                local_ret
        }
@@ -757,13 +757,13 @@ extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_counterparty_commitment(this_
        local_ret
 }
 #[must_use]
-extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_holder_commitment(this_arg: *const c_void, local_commitment_tx: &crate::ln::chan_utils::LocalCommitmentTransaction) -> crate::c_types::derived::CResult_SignatureNoneZ {
+extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_holder_commitment(this_arg: *const c_void, local_commitment_tx: &crate::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_SignatureNoneZ {
        let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_holder_commitment(unsafe { &*local_commitment_tx.inner }, &bitcoin::secp256k1::Secp256k1::new());
        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*/ }) };
        local_ret
 }
 #[must_use]
-extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_holder_commitment_htlc_transactions(this_arg: *const c_void, local_commitment_tx: &crate::ln::chan_utils::LocalCommitmentTransaction) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ {
+extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_holder_commitment_htlc_transactions(this_arg: *const c_void, local_commitment_tx: &crate::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ {
        let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_holder_commitment_htlc_transactions(unsafe { &*local_commitment_tx.inner }, &bitcoin::secp256k1::Secp256k1::new());
        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*/ }) };
        local_ret
index c946ad52acc5a217226c3d573a437e15ab2a622a..642353f09e207d2563b42abe6ce18dbda33210ff 100644 (file)
@@ -570,22 +570,22 @@ pub extern "C" fn build_htlc_transaction(prev_hash: *const [u8; 32], mut feerate
 }
 
 
-use lightning::ln::chan_utils::LocalCommitmentTransaction as nativeLocalCommitmentTransactionImport;
-type nativeLocalCommitmentTransaction = nativeLocalCommitmentTransactionImport;
+use lightning::ln::chan_utils::HolderCommitmentTransaction as nativeHolderCommitmentTransactionImport;
+type nativeHolderCommitmentTransaction = nativeHolderCommitmentTransactionImport;
 
 /// We use this to track local commitment transactions and put off signing them until we are ready
 /// to broadcast. This class can be used inside a signer implementation to generate a signature
 /// given the relevant secret key.
 #[must_use]
 #[repr(C)]
-pub struct LocalCommitmentTransaction {
+pub struct HolderCommitmentTransaction {
        /// Nearly everyhwere, inner must be non-null, however in places where
        /// the Rust equivalent takes an Option, it may be set to null to indicate None.
-       pub inner: *mut nativeLocalCommitmentTransaction,
+       pub inner: *mut nativeHolderCommitmentTransaction,
        pub is_owned: bool,
 }
 
-impl Drop for LocalCommitmentTransaction {
+impl Drop for HolderCommitmentTransaction {
        fn drop(&mut self) {
                if self.is_owned && !self.inner.is_null() {
                        let _ = unsafe { Box::from_raw(self.inner) };
@@ -593,23 +593,23 @@ impl Drop for LocalCommitmentTransaction {
        }
 }
 #[no_mangle]
-pub extern "C" fn LocalCommitmentTransaction_free(this_ptr: LocalCommitmentTransaction) { }
+pub extern "C" fn HolderCommitmentTransaction_free(this_ptr: HolderCommitmentTransaction) { }
 #[allow(unused)]
 /// Used only if an object of this type is returned as a trait impl by a method
-extern "C" fn LocalCommitmentTransaction_free_void(this_ptr: *mut c_void) {
-       unsafe { let _ = Box::from_raw(this_ptr as *mut nativeLocalCommitmentTransaction); }
+extern "C" fn HolderCommitmentTransaction_free_void(this_ptr: *mut c_void) {
+       unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHolderCommitmentTransaction); }
 }
 #[allow(unused)]
 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
-impl LocalCommitmentTransaction {
-       pub(crate) fn take_ptr(mut self) -> *mut nativeLocalCommitmentTransaction {
+impl HolderCommitmentTransaction {
+       pub(crate) fn take_ptr(mut self) -> *mut nativeHolderCommitmentTransaction {
                assert!(self.is_owned);
                let ret = self.inner;
                self.inner = std::ptr::null_mut();
                ret
        }
 }
-impl Clone for LocalCommitmentTransaction {
+impl Clone for HolderCommitmentTransaction {
        fn clone(&self) -> Self {
                Self {
                        inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
@@ -619,43 +619,43 @@ impl Clone for LocalCommitmentTransaction {
 }
 #[allow(unused)]
 /// Used only if an object of this type is returned as a trait impl by a method
-pub(crate) extern "C" fn LocalCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
-       Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeLocalCommitmentTransaction)).clone() })) as *mut c_void
+pub(crate) extern "C" fn HolderCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
+       Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHolderCommitmentTransaction)).clone() })) as *mut c_void
 }
 /// The commitment transaction itself, in unsigned form.
 #[no_mangle]
-pub extern "C" fn LocalCommitmentTransaction_get_unsigned_tx(this_ptr: &LocalCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
+pub extern "C" fn HolderCommitmentTransaction_get_unsigned_tx(this_ptr: &HolderCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
        let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.unsigned_tx;
        let mut local_inner_val = ::bitcoin::consensus::encode::serialize(inner_val);
        local_inner_val.into()
 }
 /// The commitment transaction itself, in unsigned form.
 #[no_mangle]
-pub extern "C" fn LocalCommitmentTransaction_set_unsigned_tx(this_ptr: &mut LocalCommitmentTransaction, mut val: crate::c_types::derived::CVec_u8Z) {
+pub extern "C" fn HolderCommitmentTransaction_set_unsigned_tx(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::derived::CVec_u8Z) {
        unsafe { &mut *this_ptr.inner }.unsigned_tx = ::bitcoin::consensus::encode::deserialize(&val.into_rust()[..]).unwrap();
 }
 /// Our counterparty's signature for the transaction, above.
 #[no_mangle]
-pub extern "C" fn LocalCommitmentTransaction_get_their_sig(this_ptr: &LocalCommitmentTransaction) -> crate::c_types::Signature {
-       let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.their_sig;
+pub extern "C" fn HolderCommitmentTransaction_get_counterparty_sig(this_ptr: &HolderCommitmentTransaction) -> crate::c_types::Signature {
+       let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.counterparty_sig;
        crate::c_types::Signature::from_rust(&(*inner_val))
 }
 /// Our counterparty's signature for the transaction, above.
 #[no_mangle]
-pub extern "C" fn LocalCommitmentTransaction_set_their_sig(this_ptr: &mut LocalCommitmentTransaction, mut val: crate::c_types::Signature) {
-       unsafe { &mut *this_ptr.inner }.their_sig = val.into_rust();
+pub extern "C" fn HolderCommitmentTransaction_set_counterparty_sig(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::Signature) {
+       unsafe { &mut *this_ptr.inner }.counterparty_sig = val.into_rust();
 }
 /// The feerate paid per 1000-weight-unit in this commitment transaction. This value is
 /// controlled by the channel initiator.
 #[no_mangle]
-pub extern "C" fn LocalCommitmentTransaction_get_feerate_per_kw(this_ptr: &LocalCommitmentTransaction) -> u32 {
+pub extern "C" fn HolderCommitmentTransaction_get_feerate_per_kw(this_ptr: &HolderCommitmentTransaction) -> u32 {
        let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.feerate_per_kw;
        (*inner_val)
 }
 /// The feerate paid per 1000-weight-unit in this commitment transaction. This value is
 /// controlled by the channel initiator.
 #[no_mangle]
-pub extern "C" fn LocalCommitmentTransaction_set_feerate_per_kw(this_ptr: &mut LocalCommitmentTransaction, mut val: u32) {
+pub extern "C" fn HolderCommitmentTransaction_set_feerate_per_kw(this_ptr: &mut HolderCommitmentTransaction, mut val: u32) {
        unsafe { &mut *this_ptr.inner }.feerate_per_kw = val;
 }
 /// The HTLCs and remote htlc signatures which were included in this commitment transaction.
@@ -667,37 +667,37 @@ pub extern "C" fn LocalCommitmentTransaction_set_feerate_per_kw(this_ptr: &mut L
 /// The remote HTLC signatures in the second element will always be set for non-dust HTLCs, ie
 /// those for which transaction_output_index.is_some().
 #[no_mangle]
-pub extern "C" fn LocalCommitmentTransaction_set_per_htlc(this_ptr: &mut LocalCommitmentTransaction, mut val: crate::c_types::derived::CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ) {
+pub extern "C" fn HolderCommitmentTransaction_set_per_htlc(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::derived::CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ) {
        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 }); };
        unsafe { &mut *this_ptr.inner }.per_htlc = local_val;
 }
-/// Generate a new LocalCommitmentTransaction based on a raw commitment transaction,
+/// Generate a new HolderCommitmentTransaction based on a raw commitment transaction,
 /// remote signature and both parties keys.
 ///
 /// The unsigned transaction outputs must be consistent with htlc_data.  This function
 /// only checks that the shape and amounts are consistent, but does not check the scriptPubkey.
 #[must_use]
 #[no_mangle]
-pub extern "C" fn LocalCommitmentTransaction_new_missing_local_sig(mut unsigned_tx: crate::c_types::derived::CVec_u8Z, mut their_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::LocalCommitmentTransaction {
+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 {
        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 }); };
-       let mut ret = lightning::ln::chan_utils::LocalCommitmentTransaction::new_missing_local_sig(::bitcoin::consensus::encode::deserialize(&unsigned_tx.into_rust()[..]).unwrap(), their_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);
-       crate::ln::chan_utils::LocalCommitmentTransaction { inner: Box::into_raw(Box::new(ret)), is_owned: true }
+       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);
+       crate::ln::chan_utils::HolderCommitmentTransaction { inner: Box::into_raw(Box::new(ret)), is_owned: true }
 }
 
 /// The pre-calculated transaction creation public keys.
 /// An external validating signer should not trust these keys.
 #[must_use]
 #[no_mangle]
-pub extern "C" fn LocalCommitmentTransaction_trust_key_derivation(this_arg: &LocalCommitmentTransaction) -> crate::ln::chan_utils::TxCreationKeys {
+pub extern "C" fn HolderCommitmentTransaction_trust_key_derivation(this_arg: &HolderCommitmentTransaction) -> crate::ln::chan_utils::TxCreationKeys {
        let mut ret = unsafe { &*this_arg.inner }.trust_key_derivation();
        crate::ln::chan_utils::TxCreationKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
 }
 
 /// Get the txid of the local commitment transaction contained in this
-/// LocalCommitmentTransaction
+/// HolderCommitmentTransaction
 #[must_use]
 #[no_mangle]
-pub extern "C" fn LocalCommitmentTransaction_txid(this_arg: &LocalCommitmentTransaction) -> crate::c_types::ThirtyTwoBytes {
+pub extern "C" fn HolderCommitmentTransaction_txid(this_arg: &HolderCommitmentTransaction) -> crate::c_types::ThirtyTwoBytes {
        let mut ret = unsafe { &*this_arg.inner }.txid();
        crate::c_types::ThirtyTwoBytes { data: ret.into_inner() }
 }
@@ -712,8 +712,8 @@ pub extern "C" fn LocalCommitmentTransaction_txid(this_arg: &LocalCommitmentTran
 /// Channel value is amount locked in funding_outpoint.
 #[must_use]
 #[no_mangle]
-pub extern "C" fn LocalCommitmentTransaction_get_local_sig(this_arg: &LocalCommitmentTransaction, funding_key: *const [u8; 32], funding_redeemscript: crate::c_types::u8slice, mut channel_value_satoshis: u64) -> crate::c_types::Signature {
-       let mut ret = unsafe { &*this_arg.inner }.get_local_sig(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *funding_key}[..]).unwrap(), &::bitcoin::blockdata::script::Script::from(Vec::from(funding_redeemscript.to_slice())), channel_value_satoshis, &bitcoin::secp256k1::Secp256k1::new());
+pub extern "C" fn HolderCommitmentTransaction_get_holder_sig(this_arg: &HolderCommitmentTransaction, funding_key: *const [u8; 32], funding_redeemscript: crate::c_types::u8slice, mut channel_value_satoshis: u64) -> crate::c_types::Signature {
+       let mut ret = unsafe { &*this_arg.inner }.get_holder_sig(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *funding_key}[..]).unwrap(), &::bitcoin::blockdata::script::Script::from(Vec::from(funding_redeemscript.to_slice())), channel_value_satoshis, &bitcoin::secp256k1::Secp256k1::new());
        crate::c_types::Signature::from_rust(&ret)
 }
 
@@ -725,21 +725,21 @@ pub extern "C" fn LocalCommitmentTransaction_get_local_sig(this_arg: &LocalCommi
 /// included.
 #[must_use]
 #[no_mangle]
-pub extern "C" fn LocalCommitmentTransaction_get_htlc_sigs(this_arg: &LocalCommitmentTransaction, htlc_base_key: *const [u8; 32], mut local_csv: u16) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ {
+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 {
        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());
        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*/ }) };
        local_ret
 }
 
 #[no_mangle]
-pub extern "C" fn LocalCommitmentTransaction_write(obj: *const LocalCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
+pub extern "C" fn HolderCommitmentTransaction_write(obj: *const HolderCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
        crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
 }
 #[no_mangle]
-pub extern "C" fn LocalCommitmentTransaction_read(ser: crate::c_types::u8slice) -> LocalCommitmentTransaction {
+pub extern "C" fn HolderCommitmentTransaction_read(ser: crate::c_types::u8slice) -> HolderCommitmentTransaction {
        if let Ok(res) = crate::c_types::deserialize_obj(ser) {
-               LocalCommitmentTransaction { inner: Box::into_raw(Box::new(res)), is_owned: true }
+               HolderCommitmentTransaction { inner: Box::into_raw(Box::new(res)), is_owned: true }
        } else {
-               LocalCommitmentTransaction { inner: std::ptr::null_mut(), is_owned: true }
+               HolderCommitmentTransaction { inner: std::ptr::null_mut(), is_owned: true }
        }
 }
index 1861a062937cf8b2101663b16d0f7f45e30ef1b7..eb8747e6d0a934264871132bbd3601848dff651e 100644 (file)
@@ -33,7 +33,7 @@ use util::ser::{Writeable, Writer, Readable};
 
 use chain::transaction::OutPoint;
 use ln::chan_utils;
-use ln::chan_utils::{HTLCOutputInCommitment, make_funding_redeemscript, ChannelPublicKeys, LocalCommitmentTransaction, PreCalculatedTxCreationKeys};
+use ln::chan_utils::{HTLCOutputInCommitment, make_funding_redeemscript, ChannelPublicKeys, HolderCommitmentTransaction, PreCalculatedTxCreationKeys};
 use ln::msgs::UnsignedChannelAnnouncement;
 
 use std::sync::atomic::{AtomicUsize, Ordering};
@@ -77,7 +77,7 @@ pub enum SpendableOutputDescriptor {
        /// using chan_utils::derive_public_key and only the delayed_payment_basepoint which appears in
        /// ChannelKeys::pubkeys().
        ///
-       /// To derive the counterparty_revocation_pubkey provided here (which is used in the witness
+       /// To derive the revocation_pubkey provided here (which is used in the witness
        /// script generation), you must pass the counterparty revocation_basepoint (which appears in the
        /// call to ChannelKeys::on_accept) and the provided per_commitment point
        /// to chan_utils::derive_public_revocation_key.
@@ -101,8 +101,8 @@ pub enum SpendableOutputDescriptor {
                /// The channel keys state used to proceed to derivation of signing key. Must
                /// be pass to KeysInterface::derive_channel_keys.
                key_derivation_params: (u64, u64),
-               /// The counterparty_revocation_pubkey used to derive witnessScript
-               counterparty_revocation_pubkey: PublicKey
+               /// The revocation_pubkey used to derive witnessScript
+               revocation_pubkey: PublicKey
        },
        /// An output to a P2WPKH, spendable exclusively by our payment key (ie the private key which
        /// corresponds to the public key in ChannelKeys::pubkeys().payment_point).
@@ -130,7 +130,7 @@ impl Writeable for SpendableOutputDescriptor {
                                outpoint.write(writer)?;
                                output.write(writer)?;
                        },
-                       &SpendableOutputDescriptor::DynamicOutputP2WSH { ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref key_derivation_params, ref counterparty_revocation_pubkey } => {
+                       &SpendableOutputDescriptor::DynamicOutputP2WSH { ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref key_derivation_params, ref revocation_pubkey } => {
                                1u8.write(writer)?;
                                outpoint.write(writer)?;
                                per_commitment_point.write(writer)?;
@@ -138,7 +138,7 @@ impl Writeable for SpendableOutputDescriptor {
                                output.write(writer)?;
                                key_derivation_params.0.write(writer)?;
                                key_derivation_params.1.write(writer)?;
-                               counterparty_revocation_pubkey.write(writer)?;
+                               revocation_pubkey.write(writer)?;
                        },
                        &SpendableOutputDescriptor::StaticOutputCounterpartyPayment { ref outpoint, ref output, ref key_derivation_params } => {
                                2u8.write(writer)?;
@@ -165,7 +165,7 @@ impl Readable for SpendableOutputDescriptor {
                                to_self_delay: Readable::read(reader)?,
                                output: Readable::read(reader)?,
                                key_derivation_params: (Readable::read(reader)?, Readable::read(reader)?),
-                               counterparty_revocation_pubkey: Readable::read(reader)?,
+                               revocation_pubkey: Readable::read(reader)?,
                        }),
                        2u8 => Ok(SpendableOutputDescriptor::StaticOutputCounterpartyPayment {
                                outpoint: Readable::read(reader)?,
@@ -242,14 +242,14 @@ pub trait ChannelKeys : Send+Clone {
        //
        // TODO: Document the things someone using this interface should enforce before signing.
        // TODO: Add more input vars to enable better checking (preferably removing commitment_tx and
-       fn sign_holder_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()>;
+       fn sign_holder_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()>;
 
        /// Same as sign_holder_commitment, but exists only for tests to get access to holder commitment
        /// transactions which will be broadcasted later, after the channel has moved on to a newer
        /// state. Thus, needs its own method as sign_holder_commitment may enforce that we only ever
        /// get called once.
        #[cfg(any(test,feature = "unsafe_revoked_tx_signing"))]
-       fn unsafe_sign_holder_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()>;
+       fn unsafe_sign_holder_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()>;
 
        /// Create a signature for each HTLC transaction spending a holder's commitment transaction.
        ///
@@ -264,7 +264,7 @@ pub trait ChannelKeys : Send+Clone {
        /// (implying they were considered dust at the time the commitment transaction was negotiated),
        /// a corresponding None should be included in the return value. All other positions in the
        /// return value must contain a signature.
-       fn sign_holder_commitment_htlc_transactions<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Vec<Option<Signature>>, ()>;
+       fn sign_holder_commitment_htlc_transactions<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Vec<Option<Signature>>, ()>;
 
        /// Create a signature for the given input in a transaction spending an HTLC or commitment
        /// transaction output when our counterparty broadcasts an old state.
@@ -499,24 +499,24 @@ impl ChannelKeys for InMemoryChannelKeys {
                Ok((commitment_sig, htlc_sigs))
        }
 
-       fn sign_holder_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
+       fn sign_holder_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
                let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
                let counterparty_channel_data = self.accepted_channel_data.as_ref().expect("must accept before signing");
                let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &counterparty_channel_data.counterparty_channel_pubkeys.funding_pubkey);
 
-               Ok(holder_commitment_tx.get_local_sig(&self.funding_key, &channel_funding_redeemscript, self.channel_value_satoshis, secp_ctx))
+               Ok(holder_commitment_tx.get_holder_sig(&self.funding_key, &channel_funding_redeemscript, self.channel_value_satoshis, secp_ctx))
        }
 
        #[cfg(any(test,feature = "unsafe_revoked_tx_signing"))]
-       fn unsafe_sign_holder_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
+       fn unsafe_sign_holder_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
                let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
                let counterparty_channel_pubkeys = &self.accepted_channel_data.as_ref().expect("must accept before signing").counterparty_channel_pubkeys;
                let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &counterparty_channel_pubkeys.funding_pubkey);
 
-               Ok(holder_commitment_tx.get_local_sig(&self.funding_key, &channel_funding_redeemscript, self.channel_value_satoshis, secp_ctx))
+               Ok(holder_commitment_tx.get_holder_sig(&self.funding_key, &channel_funding_redeemscript, self.channel_value_satoshis, secp_ctx))
        }
 
-       fn sign_holder_commitment_htlc_transactions<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Vec<Option<Signature>>, ()> {
+       fn sign_holder_commitment_htlc_transactions<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Vec<Option<Signature>>, ()> {
                let counterparty_selected_contest_delay = self.accepted_channel_data.as_ref().unwrap().counterparty_selected_contest_delay;
                holder_commitment_tx.get_htlc_sigs(&self.htlc_base_key, counterparty_selected_contest_delay, secp_ctx)
        }
index 87a03b14393709ab757381f18d12816e97f34dc9..7b35fb3d98c8f5d1e1195a3af63420c2317acb5d 100644 (file)
@@ -350,7 +350,7 @@ pub struct ChannelPublicKeys {
        /// states.
        pub revocation_basepoint: PublicKey,
        /// The public key which receives our immediately spendable primary channel balance in
-       /// remote-broadcasted commitment transactions. This key is static across every commitment
+       /// counterparty-broadcasted commitment transactions. This key is static across every commitment
        /// transaction.
        pub payment_point: PublicKey,
        /// The base point which is used (with derive_public_key) to derive a per-commitment payment
@@ -406,7 +406,7 @@ pub struct HTLCOutputInCommitment {
        /// Whether the HTLC was "offered" (ie outbound in relation to this commitment transaction).
        /// Note that this is not the same as whether it is ountbound *from us*. To determine that you
        /// need to compare this value to whether the commitment transaction in question is that of
-       /// the remote party or our own.
+       /// the counterparty or our own.
        pub offered: bool,
        /// The value, in msat, of the HTLC. The value as it appears in the commitment transaction is
        /// this divided by 1000.
@@ -551,35 +551,35 @@ pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u32, contest_del
 }
 
 #[derive(Clone)]
-/// We use this to track local commitment transactions and put off signing them until we are ready
+/// We use this to track holder commitment transactions and put off signing them until we are ready
 /// to broadcast. This class can be used inside a signer implementation to generate a signature
 /// given the relevant secret key.
-pub struct LocalCommitmentTransaction {
+pub struct HolderCommitmentTransaction {
        // TODO: We should migrate away from providing the transaction, instead providing enough to
        // allow the ChannelKeys to construct it from scratch. Luckily we already have HTLC data here,
        // so we're probably most of the way there.
        /// The commitment transaction itself, in unsigned form.
        pub unsigned_tx: Transaction,
        /// Our counterparty's signature for the transaction, above.
-       pub their_sig: Signature,
+       pub counterparty_sig: Signature,
        // Which order the signatures should go in when constructing the final commitment tx witness.
        // The user should be able to reconstruc this themselves, so we don't bother to expose it.
-       our_sig_first: bool,
-       pub(crate) local_keys: TxCreationKeys,
+       holder_sig_first: bool,
+       pub(crate) keys: TxCreationKeys,
        /// The feerate paid per 1000-weight-unit in this commitment transaction. This value is
        /// controlled by the channel initiator.
        pub feerate_per_kw: u32,
-       /// The HTLCs and remote htlc signatures which were included in this commitment transaction.
+       /// The HTLCs and counterparty htlc signatures which were included in this commitment transaction.
        ///
        /// Note that this includes all HTLCs, including ones which were considered dust and not
        /// actually included in the transaction as it appears on-chain, but who's value is burned as
-       /// fees and not included in the to_local or to_remote outputs.
+       /// fees and not included in the to_holder or to_counterparty outputs.
        ///
-       /// The remote HTLC signatures in the second element will always be set for non-dust HTLCs, ie
+       /// The counterparty HTLC signatures in the second element will always be set for non-dust HTLCs, ie
        /// those for which transaction_output_index.is_some().
        pub per_htlc: Vec<(HTLCOutputInCommitment, Option<Signature>)>,
 }
-impl LocalCommitmentTransaction {
+impl HolderCommitmentTransaction {
        #[cfg(test)]
        pub fn dummy() -> Self {
                let dummy_input = TxIn {
@@ -600,9 +600,9 @@ impl LocalCommitmentTransaction {
                                output: Vec::new(),
                                lock_time: 0,
                        },
-                       their_sig: dummy_sig,
-                       our_sig_first: false,
-                       local_keys: TxCreationKeys {
+                       counterparty_sig: dummy_sig,
+                       holder_sig_first: false,
+                       keys: TxCreationKeys {
                                        per_commitment_point: dummy_key.clone(),
                                        revocation_key: dummy_key.clone(),
                                        broadcaster_htlc_key: dummy_key.clone(),
@@ -614,12 +614,12 @@ impl LocalCommitmentTransaction {
                }
        }
 
-       /// Generate a new LocalCommitmentTransaction based on a raw commitment transaction,
-       /// remote signature and both parties keys.
+       /// Generate a new HolderCommitmentTransaction based on a raw commitment transaction,
+       /// counterparty signature and both parties keys.
        ///
        /// The unsigned transaction outputs must be consistent with htlc_data.  This function
        /// only checks that the shape and amounts are consistent, but does not check the scriptPubkey.
-       pub fn new_missing_local_sig(unsigned_tx: Transaction, their_sig: Signature, our_funding_key: &PublicKey, their_funding_key: &PublicKey, local_keys: TxCreationKeys, feerate_per_kw: u32, htlc_data: Vec<(HTLCOutputInCommitment, Option<Signature>)>) -> LocalCommitmentTransaction {
+       pub fn new_missing_holder_sig(unsigned_tx: Transaction, counterparty_sig: Signature, holder_funding_key: &PublicKey, counterparty_funding_key: &PublicKey, keys: TxCreationKeys, feerate_per_kw: u32, htlc_data: Vec<(HTLCOutputInCommitment, Option<Signature>)>) -> HolderCommitmentTransaction {
                if unsigned_tx.input.len() != 1 { panic!("Tried to store a commitment transaction that had input count != 1!"); }
                if unsigned_tx.input[0].witness.len() != 0 { panic!("Tried to store a signed commitment transaction?"); }
 
@@ -637,9 +637,9 @@ impl LocalCommitmentTransaction {
 
                Self {
                        unsigned_tx,
-                       their_sig,
-                       our_sig_first: our_funding_key.serialize()[..] < their_funding_key.serialize()[..],
-                       local_keys,
+                       counterparty_sig,
+                       holder_sig_first: holder_funding_key.serialize()[..] < counterparty_funding_key.serialize()[..],
+                       keys,
                        feerate_per_kw,
                        per_htlc: htlc_data,
                }
@@ -648,40 +648,40 @@ impl LocalCommitmentTransaction {
        /// The pre-calculated transaction creation public keys.
        /// An external validating signer should not trust these keys.
        pub fn trust_key_derivation(&self) -> &TxCreationKeys {
-               &self.local_keys
+               &self.keys
        }
 
-       /// Get the txid of the local commitment transaction contained in this
-       /// LocalCommitmentTransaction
+       /// Get the txid of the holder commitment transaction contained in this
+       /// HolderCommitmentTransaction
        pub fn txid(&self) -> Txid {
                self.unsigned_tx.txid()
        }
 
-       /// Gets our signature for the contained commitment transaction given our funding private key.
+       /// Gets holder signature for the contained commitment transaction given holder funding private key.
        ///
        /// Funding key is your key included in the 2-2 funding_outpoint lock. Should be provided
        /// by your ChannelKeys.
        /// Funding redeemscript is script locking funding_outpoint. This is the mutlsig script
        /// between your own funding key and your counterparty's. Currently, this is provided in
-       /// ChannelKeys::sign_local_commitment() calls directly.
+       /// ChannelKeys::sign_holder_commitment() calls directly.
        /// Channel value is amount locked in funding_outpoint.
-       pub fn get_local_sig<T: secp256k1::Signing>(&self, funding_key: &SecretKey, funding_redeemscript: &Script, channel_value_satoshis: u64, secp_ctx: &Secp256k1<T>) -> Signature {
+       pub fn get_holder_sig<T: secp256k1::Signing>(&self, funding_key: &SecretKey, funding_redeemscript: &Script, channel_value_satoshis: u64, secp_ctx: &Secp256k1<T>) -> Signature {
                let sighash = hash_to_message!(&bip143::SigHashCache::new(&self.unsigned_tx)
                        .signature_hash(0, funding_redeemscript, channel_value_satoshis, SigHashType::All)[..]);
                secp_ctx.sign(&sighash, funding_key)
        }
 
-       pub(crate) fn add_local_sig(&self, funding_redeemscript: &Script, our_sig: Signature) -> Transaction {
+       pub(crate) fn add_holder_sig(&self, funding_redeemscript: &Script, holder_sig: Signature) -> Transaction {
                let mut tx = self.unsigned_tx.clone();
                // First push the multisig dummy, note that due to BIP147 (NULLDUMMY) it must be a zero-length element.
                tx.input[0].witness.push(Vec::new());
 
-               if self.our_sig_first {
-                       tx.input[0].witness.push(our_sig.serialize_der().to_vec());
-                       tx.input[0].witness.push(self.their_sig.serialize_der().to_vec());
+               if self.holder_sig_first {
+                       tx.input[0].witness.push(holder_sig.serialize_der().to_vec());
+                       tx.input[0].witness.push(self.counterparty_sig.serialize_der().to_vec());
                } else {
-                       tx.input[0].witness.push(self.their_sig.serialize_der().to_vec());
-                       tx.input[0].witness.push(our_sig.serialize_der().to_vec());
+                       tx.input[0].witness.push(self.counterparty_sig.serialize_der().to_vec());
+                       tx.input[0].witness.push(holder_sig.serialize_der().to_vec());
                }
                tx.input[0].witness[1].push(SigHashType::All as u8);
                tx.input[0].witness[2].push(SigHashType::All as u8);
@@ -696,19 +696,19 @@ impl LocalCommitmentTransaction {
        /// The returned Vec has one entry for each HTLC, and in the same order. For HTLCs which were
        /// considered dust and not included, a None entry exists, for all others a signature is
        /// included.
-       pub fn get_htlc_sigs<T: secp256k1::Signing + secp256k1::Verification>(&self, htlc_base_key: &SecretKey, local_csv: u16, secp_ctx: &Secp256k1<T>) -> Result<Vec<Option<Signature>>, ()> {
+       pub fn get_htlc_sigs<T: secp256k1::Signing + secp256k1::Verification>(&self, htlc_base_key: &SecretKey, holder_selected_contest_delay: u16, secp_ctx: &Secp256k1<T>) -> Result<Vec<Option<Signature>>, ()> {
                let txid = self.txid();
                let mut ret = Vec::with_capacity(self.per_htlc.len());
-               let our_htlc_key = derive_private_key(secp_ctx, &self.local_keys.per_commitment_point, htlc_base_key).map_err(|_| ())?;
+               let holder_htlc_key = derive_private_key(secp_ctx, &self.keys.per_commitment_point, htlc_base_key).map_err(|_| ())?;
 
                for this_htlc in self.per_htlc.iter() {
                        if this_htlc.0.transaction_output_index.is_some() {
-                               let htlc_tx = build_htlc_transaction(&txid, self.feerate_per_kw, local_csv, &this_htlc.0, &self.local_keys.broadcaster_delayed_payment_key, &self.local_keys.revocation_key);
+                               let htlc_tx = build_htlc_transaction(&txid, self.feerate_per_kw, holder_selected_contest_delay, &this_htlc.0, &self.keys.broadcaster_delayed_payment_key, &self.keys.revocation_key);
 
-                               let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(&this_htlc.0, &self.local_keys.broadcaster_htlc_key, &self.local_keys.countersignatory_htlc_key, &self.local_keys.revocation_key);
+                               let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(&this_htlc.0, &self.keys.broadcaster_htlc_key, &self.keys.countersignatory_htlc_key, &self.keys.revocation_key);
 
                                let sighash = hash_to_message!(&bip143::SigHashCache::new(&htlc_tx).signature_hash(0, &htlc_redeemscript, this_htlc.0.amount_msat / 1000, SigHashType::All)[..]);
-                               ret.push(Some(secp_ctx.sign(&sighash, &our_htlc_key)));
+                               ret.push(Some(secp_ctx.sign(&sighash, &holder_htlc_key)));
                        } else {
                                ret.push(None);
                        }
@@ -716,8 +716,8 @@ impl LocalCommitmentTransaction {
                Ok(ret)
        }
 
-       /// Gets a signed HTLC transaction given a preimage (for !htlc.offered) and the local HTLC transaction signature.
-       pub(crate) fn get_signed_htlc_tx(&self, htlc_index: usize, signature: &Signature, preimage: &Option<PaymentPreimage>, local_csv: u16) -> Transaction {
+       /// Gets a signed HTLC transaction given a preimage (for !htlc.offered) and the holder HTLC transaction signature.
+       pub(crate) fn get_signed_htlc_tx(&self, htlc_index: usize, signature: &Signature, preimage: &Option<PaymentPreimage>, holder_selected_contest_delay: u16) -> Transaction {
                let txid = self.txid();
                let this_htlc = &self.per_htlc[htlc_index];
                assert!(this_htlc.0.transaction_output_index.is_some());
@@ -726,12 +726,12 @@ impl LocalCommitmentTransaction {
                // Further, we should never be provided the preimage for an HTLC-Timeout transaction.
                if  this_htlc.0.offered && preimage.is_some() { unreachable!(); }
 
-               let mut htlc_tx = build_htlc_transaction(&txid, self.feerate_per_kw, local_csv, &this_htlc.0, &self.local_keys.broadcaster_delayed_payment_key, &self.local_keys.revocation_key);
-               // Channel should have checked that we have a remote signature for this HTLC at
+               let mut htlc_tx = build_htlc_transaction(&txid, self.feerate_per_kw, holder_selected_contest_delay, &this_htlc.0, &self.keys.broadcaster_delayed_payment_key, &self.keys.revocation_key);
+               // Channel should have checked that we have a counterparty signature for this HTLC at
                // creation, and we should have a sensible htlc transaction:
                assert!(this_htlc.1.is_some());
 
-               let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(&this_htlc.0, &self.local_keys.broadcaster_htlc_key, &self.local_keys.countersignatory_htlc_key, &self.local_keys.revocation_key);
+               let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(&this_htlc.0, &self.keys.broadcaster_htlc_key, &self.keys.countersignatory_htlc_key, &self.keys.revocation_key);
 
                // First push the multisig dummy, note that due to BIP147 (NULLDUMMY) it must be a zero-length element.
                htlc_tx.input[0].witness.push(Vec::new());
@@ -752,23 +752,23 @@ impl LocalCommitmentTransaction {
                htlc_tx
        }
 }
-impl PartialEq for LocalCommitmentTransaction {
+impl PartialEq for HolderCommitmentTransaction {
        // We dont care whether we are signed in equality comparison
        fn eq(&self, o: &Self) -> bool {
                self.txid() == o.txid()
        }
 }
-impl Writeable for LocalCommitmentTransaction {
+impl Writeable for HolderCommitmentTransaction {
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
                if let Err(e) = self.unsigned_tx.consensus_encode(&mut WriterWriteAdaptor(writer)) {
                        match e {
                                encode::Error::Io(e) => return Err(e),
-                               _ => panic!("local tx must have been well-formed!"),
+                               _ => panic!("holder tx must have been well-formed!"),
                        }
                }
-               self.their_sig.write(writer)?;
-               self.our_sig_first.write(writer)?;
-               self.local_keys.write(writer)?;
+               self.counterparty_sig.write(writer)?;
+               self.holder_sig_first.write(writer)?;
+               self.keys.write(writer)?;
                self.feerate_per_kw.write(writer)?;
                writer.write_all(&byte_utils::be64_to_array(self.per_htlc.len() as u64))?;
                for &(ref htlc, ref sig) in self.per_htlc.iter() {
@@ -778,7 +778,7 @@ impl Writeable for LocalCommitmentTransaction {
                Ok(())
        }
 }
-impl Readable for LocalCommitmentTransaction {
+impl Readable for HolderCommitmentTransaction {
        fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
                let unsigned_tx = match Transaction::consensus_decode(reader.by_ref()) {
                        Ok(tx) => tx,
@@ -787,9 +787,9 @@ impl Readable for LocalCommitmentTransaction {
                                _ => return Err(DecodeError::InvalidValue),
                        },
                };
-               let their_sig = Readable::read(reader)?;
-               let our_sig_first = Readable::read(reader)?;
-               let local_keys = Readable::read(reader)?;
+               let counterparty_sig = Readable::read(reader)?;
+               let holder_sig_first = Readable::read(reader)?;
+               let keys = Readable::read(reader)?;
                let feerate_per_kw = Readable::read(reader)?;
                let htlcs_count: u64 = Readable::read(reader)?;
                let mut per_htlc = Vec::with_capacity(cmp::min(htlcs_count as usize, MAX_ALLOC_SIZE / mem::size_of::<(HTLCOutputInCommitment, Option<Signature>)>()));
@@ -805,9 +805,9 @@ impl Readable for LocalCommitmentTransaction {
                }
                Ok(Self {
                        unsigned_tx,
-                       their_sig,
-                       our_sig_first,
-                       local_keys,
+                       counterparty_sig,
+                       holder_sig_first,
+                       keys,
                        feerate_per_kw,
                        per_htlc,
                })
index 2a5ba67aea14decd1b60c55df1498377689adb96..e00d34895c2e30b54c84dab6945dc6344238c97d 100644 (file)
@@ -27,7 +27,7 @@ use ln::msgs;
 use ln::msgs::{DecodeError, OptionalField, DataLossProtect};
 use ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, HTLC_FAIL_BACK_BUFFER};
 use ln::channelmanager::{PendingHTLCStatus, HTLCSource, HTLCFailReason, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, PaymentPreimage, PaymentHash, BREAKDOWN_TIMEOUT, MAX_LOCAL_BREAKDOWN_TIMEOUT};
-use ln::chan_utils::{CounterpartyCommitmentSecrets, LocalCommitmentTransaction, TxCreationKeys, HTLCOutputInCommitment, HTLC_SUCCESS_TX_WEIGHT, HTLC_TIMEOUT_TX_WEIGHT, make_funding_redeemscript, ChannelPublicKeys, PreCalculatedTxCreationKeys};
+use ln::chan_utils::{CounterpartyCommitmentSecrets, HolderCommitmentTransaction, TxCreationKeys, HTLCOutputInCommitment, HTLC_SUCCESS_TX_WEIGHT, HTLC_TIMEOUT_TX_WEIGHT, make_funding_redeemscript, ChannelPublicKeys, PreCalculatedTxCreationKeys};
 use ln::chan_utils;
 use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
 use chain::transaction::OutPoint;
@@ -1471,7 +1471,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
                Ok(())
        }
 
-       fn funding_created_signature<L: Deref>(&mut self, sig: &Signature, logger: &L) -> Result<(Transaction, LocalCommitmentTransaction, Signature), ChannelError> where L::Target: Logger {
+       fn funding_created_signature<L: Deref>(&mut self, sig: &Signature, logger: &L) -> Result<(Transaction, HolderCommitmentTransaction, Signature), ChannelError> where L::Target: Logger {
                let funding_script = self.get_funding_redeemscript();
 
                let keys = self.build_holder_transaction_keys(self.cur_holder_commitment_transaction_number)?;
@@ -1482,7 +1482,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
                log_trace!(logger, "Checking funding_created tx signature {} by key {} against tx {} (sighash {}) with redeemscript {}", log_bytes!(sig.serialize_compact()[..]), log_bytes!(self.counterparty_funding_pubkey().serialize()), encode::serialize_hex(&initial_commitment_tx), log_bytes!(sighash[..]), encode::serialize_hex(&funding_script));
                secp_check!(self.secp_ctx.verify(&sighash, &sig, self.counterparty_funding_pubkey()), "Invalid funding_created signature from peer".to_owned());
 
-               let tx = LocalCommitmentTransaction::new_missing_local_sig(initial_commitment_tx, sig.clone(), &self.holder_keys.pubkeys().funding_pubkey, self.counterparty_funding_pubkey(), keys, self.feerate_per_kw, Vec::new());
+               let tx = HolderCommitmentTransaction::new_missing_holder_sig(initial_commitment_tx, sig.clone(), &self.holder_keys.pubkeys().funding_pubkey, self.counterparty_funding_pubkey(), keys, self.feerate_per_kw, Vec::new());
 
                let counterparty_keys = self.build_remote_transaction_keys()?;
                let counterparty_initial_commitment_tx = self.build_commitment_transaction(self.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, self.feerate_per_kw, logger).0;
@@ -1595,7 +1595,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
                let funding_txo_script = funding_redeemscript.to_v0_p2wsh();
                macro_rules! create_monitor {
                        () => { {
-                               let commitment_tx = LocalCommitmentTransaction::new_missing_local_sig(initial_commitment_tx.clone(), msg.signature.clone(), &self.holder_keys.pubkeys().funding_pubkey, counterparty_funding_pubkey, holder_keys.clone(), self.feerate_per_kw, Vec::new());
+                               let commitment_tx = HolderCommitmentTransaction::new_missing_holder_sig(initial_commitment_tx.clone(), msg.signature.clone(), &self.holder_keys.pubkeys().funding_pubkey, counterparty_funding_pubkey, holder_keys.clone(), self.feerate_per_kw, Vec::new());
                                let mut channel_monitor = ChannelMonitor::new(self.holder_keys.clone(),
                                                                              &self.shutdown_pubkey, self.holder_selected_contest_delay,
                                                                              &self.destination_script, (funding_txo.clone(), funding_txo_script.clone()),
@@ -2046,7 +2046,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
                let mut monitor_update = ChannelMonitorUpdate {
                        update_id: self.latest_monitor_update_id,
                        updates: vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
-                               commitment_tx: LocalCommitmentTransaction::new_missing_local_sig(commitment_tx.0, msg.signature.clone(), &self.holder_keys.pubkeys().funding_pubkey, &counterparty_funding_pubkey, keys, self.feerate_per_kw, htlcs_without_source),
+                               commitment_tx: HolderCommitmentTransaction::new_missing_holder_sig(commitment_tx.0, msg.signature.clone(), &self.holder_keys.pubkeys().funding_pubkey, &counterparty_funding_pubkey, keys, self.feerate_per_kw, htlcs_without_source),
                                htlc_outputs: htlcs_and_sigs
                        }]
                };
@@ -4464,7 +4464,7 @@ mod tests {
        use ln::features::InitFeatures;
        use ln::msgs::{OptionalField, DataLossProtect};
        use ln::chan_utils;
-       use ln::chan_utils::{LocalCommitmentTransaction, ChannelPublicKeys};
+       use ln::chan_utils::{HolderCommitmentTransaction, ChannelPublicKeys};
        use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
        use chain::keysinterface::{InMemoryChannelKeys, KeysInterface};
        use chain::transaction::OutPoint;
@@ -4676,7 +4676,7 @@ mod tests {
 
                let mut unsigned_tx: (Transaction, Vec<HTLCOutputInCommitment>);
 
-               let mut localtx;
+               let mut holdertx;
                macro_rules! test_commitment {
                        ( $counterparty_sig_hex: expr, $sig_hex: expr, $tx_hex: expr, {
                                $( { $htlc_idx: expr, $counterparty_htlc_sig_hex: expr, $htlc_sig_hex: expr, $htlc_tx_hex: expr } ), *
@@ -4701,15 +4701,15 @@ mod tests {
                                })*
                                assert_eq!(unsigned_tx.1.len(), per_htlc.len());
 
-                               localtx = LocalCommitmentTransaction::new_missing_local_sig(unsigned_tx.0.clone(), counterparty_signature.clone(), &chan_keys.pubkeys().funding_pubkey, chan.counterparty_funding_pubkey(), keys.clone(), chan.feerate_per_kw, per_htlc);
-                               let local_sig = chan_keys.sign_holder_commitment(&localtx, &chan.secp_ctx).unwrap();
-                               assert_eq!(Signature::from_der(&hex::decode($sig_hex).unwrap()[..]).unwrap(), local_sig);
+                               holdertx = HolderCommitmentTransaction::new_missing_holder_sig(unsigned_tx.0.clone(), counterparty_signature.clone(), &chan_keys.pubkeys().funding_pubkey, chan.counterparty_funding_pubkey(), keys.clone(), chan.feerate_per_kw, per_htlc);
+                               let holder_sig = chan_keys.sign_holder_commitment(&holdertx, &chan.secp_ctx).unwrap();
+                               assert_eq!(Signature::from_der(&hex::decode($sig_hex).unwrap()[..]).unwrap(), holder_sig);
 
-                               assert_eq!(serialize(&localtx.add_local_sig(&redeemscript, local_sig))[..],
+                               assert_eq!(serialize(&holdertx.add_holder_sig(&redeemscript, holder_sig))[..],
                                                hex::decode($tx_hex).unwrap()[..]);
 
-                               let htlc_sigs = chan_keys.sign_holder_commitment_htlc_transactions(&localtx, &chan.secp_ctx).unwrap();
-                               let mut htlc_sig_iter = localtx.per_htlc.iter().zip(htlc_sigs.iter().enumerate());
+                               let htlc_sigs = chan_keys.sign_holder_commitment_htlc_transactions(&holdertx, &chan.secp_ctx).unwrap();
+                               let mut htlc_sig_iter = holdertx.per_htlc.iter().zip(htlc_sigs.iter().enumerate());
 
                                $({
                                        let remote_signature = Signature::from_der(&hex::decode($counterparty_htlc_sig_hex).unwrap()[..]).unwrap();
@@ -4738,7 +4738,7 @@ mod tests {
 
                                        let signature = Signature::from_der(&hex::decode($htlc_sig_hex).unwrap()[..]).unwrap();
                                        assert_eq!(Some(signature), *(htlc_sig.1).1);
-                                       assert_eq!(serialize(&localtx.get_signed_htlc_tx((htlc_sig.1).0, &(htlc_sig.1).1.unwrap(), &preimage, chan.counterparty_selected_contest_delay))[..],
+                                       assert_eq!(serialize(&holdertx.get_signed_htlc_tx((htlc_sig.1).0, &(htlc_sig.1).1.unwrap(), &preimage, chan.counterparty_selected_contest_delay))[..],
                                                        hex::decode($htlc_tx_hex).unwrap()[..]);
                                })*
                                loop {
index 231e42b0c89f297eadc24ca77370a7a6682c698c..d17078554b4702c0af0020685c0b58fe2292076e 100644 (file)
@@ -37,7 +37,7 @@ use bitcoin::secp256k1;
 
 use ln::msgs::DecodeError;
 use ln::chan_utils;
-use ln::chan_utils::{CounterpartyCommitmentSecrets, HTLCOutputInCommitment, LocalCommitmentTransaction, HTLCType};
+use ln::chan_utils::{CounterpartyCommitmentSecrets, HTLCOutputInCommitment, HolderCommitmentTransaction, HTLCType};
 use ln::channelmanager::{HTLCSource, PaymentPreimage, PaymentHash};
 use ln::onchaintx::{OnchainTxHandler, InputDescriptors};
 use chain::chaininterface::{ChainListener, ChainWatchInterface, BroadcasterInterface, FeeEstimator};
@@ -617,7 +617,7 @@ const MIN_SERIALIZATION_VERSION: u8 = 1;
 #[derive(Clone)]
 pub(super) enum ChannelMonitorUpdateStep {
        LatestHolderCommitmentTXInfo {
-               commitment_tx: LocalCommitmentTransaction,
+               commitment_tx: HolderCommitmentTransaction,
                htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>,
        },
        LatestCounterpartyCommitmentTXInfo {
@@ -1143,7 +1143,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
                        counterparty_htlc_base_key: &PublicKey, counterparty_delayed_payment_base_key: &PublicKey,
                        on_holder_tx_csv: u16, funding_redeemscript: Script, channel_value_satoshis: u64,
                        commitment_transaction_number_obscure_factor: u64,
-                       initial_holder_commitment_tx: LocalCommitmentTransaction) -> ChannelMonitor<ChanSigner> {
+                       initial_holder_commitment_tx: HolderCommitmentTransaction) -> ChannelMonitor<ChanSigner> {
 
                assert!(commitment_transaction_number_obscure_factor <= (1 << 48));
                let our_channel_close_key_hash = WPubkeyHash::hash(&shutdown_pubkey.serialize());
@@ -1159,11 +1159,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
                let holder_tx_locktime = initial_holder_commitment_tx.unsigned_tx.lock_time as u64;
                let holder_commitment_tx = HolderSignedTx {
                        txid: initial_holder_commitment_tx.txid(),
-                       revocation_key: initial_holder_commitment_tx.local_keys.revocation_key,
-                       a_htlc_key: initial_holder_commitment_tx.local_keys.broadcaster_htlc_key,
-                       b_htlc_key: initial_holder_commitment_tx.local_keys.countersignatory_htlc_key,
-                       delayed_payment_key: initial_holder_commitment_tx.local_keys.broadcaster_delayed_payment_key,
-                       per_commitment_point: initial_holder_commitment_tx.local_keys.per_commitment_point,
+                       revocation_key: initial_holder_commitment_tx.keys.revocation_key,
+                       a_htlc_key: initial_holder_commitment_tx.keys.broadcaster_htlc_key,
+                       b_htlc_key: initial_holder_commitment_tx.keys.countersignatory_htlc_key,
+                       delayed_payment_key: initial_holder_commitment_tx.keys.broadcaster_delayed_payment_key,
+                       per_commitment_point: initial_holder_commitment_tx.keys.per_commitment_point,
                        feerate_per_kw: initial_holder_commitment_tx.feerate_per_kw,
                        htlc_outputs: Vec::new(), // There are never any HTLCs in the initial commitment transactions
                };
@@ -1326,7 +1326,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
        /// is important that any clones of this channel monitor (including remote clones) by kept
        /// up-to-date as our holder commitment transaction is updated.
        /// Panics if set_on_holder_tx_csv has never been called.
-       pub(super) fn provide_latest_holder_commitment_tx_info(&mut self, commitment_tx: LocalCommitmentTransaction, htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>) -> Result<(), MonitorUpdateError> {
+       pub(super) fn provide_latest_holder_commitment_tx_info(&mut self, commitment_tx: HolderCommitmentTransaction, htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>) -> Result<(), MonitorUpdateError> {
                if self.holder_tx_signed {
                        return Err(MonitorUpdateError("A holder commitment tx has already been signed, no new holder commitment txn can be sent to our counterparty"));
                }
@@ -1335,11 +1335,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
                let locktime = commitment_tx.unsigned_tx.lock_time as u64;
                let mut new_holder_commitment_tx = HolderSignedTx {
                        txid,
-                       revocation_key: commitment_tx.local_keys.revocation_key,
-                       a_htlc_key: commitment_tx.local_keys.broadcaster_htlc_key,
-                       b_htlc_key: commitment_tx.local_keys.countersignatory_htlc_key,
-                       delayed_payment_key: commitment_tx.local_keys.broadcaster_delayed_payment_key,
-                       per_commitment_point: commitment_tx.local_keys.per_commitment_point,
+                       revocation_key: commitment_tx.keys.revocation_key,
+                       a_htlc_key: commitment_tx.keys.broadcaster_htlc_key,
+                       b_htlc_key: commitment_tx.keys.countersignatory_htlc_key,
+                       delayed_payment_key: commitment_tx.keys.broadcaster_delayed_payment_key,
+                       per_commitment_point: commitment_tx.keys.per_commitment_point,
                        feerate_per_kw: commitment_tx.feerate_per_kw,
                        htlc_outputs: htlc_outputs,
                };
@@ -1848,7 +1848,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
        }
 
        /// Unsafe test-only version of get_latest_holder_commitment_txn used by our test framework
-       /// to bypass LocalCommitmentTransaction state update lockdown after signature and generate
+       /// to bypass HolderCommitmentTransaction state update lockdown after signature and generate
        /// revoked commitment transaction.
        #[cfg(any(test,feature = "unsafe_revoked_tx_signing"))]
        pub fn unsafe_get_latest_holder_commitment_txn<L: Deref>(&mut self, logger: &L) -> Vec<Transaction> where L::Target: Logger {
@@ -2234,7 +2234,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
                                                to_self_delay: self.on_holder_tx_csv,
                                                output: outp.clone(),
                                                key_derivation_params: self.keys.key_derivation_params(),
-                                               counterparty_revocation_pubkey: broadcasted_holder_revokable_script.2.clone(),
+                                               revocation_pubkey: broadcasted_holder_revokable_script.2.clone(),
                                        });
                                        break;
                                }
@@ -2579,7 +2579,7 @@ mod tests {
        use ln::channelmonitor::ChannelMonitor;
        use ln::onchaintx::{OnchainTxHandler, InputDescriptors};
        use ln::chan_utils;
-       use ln::chan_utils::{HTLCOutputInCommitment, LocalCommitmentTransaction};
+       use ln::chan_utils::{HTLCOutputInCommitment, HolderCommitmentTransaction};
        use util::test_utils::TestLogger;
        use bitcoin::secp256k1::key::{SecretKey,PublicKey};
        use bitcoin::secp256k1::Secp256k1;
@@ -2657,9 +2657,9 @@ mod tests {
                        (OutPoint { txid: Txid::from_slice(&[43; 32]).unwrap(), index: 0 }, Script::new()),
                        &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
                        &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap()),
-                       10, Script::new(), 46, 0, LocalCommitmentTransaction::dummy());
+                       10, Script::new(), 46, 0, HolderCommitmentTransaction::dummy());
 
-               monitor.provide_latest_holder_commitment_tx_info(LocalCommitmentTransaction::dummy(), preimages_to_holder_htlcs!(preimages[0..10])).unwrap();
+               monitor.provide_latest_holder_commitment_tx_info(HolderCommitmentTransaction::dummy(), preimages_to_holder_htlcs!(preimages[0..10])).unwrap();
                monitor.provide_latest_counterparty_commitment_tx_info(&dummy_tx, preimages_slice_to_htlc_outputs!(preimages[5..15]), 281474976710655, dummy_key, &logger);
                monitor.provide_latest_counterparty_commitment_tx_info(&dummy_tx, preimages_slice_to_htlc_outputs!(preimages[15..20]), 281474976710654, dummy_key, &logger);
                monitor.provide_latest_counterparty_commitment_tx_info(&dummy_tx, preimages_slice_to_htlc_outputs!(preimages[17..20]), 281474976710653, dummy_key, &logger);
@@ -2685,7 +2685,7 @@ mod tests {
 
                // Now update holder commitment tx info, pruning only element 18 as we still care about the
                // previous commitment tx's preimages too
-               monitor.provide_latest_holder_commitment_tx_info(LocalCommitmentTransaction::dummy(), preimages_to_holder_htlcs!(preimages[0..5])).unwrap();
+               monitor.provide_latest_holder_commitment_tx_info(HolderCommitmentTransaction::dummy(), preimages_to_holder_htlcs!(preimages[0..5])).unwrap();
                secret[0..32].clone_from_slice(&hex::decode("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
                monitor.provide_secret(281474976710653, secret.clone()).unwrap();
                assert_eq!(monitor.payment_preimages.len(), 12);
@@ -2693,7 +2693,7 @@ mod tests {
                test_preimages_exist!(&preimages[18..20], monitor);
 
                // But if we do it again, we'll prune 5-10
-               monitor.provide_latest_holder_commitment_tx_info(LocalCommitmentTransaction::dummy(), preimages_to_holder_htlcs!(preimages[0..3])).unwrap();
+               monitor.provide_latest_holder_commitment_tx_info(HolderCommitmentTransaction::dummy(), preimages_to_holder_htlcs!(preimages[0..3])).unwrap();
                secret[0..32].clone_from_slice(&hex::decode("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
                monitor.provide_secret(281474976710652, secret.clone()).unwrap();
                assert_eq!(monitor.payment_preimages.len(), 5);
index eda476699cf1849fcc2a32145d27889fce21cd24..b11b57d34fa5ae802aed7c20fa6f3980c03dffaf 100644 (file)
@@ -4697,7 +4697,7 @@ macro_rules! check_spendable_outputs {
                                                                        spend_tx.input[0].witness.push(remotepubkey.serialize().to_vec());
                                                                        txn.push(spend_tx);
                                                                },
-                                                               SpendableOutputDescriptor::DynamicOutputP2WSH { ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref key_derivation_params, ref counterparty_revocation_pubkey } => {
+                                                               SpendableOutputDescriptor::DynamicOutputP2WSH { ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref key_derivation_params, ref revocation_pubkey } => {
                                                                        let input = TxIn {
                                                                                previous_output: outpoint.into_bitcoin_outpoint(),
                                                                                script_sig: Script::new(),
@@ -4719,7 +4719,7 @@ macro_rules! check_spendable_outputs {
                                                                        if let Ok(delayed_payment_key) = chan_utils::derive_private_key(&secp_ctx, &per_commitment_point, &keys.inner.delayed_payment_base_key) {
 
                                                                                let delayed_payment_pubkey = PublicKey::from_secret_key(&secp_ctx, &delayed_payment_key);
-                                                                               let witness_script = chan_utils::get_revokeable_redeemscript(counterparty_revocation_pubkey, *to_self_delay, &delayed_payment_pubkey);
+                                                                               let witness_script = chan_utils::get_revokeable_redeemscript(revocation_pubkey, *to_self_delay, &delayed_payment_pubkey);
                                                                                let sighash = Message::from_slice(&bip143::SigHashCache::new(&spend_tx).signature_hash(0, &witness_script, output.value, SigHashType::All)[..]).unwrap();
                                                                                let local_delayedsig = secp_ctx.sign(&sighash, &delayed_payment_key);
                                                                                spend_tx.input[0].witness.push(local_delayedsig.serialize_der().to_vec());
index 7aced598ecbb4f39c9a4d30dada413021c9e0bb9..281bc919060a95445b1f8d76a7d1764ee15b500a 100644 (file)
@@ -25,7 +25,7 @@ use ln::msgs::DecodeError;
 use ln::channelmonitor::{ANTI_REORG_DELAY, CLTV_SHARED_CLAIM_BUFFER, InputMaterial, ClaimRequest};
 use ln::channelmanager::PaymentPreimage;
 use ln::chan_utils;
-use ln::chan_utils::{TxCreationKeys, LocalCommitmentTransaction};
+use ln::chan_utils::{TxCreationKeys, HolderCommitmentTransaction};
 use chain::chaininterface::{FeeEstimator, BroadcasterInterface, ConfirmationTarget, MIN_RELAY_FEE_SAT_PER_1000_WEIGHT};
 use chain::keysinterface::ChannelKeys;
 use util::logger::Logger;
@@ -241,13 +241,13 @@ impl Writeable for Option<Vec<Option<(usize, Signature)>>> {
 /// do RBF bumping if possible.
 pub struct OnchainTxHandler<ChanSigner: ChannelKeys> {
        destination_script: Script,
-       holder_commitment: Option<LocalCommitmentTransaction>,
+       holder_commitment: Option<HolderCommitmentTransaction>,
        // holder_htlc_sigs and prev_holder_htlc_sigs are in the order as they appear in the commitment
        // transaction outputs (hence the Option<>s inside the Vec). The first usize is the index in
-       // the set of HTLCs in the LocalCommitmentTransaction (including those which do not appear in
+       // the set of HTLCs in the HolderCommitmentTransaction (including those which do not appear in
        // the commitment transaction).
        holder_htlc_sigs: Option<Vec<Option<(usize, Signature)>>>,
-       prev_holder_commitment: Option<LocalCommitmentTransaction>,
+       prev_holder_commitment: Option<HolderCommitmentTransaction>,
        prev_holder_htlc_sigs: Option<Vec<Option<(usize, Signature)>>>,
        on_holder_tx_csv: u16,
 
@@ -877,7 +877,7 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
                }
        }
 
-       pub(super) fn provide_latest_holder_tx(&mut self, tx: LocalCommitmentTransaction) -> Result<(), ()> {
+       pub(super) fn provide_latest_holder_tx(&mut self, tx: HolderCommitmentTransaction) -> Result<(), ()> {
                // To prevent any unsafe state discrepancy between offchain and onchain, once holder
                // commitment transaction has been signed due to an event (either block height for
                // HTLC-timeout or channel force-closure), don't allow any further update of holder
@@ -931,7 +931,7 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
        pub(super) fn get_fully_signed_holder_tx(&mut self, funding_redeemscript: &Script) -> Option<Transaction> {
                if let Some(ref mut holder_commitment) = self.holder_commitment {
                        match self.key_storage.sign_holder_commitment(holder_commitment, &self.secp_ctx) {
-                               Ok(sig) => Some(holder_commitment.add_local_sig(funding_redeemscript, sig)),
+                               Ok(sig) => Some(holder_commitment.add_holder_sig(funding_redeemscript, sig)),
                                Err(_) => return None,
                        }
                } else {
@@ -944,7 +944,7 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
                if let Some(ref mut holder_commitment) = self.holder_commitment {
                        let holder_commitment = holder_commitment.clone();
                        match self.key_storage.sign_holder_commitment(&holder_commitment, &self.secp_ctx) {
-                               Ok(sig) => Some(holder_commitment.add_local_sig(funding_redeemscript, sig)),
+                               Ok(sig) => Some(holder_commitment.add_holder_sig(funding_redeemscript, sig)),
                                Err(_) => return None,
                        }
                } else {
index 67c38dc7193263a5df4e5e02d1e4f50bd48df627..05158f1b4d2c1109071d8624d0f59f4a27d12f3b 100644 (file)
@@ -7,7 +7,7 @@
 // You may not use this file except in accordance with one or both of these
 // licenses.
 
-use ln::chan_utils::{HTLCOutputInCommitment, TxCreationKeys, ChannelPublicKeys, LocalCommitmentTransaction, PreCalculatedTxCreationKeys};
+use ln::chan_utils::{HTLCOutputInCommitment, TxCreationKeys, ChannelPublicKeys, HolderCommitmentTransaction, PreCalculatedTxCreationKeys};
 use ln::{chan_utils, msgs};
 use chain::keysinterface::{ChannelKeys, InMemoryChannelKeys};
 
@@ -87,29 +87,29 @@ impl ChannelKeys for EnforcingChannelKeys {
                Ok(self.inner.sign_counterparty_commitment(feerate_per_kw, commitment_tx, pre_keys, htlcs, secp_ctx).unwrap())
        }
 
-       fn sign_holder_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
+       fn sign_holder_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
                // TODO: enforce the ChannelKeys contract - error if this commitment was already revoked
                // TODO: need the commitment number
                Ok(self.inner.sign_holder_commitment(holder_commitment_tx, secp_ctx).unwrap())
        }
 
        #[cfg(any(test,feature = "unsafe_revoked_tx_signing"))]
-       fn unsafe_sign_holder_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
+       fn unsafe_sign_holder_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
                Ok(self.inner.unsafe_sign_holder_commitment(holder_commitment_tx, secp_ctx).unwrap())
        }
 
-       fn sign_holder_commitment_htlc_transactions<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Vec<Option<Signature>>, ()> {
+       fn sign_holder_commitment_htlc_transactions<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Vec<Option<Signature>>, ()> {
                let commitment_txid = holder_commitment_tx.txid();
-               let local_csv = self.inner.counterparty_selected_contest_delay();
+               let holder_csv = self.inner.counterparty_selected_contest_delay();
 
                for this_htlc in holder_commitment_tx.per_htlc.iter() {
                        if this_htlc.0.transaction_output_index.is_some() {
-                               let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, holder_commitment_tx.feerate_per_kw, local_csv, &this_htlc.0, &holder_commitment_tx.local_keys.broadcaster_delayed_payment_key, &holder_commitment_tx.local_keys.revocation_key);
+                               let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, holder_commitment_tx.feerate_per_kw, holder_csv, &this_htlc.0, &holder_commitment_tx.keys.broadcaster_delayed_payment_key, &holder_commitment_tx.keys.revocation_key);
 
-                               let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&this_htlc.0, &holder_commitment_tx.local_keys);
+                               let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&this_htlc.0, &holder_commitment_tx.keys);
 
                                let sighash = hash_to_message!(&bip143::SigHashCache::new(&htlc_tx).signature_hash(0, &htlc_redeemscript, this_htlc.0.amount_msat / 1000, SigHashType::All)[..]);
-                               secp_ctx.verify(&sighash, this_htlc.1.as_ref().unwrap(), &holder_commitment_tx.local_keys.countersignatory_htlc_key).unwrap();
+                               secp_ctx.verify(&sighash, this_htlc.1.as_ref().unwrap(), &holder_commitment_tx.keys.countersignatory_htlc_key).unwrap();
                        }
                }