diff --git a/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs index 9991ea3b365..42da4d90312 100644 --- a/fuzz/src/full_stack.rs +++ b/fuzz/src/full_stack.rs @@ -903,6 +903,6 @@ mod tests { assert_eq!(log_entries.get(&("lightning::ln::peer_handler".to_string(), "Handling UpdateHTLCs event in peer_handler for node 030200000000000000000000000000000000000000000000000000000000000000 with 1 adds, 0 fulfills, 0 fails for channel 3900000000000000000000000000000000000000000000000000000000000000".to_string())), Some(&3)); // 7 assert_eq!(log_entries.get(&("lightning::ln::peer_handler".to_string(), "Handling UpdateHTLCs event in peer_handler for node 030000000000000000000000000000000000000000000000000000000000000000 with 0 adds, 1 fulfills, 0 fails for channel 3d00000000000000000000000000000000000000000000000000000000000000".to_string())), Some(&1)); // 8 assert_eq!(log_entries.get(&("lightning::ln::peer_handler".to_string(), "Handling UpdateHTLCs event in peer_handler for node 030000000000000000000000000000000000000000000000000000000000000000 with 0 adds, 0 fulfills, 1 fails for channel 3d00000000000000000000000000000000000000000000000000000000000000".to_string())), Some(&2)); // 9 - assert_eq!(log_entries.get(&("lightning::ln::channelmonitor".to_string(), "Input spending remote commitment tx (00000000000000000000000000000000000000000000000000000000000000a1:0) in 0000000000000000000000000000000000000000000000000000000000000018 resolves outbound HTLC with payment hash ff00000000000000000000000000000000000000000000000000000000000000 with timeout".to_string())), Some(&1)); // 10 + assert_eq!(log_entries.get(&("lightning::ln::channelmonitor".to_string(), "Input spending counterparty commitment tx (00000000000000000000000000000000000000000000000000000000000000a1:0) in 0000000000000000000000000000000000000000000000000000000000000018 resolves outbound HTLC with payment hash ff00000000000000000000000000000000000000000000000000000000000000 with timeout".to_string())), Some(&1)); // 10 } } diff --git a/lightning-c-bindings/src/chain/keysinterface.rs b/lightning-c-bindings/src/chain/keysinterface.rs index 9cc9360bde9..c68c219c24e 100644 --- a/lightning-c-bindings/src/chain/keysinterface.rs +++ b/lightning-c-bindings/src/chain/keysinterface.rs @@ -37,14 +37,14 @@ pub enum SpendableOutputDescriptor { /// it is an output from an old state which we broadcast (which should never happen). /// /// To derive the delayed_payment key which is used to sign for this input, you must pass the - /// local delayed_payment_base_key (ie the private key which corresponds to the pubkey in + /// holder delayed_payment_base_key (ie the private key which corresponds to the pubkey in /// ChannelKeys::pubkeys().delayed_payment_basepoint) and the provided per_commitment_point to /// chan_utils::derive_private_key. The public key can be generated without the secret key /// using chan_utils::derive_public_key and only the delayed_payment_basepoint which appears in /// ChannelKeys::pubkeys(). /// - /// To derive the remote_revocation_pubkey provided here (which is used in the witness - /// script generation), you must pass the remote revocation_basepoint (which appears in the + /// To derive the revocation_pubkey provided here (which is used in the witness + /// script generation), you must pass the 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, - remote_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). @@ -67,7 +67,7 @@ pub enum SpendableOutputDescriptor { /// /// These are generally the result of our counterparty having broadcast the current state, /// allowing us to claim the non-HTLC-encumbered outputs immediately. - StaticOutputRemotePayment { + StaticOutputCounterpartyPayment { outpoint: crate::chain::transaction::OutPoint, output: crate::c_types::TxOut, key_derivation_params: crate::c_types::derived::C2Tuple_u64u64Z, @@ -86,29 +86,29 @@ 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 remote_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 remote_revocation_pubkey_nonref = (*remote_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, - remote_revocation_pubkey: remote_revocation_pubkey_nonref.into_rust(), + revocation_pubkey: revocation_pubkey_nonref.into_rust(), } }, - SpendableOutputDescriptor::StaticOutputRemotePayment {ref outpoint, ref output, ref key_derivation_params, } => { + SpendableOutputDescriptor::StaticOutputCounterpartyPayment {ref outpoint, ref output, ref key_derivation_params, } => { let mut outpoint_nonref = (*outpoint).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); - nativeSpendableOutputDescriptor::StaticOutputRemotePayment { + nativeSpendableOutputDescriptor::StaticOutputCounterpartyPayment { outpoint: *unsafe { Box::from_raw(outpoint_nonref.take_ptr()) }, output: output_nonref.into_rust(), key_derivation_params: local_key_derivation_params_nonref, @@ -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 remote_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,12 +133,12 @@ impl SpendableOutputDescriptor { to_self_delay: to_self_delay, output: output.into_rust(), key_derivation_params: local_key_derivation_params, - remote_revocation_pubkey: remote_revocation_pubkey.into_rust(), + revocation_pubkey: revocation_pubkey.into_rust(), } }, - SpendableOutputDescriptor::StaticOutputRemotePayment {mut outpoint, mut output, mut key_derivation_params, } => { + SpendableOutputDescriptor::StaticOutputCounterpartyPayment {mut outpoint, mut output, mut key_derivation_params, } => { 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::StaticOutputRemotePayment { + nativeSpendableOutputDescriptor::StaticOutputCounterpartyPayment { outpoint: *unsafe { Box::from_raw(outpoint.take_ptr()) }, output: output.into_rust(), key_derivation_params: local_key_derivation_params, @@ -157,29 +157,29 @@ 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 remote_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 remote_revocation_pubkey_nonref = (*remote_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, - remote_revocation_pubkey: crate::c_types::PublicKey::from_rust(&remote_revocation_pubkey_nonref), + revocation_pubkey: crate::c_types::PublicKey::from_rust(&revocation_pubkey_nonref), } }, - nativeSpendableOutputDescriptor::StaticOutputRemotePayment {ref outpoint, ref output, ref key_derivation_params, } => { + nativeSpendableOutputDescriptor::StaticOutputCounterpartyPayment {ref outpoint, ref output, ref key_derivation_params, } => { let mut outpoint_nonref = (*outpoint).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(); - SpendableOutputDescriptor::StaticOutputRemotePayment { + SpendableOutputDescriptor::StaticOutputCounterpartyPayment { outpoint: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(outpoint_nonref)), is_owned: true }, output: crate::c_types::TxOut::from_rust(output_nonref), key_derivation_params: local_key_derivation_params_nonref, @@ -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 remote_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,12 +204,12 @@ impl SpendableOutputDescriptor { to_self_delay: to_self_delay, output: crate::c_types::TxOut::from_rust(output), key_derivation_params: local_key_derivation_params, - remote_revocation_pubkey: crate::c_types::PublicKey::from_rust(&remote_revocation_pubkey), + revocation_pubkey: crate::c_types::PublicKey::from_rust(&revocation_pubkey), } }, - nativeSpendableOutputDescriptor::StaticOutputRemotePayment {mut outpoint, mut output, mut key_derivation_params, } => { + nativeSpendableOutputDescriptor::StaticOutputCounterpartyPayment {mut outpoint, mut output, mut key_derivation_params, } => { 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::StaticOutputRemotePayment { + SpendableOutputDescriptor::StaticOutputCounterpartyPayment { outpoint: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(outpoint)), is_owned: true }, output: crate::c_types::TxOut::from_rust(output), key_derivation_params: local_key_derivation_params, @@ -272,32 +272,32 @@ pub struct ChannelKeys { /// ChannelKeys object uniquely and lookup or re-derive its keys. #[must_use] pub key_derivation_params: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::C2Tuple_u64u64Z, - /// Create a signature for a remote commitment transaction and associated HTLC transactions. + /// Create a signature for a counterparty commitment transaction and associated HTLC transactions. /// /// Note that if signing fails or is rejected, the channel will be force-closed. #[must_use] - pub sign_remote_commitment: extern "C" fn (this_arg: *const c_void, feerate_per_kw: u32, commitment_tx: crate::c_types::Transaction, keys: &crate::ln::chan_utils::PreCalculatedTxCreationKeys, htlcs: crate::c_types::derived::CVec_HTLCOutputInCommitmentZ) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ, + pub sign_counterparty_commitment: extern "C" fn (this_arg: *const c_void, feerate_per_kw: u32, commitment_tx: crate::c_types::Transaction, keys: &crate::ln::chan_utils::PreCalculatedTxCreationKeys, htlcs: crate::c_types::derived::CVec_HTLCOutputInCommitmentZ) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ, /// Create a signature for a local commitment transaction. This will only ever be called with /// the same local_commitment_tx (or a copy thereof), though there are currently no guarantees /// 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_local_commitment: extern "C" fn (this_arg: *const c_void, local_commitment_tx: &crate::ln::chan_utils::LocalCommitmentTransaction) -> crate::c_types::derived::CResult_SignatureNoneZ, - /// Create a signature for each HTLC transaction spending a local commitment transaction. + 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_local_commitment, this may be called multiple times with *different* - /// local_commitment_tx values. While this will never be called with a revoked - /// local_commitment_tx, it is possible that it is called with the second-latest - /// local_commitment_tx (only if we haven't yet revoked it) if some watchtower/secondary + /// Unlike sign_holder_commitment, this may be called multiple times with *different* + /// holder_commitment_tx values. While this will never be called with a revoked + /// holder_commitment_tx, it is possible that it is called with the second-latest + /// holder_commitment_tx (only if we haven't yet revoked it) if some watchtower/secondary /// ChannelMonitor decided to broadcast before it had been updated to the latest. /// /// Either an Err should be returned, or a Vec with one entry for each HTLC which exists in - /// local_commitment_tx. For those HTLCs which have transaction_output_index set to None + /// holder_commitment_tx. For those HTLCs which have transaction_output_index set to None /// (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. #[must_use] - pub sign_local_commitment_htlc_transactions: extern "C" fn (this_arg: *const c_void, local_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. /// @@ -318,7 +318,7 @@ pub struct ChannelKeys { /// signatures). #[must_use] pub sign_justice_transaction: extern "C" fn (this_arg: *const c_void, justice_tx: crate::c_types::Transaction, input: usize, amount: u64, per_commitment_key: *const [u8; 32], htlc: &crate::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_SignatureNoneZ, - /// Create a signature for a claiming transaction for a HTLC output on a remote commitment + /// Create a signature for a claiming transaction for a HTLC output on a counterparty commitment /// transaction, either offered or received. /// /// Such a transaction may claim multiples offered outputs at same time if we know the @@ -336,7 +336,7 @@ pub struct ChannelKeys { /// channel state keys, which are then included in the witness script and committed to in the /// BIP 143 signature. #[must_use] - pub sign_remote_htlc_transaction: extern "C" fn (this_arg: *const c_void, htlc_tx: crate::c_types::Transaction, input: usize, amount: u64, per_commitment_point: crate::c_types::PublicKey, htlc: &crate::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_SignatureNoneZ, + pub sign_counterparty_htlc_transaction: extern "C" fn (this_arg: *const c_void, htlc_tx: crate::c_types::Transaction, input: usize, amount: u64, per_commitment_point: crate::c_types::PublicKey, htlc: &crate::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_SignatureNoneZ, /// Create a signature for a (proposed) closing transaction. /// /// Note that, due to rounding, there may be one \"missing\" satoshi, and either party may have @@ -351,13 +351,13 @@ pub struct ChannelKeys { /// protocol. #[must_use] pub sign_channel_announcement: extern "C" fn (this_arg: *const c_void, msg: &crate::ln::msgs::UnsignedChannelAnnouncement) -> crate::c_types::derived::CResult_SignatureNoneZ, - /// Set the remote channel basepoints and remote/local to_self_delay. + /// Set the counterparty channel basepoints and counterparty/local to_self_delay. /// This is done immediately on incoming channels and as soon as the channel is accepted on outgoing channels. /// /// We bind local_to_self_delay late here for API convenience. /// /// Will be called before any signatures are applied. - pub on_accept: extern "C" fn (this_arg: *mut c_void, channel_points: &crate::ln::chan_utils::ChannelPublicKeys, remote_to_self_delay: u16, local_to_self_delay: u16), + pub on_accept: extern "C" fn (this_arg: *mut c_void, channel_points: &crate::ln::chan_utils::ChannelPublicKeys, counterparty_to_self_delay: u16, local_to_self_delay: u16), pub clone: Option *mut c_void>, pub free: Option, } @@ -371,11 +371,11 @@ impl Clone for ChannelKeys { pubkeys: self.pubkeys.clone(), set_pubkeys: self.set_pubkeys.clone(), key_derivation_params: self.key_derivation_params.clone(), - sign_remote_commitment: self.sign_remote_commitment.clone(), - sign_local_commitment: self.sign_local_commitment.clone(), - sign_local_commitment_htlc_transactions: self.sign_local_commitment_htlc_transactions.clone(), + sign_counterparty_commitment: self.sign_counterparty_commitment.clone(), + sign_holder_commitment: self.sign_holder_commitment.clone(), + sign_holder_commitment_htlc_transactions: self.sign_holder_commitment_htlc_transactions.clone(), sign_justice_transaction: self.sign_justice_transaction.clone(), - sign_remote_htlc_transaction: self.sign_remote_htlc_transaction.clone(), + sign_counterparty_htlc_transaction: self.sign_counterparty_htlc_transaction.clone(), sign_closing_transaction: self.sign_closing_transaction.clone(), sign_channel_announcement: self.sign_channel_announcement.clone(), on_accept: self.on_accept.clone(), @@ -406,20 +406,20 @@ impl rustChannelKeys for ChannelKeys { let (mut orig_ret_0, mut orig_ret_1) = ret.to_rust(); let mut local_ret = (orig_ret_0, orig_ret_1); local_ret } - fn sign_remote_commitment(&self, feerate_per_kw: u32, commitment_tx: &bitcoin::blockdata::transaction::Transaction, keys: &lightning::ln::chan_utils::PreCalculatedTxCreationKeys, htlcs: &[&lightning::ln::chan_utils::HTLCOutputInCommitment], _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result<(bitcoin::secp256k1::Signature, Vec), ()> { + fn sign_counterparty_commitment(&self, feerate_per_kw: u32, commitment_tx: &bitcoin::blockdata::transaction::Transaction, keys: &lightning::ln::chan_utils::PreCalculatedTxCreationKeys, htlcs: &[&lightning::ln::chan_utils::HTLCOutputInCommitment], _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result<(bitcoin::secp256k1::Signature, Vec), ()> { let mut local_commitment_tx = ::bitcoin::consensus::encode::serialize(commitment_tx); let mut local_htlcs = Vec::new(); for item in htlcs.iter() { local_htlcs.push( { crate::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { ( (&(**item) as *const _) as *mut _) }, is_owned: false } }); }; - let mut ret = (self.sign_remote_commitment)(self.this_arg, feerate_per_kw, crate::c_types::Transaction::from_slice(&local_commitment_tx), &crate::ln::chan_utils::PreCalculatedTxCreationKeys { inner: unsafe { (keys as *const _) as *mut _ }, is_owned: false }, local_htlcs.into()); + let mut ret = (self.sign_counterparty_commitment)(self.this_arg, feerate_per_kw, crate::c_types::Transaction::from_slice(&local_commitment_tx), &crate::ln::chan_utils::PreCalculatedTxCreationKeys { inner: unsafe { (keys as *const _) as *mut _ }, is_owned: false }, local_htlcs.into()); 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_local_commitment(&self, local_commitment_tx: &lightning::ln::chan_utils::LocalCommitmentTransaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result { - let mut ret = (self.sign_local_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(&self, local_commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result { + 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_local_commitment_htlc_transactions(&self, local_commitment_tx: &lightning::ln::chan_utils::LocalCommitmentTransaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result>, ()> { - let mut ret = (self.sign_local_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(&self, local_commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result>, ()> { + 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 } @@ -430,9 +430,9 @@ impl rustChannelKeys for ChannelKeys { 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_remote_htlc_transaction(&self, htlc_tx: &bitcoin::blockdata::transaction::Transaction, input: usize, amount: u64, per_commitment_point: &bitcoin::secp256k1::key::PublicKey, htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result { + fn sign_counterparty_htlc_transaction(&self, htlc_tx: &bitcoin::blockdata::transaction::Transaction, input: usize, amount: u64, per_commitment_point: &bitcoin::secp256k1::key::PublicKey, htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result { let mut local_htlc_tx = ::bitcoin::consensus::encode::serialize(htlc_tx); - let mut ret = (self.sign_remote_htlc_transaction)(self.this_arg, crate::c_types::Transaction::from_slice(&local_htlc_tx), input, amount, crate::c_types::PublicKey::from_rust(&per_commitment_point), &crate::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { (htlc as *const _) as *mut _ }, is_owned: false }); + let mut ret = (self.sign_counterparty_htlc_transaction)(self.this_arg, crate::c_types::Transaction::from_slice(&local_htlc_tx), input, amount, crate::c_types::PublicKey::from_rust(&per_commitment_point), &crate::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { (htlc 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 } @@ -447,8 +447,8 @@ impl rustChannelKeys for ChannelKeys { 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 on_accept(&mut self, channel_points: &lightning::ln::chan_utils::ChannelPublicKeys, remote_to_self_delay: u16, local_to_self_delay: u16) { - (self.on_accept)(self.this_arg, &crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { (channel_points as *const _) as *mut _ }, is_owned: false }, remote_to_self_delay, local_to_self_delay) + fn on_accept(&mut self, channel_points: &lightning::ln::chan_utils::ChannelPublicKeys, counterparty_to_self_delay: u16, local_to_self_delay: u16) { + (self.on_accept)(self.this_arg, &crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { (channel_points as *const _) as *mut _ }, is_owned: false }, counterparty_to_self_delay, local_to_self_delay) } } @@ -613,13 +613,13 @@ pub extern "C" fn InMemoryChannelKeys_get_revocation_base_key(this_ptr: &InMemor pub extern "C" fn InMemoryChannelKeys_set_revocation_base_key(this_ptr: &mut InMemoryChannelKeys, mut val: crate::c_types::SecretKey) { unsafe { &mut *this_ptr.inner }.revocation_base_key = val.into_rust(); } -/// Local secret key used for our balance in remote-broadcasted commitment transactions +/// Local secret key used for our balance in counterparty-broadcasted commitment transactions #[no_mangle] pub extern "C" fn InMemoryChannelKeys_get_payment_key(this_ptr: &InMemoryChannelKeys) -> *const [u8; 32] { let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.payment_key; (*inner_val).as_ref() } -/// Local secret key used for our balance in remote-broadcasted commitment transactions +/// Local secret key used for our balance in counterparty-broadcasted commitment transactions #[no_mangle] pub extern "C" fn InMemoryChannelKeys_set_payment_key(this_ptr: &mut InMemoryChannelKeys, mut val: crate::c_types::SecretKey) { unsafe { &mut *this_ptr.inner }.payment_key = val.into_rust(); @@ -666,35 +666,35 @@ pub extern "C" fn InMemoryChannelKeys_new(mut funding_key: crate::c_types::Secre crate::chain::keysinterface::InMemoryChannelKeys { inner: Box::into_raw(Box::new(ret)), is_owned: true } } -/// Remote pubkeys. +/// Counterparty pubkeys. /// Will panic if on_accept wasn't called. #[must_use] #[no_mangle] -pub extern "C" fn InMemoryChannelKeys_remote_pubkeys(this_arg: &InMemoryChannelKeys) -> crate::ln::chan_utils::ChannelPublicKeys { - let mut ret = unsafe { &*this_arg.inner }.remote_pubkeys(); +pub extern "C" fn InMemoryChannelKeys_counterparty_pubkeys(this_arg: &InMemoryChannelKeys) -> crate::ln::chan_utils::ChannelPublicKeys { + let mut ret = unsafe { &*this_arg.inner }.counterparty_pubkeys(); crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } } -/// The to_self_delay value specified by our counterparty and applied on locally-broadcastable +/// The contest delay value specified by our counterparty and applied on holder-broadcastable /// transactions, ie the amount of time that we have to wait to recover our funds if we /// broadcast a transaction. You'll likely want to pass this to the -/// ln::chan_utils::build*_transaction functions when signing local transactions. +/// ln::chan_utils::build*_transaction functions when signing holder transactions. /// Will panic if on_accept wasn't called. #[must_use] #[no_mangle] -pub extern "C" fn InMemoryChannelKeys_remote_to_self_delay(this_arg: &InMemoryChannelKeys) -> u16 { - let mut ret = unsafe { &*this_arg.inner }.remote_to_self_delay(); +pub extern "C" fn InMemoryChannelKeys_counterparty_selected_contest_delay(this_arg: &InMemoryChannelKeys) -> u16 { + let mut ret = unsafe { &*this_arg.inner }.counterparty_selected_contest_delay(); ret } -/// The to_self_delay value specified by us and applied on transactions broadcastable +/// The to_contest delay value specified by us and applied on transactions broadcastable /// by our counterparty, ie the amount of time that they have to wait to recover their funds /// if they broadcast a transaction. /// Will panic if on_accept wasn't called. #[must_use] #[no_mangle] -pub extern "C" fn InMemoryChannelKeys_local_to_self_delay(this_arg: &InMemoryChannelKeys) -> u16 { - let mut ret = unsafe { &*this_arg.inner }.local_to_self_delay(); +pub extern "C" fn InMemoryChannelKeys_holder_selected_contest_delay(this_arg: &InMemoryChannelKeys) -> u16 { + let mut ret = unsafe { &*this_arg.inner }.holder_selected_contest_delay(); ret } @@ -709,11 +709,11 @@ pub extern "C" fn InMemoryChannelKeys_as_ChannelKeys(this_arg: *const InMemoryCh pubkeys: crate::ln::chan_utils::ChannelPublicKeys { inner: std::ptr::null_mut(), is_owned: true }, set_pubkeys: Some(InMemoryChannelKeys_ChannelKeys_set_pubkeys), key_derivation_params: InMemoryChannelKeys_ChannelKeys_key_derivation_params, - sign_remote_commitment: InMemoryChannelKeys_ChannelKeys_sign_remote_commitment, - sign_local_commitment: InMemoryChannelKeys_ChannelKeys_sign_local_commitment, - sign_local_commitment_htlc_transactions: InMemoryChannelKeys_ChannelKeys_sign_local_commitment_htlc_transactions, + sign_counterparty_commitment: InMemoryChannelKeys_ChannelKeys_sign_counterparty_commitment, + sign_holder_commitment: InMemoryChannelKeys_ChannelKeys_sign_holder_commitment, + sign_holder_commitment_htlc_transactions: InMemoryChannelKeys_ChannelKeys_sign_holder_commitment_htlc_transactions, sign_justice_transaction: InMemoryChannelKeys_ChannelKeys_sign_justice_transaction, - sign_remote_htlc_transaction: InMemoryChannelKeys_ChannelKeys_sign_remote_htlc_transaction, + sign_counterparty_htlc_transaction: InMemoryChannelKeys_ChannelKeys_sign_counterparty_htlc_transaction, sign_closing_transaction: InMemoryChannelKeys_ChannelKeys_sign_closing_transaction, sign_channel_announcement: InMemoryChannelKeys_ChannelKeys_sign_channel_announcement, on_accept: InMemoryChannelKeys_ChannelKeys_on_accept, @@ -750,21 +750,21 @@ extern "C" fn InMemoryChannelKeys_ChannelKeys_key_derivation_params(this_arg: *c local_ret } #[must_use] -extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_remote_commitment(this_arg: *const c_void, mut feerate_per_kw: u32, commitment_tx: crate::c_types::Transaction, pre_keys: &crate::ln::chan_utils::PreCalculatedTxCreationKeys, mut htlcs: crate::c_types::derived::CVec_HTLCOutputInCommitmentZ) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ { +extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_counterparty_commitment(this_arg: *const c_void, mut feerate_per_kw: u32, commitment_tx: crate::c_types::Transaction, pre_keys: &crate::ln::chan_utils::PreCalculatedTxCreationKeys, mut htlcs: crate::c_types::derived::CVec_HTLCOutputInCommitmentZ) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ { let mut local_htlcs = Vec::new(); for mut item in htlcs.as_slice().iter() { local_htlcs.push( { unsafe { &*item.inner } }); }; - let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_remote_commitment(feerate_per_kw, &commitment_tx.into_bitcoin(), unsafe { &*pre_keys.inner }, &local_htlcs[..], &bitcoin::secp256k1::Secp256k1::new()); + let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_counterparty_commitment(feerate_per_kw, &commitment_tx.into_bitcoin(), unsafe { &*pre_keys.inner }, &local_htlcs[..], &bitcoin::secp256k1::Secp256k1::new()); let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_orig_ret_0_1 = Vec::new(); for item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { crate::c_types::Signature::from_rust(&item) }); }; let mut local_ret_0 = (crate::c_types::Signature::from_rust(&orig_ret_0_0), local_orig_ret_0_1.into()).into(); local_ret_0 }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) }; local_ret } #[must_use] -extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_local_commitment(this_arg: *const c_void, local_commitment_tx: &crate::ln::chan_utils::LocalCommitmentTransaction) -> crate::c_types::derived::CResult_SignatureNoneZ { - let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_local_commitment(unsafe { &*local_commitment_tx.inner }, &bitcoin::secp256k1::Secp256k1::new()); +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_local_commitment_htlc_transactions(this_arg: *const c_void, local_commitment_tx: &crate::ln::chan_utils::LocalCommitmentTransaction) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ { - let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_local_commitment_htlc_transactions(unsafe { &*local_commitment_tx.inner }, &bitcoin::secp256k1::Secp256k1::new()); +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 } @@ -776,8 +776,8 @@ extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_justice_transaction(this_arg: local_ret } #[must_use] -extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_remote_htlc_transaction(this_arg: *const c_void, htlc_tx: crate::c_types::Transaction, mut input: usize, mut amount: u64, per_commitment_point: crate::c_types::PublicKey, htlc: &crate::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_SignatureNoneZ { - let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_remote_htlc_transaction(&htlc_tx.into_bitcoin(), input, amount, &per_commitment_point.into_rust(), unsafe { &*htlc.inner }, &bitcoin::secp256k1::Secp256k1::new()); +extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_counterparty_htlc_transaction(this_arg: *const c_void, htlc_tx: crate::c_types::Transaction, mut input: usize, mut amount: u64, per_commitment_point: crate::c_types::PublicKey, htlc: &crate::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_SignatureNoneZ { + let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_counterparty_htlc_transaction(&htlc_tx.into_bitcoin(), input, amount, &per_commitment_point.into_rust(), unsafe { &*htlc.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 } @@ -793,8 +793,8 @@ extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_channel_announcement(this_arg 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 } -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) { - unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.on_accept(unsafe { &*channel_pubkeys.inner }, remote_to_self_delay, local_to_self_delay) +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) { + unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.on_accept(unsafe { &*channel_pubkeys.inner }, counterparty_selected_contest_delay, holder_selected_contest_delay) } #[no_mangle] diff --git a/lightning-c-bindings/src/ln/chan_utils.rs b/lightning-c-bindings/src/ln/chan_utils.rs index df9094a5193..d4f551b2317 100644 --- a/lightning-c-bindings/src/ln/chan_utils.rs +++ b/lightning-c-bindings/src/ln/chan_utils.rs @@ -143,48 +143,48 @@ pub extern "C" fn TxCreationKeys_get_revocation_key(this_ptr: &TxCreationKeys) - pub extern "C" fn TxCreationKeys_set_revocation_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) { unsafe { &mut *this_ptr.inner }.revocation_key = val.into_rust(); } -/// A's HTLC Key +/// Broadcaster's HTLC Key #[no_mangle] -pub extern "C" fn TxCreationKeys_get_a_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.a_htlc_key; +pub extern "C" fn TxCreationKeys_get_broadcaster_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.broadcaster_htlc_key; crate::c_types::PublicKey::from_rust(&(*inner_val)) } -/// A's HTLC Key +/// Broadcaster's HTLC Key #[no_mangle] -pub extern "C" fn TxCreationKeys_set_a_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.a_htlc_key = val.into_rust(); +pub extern "C" fn TxCreationKeys_set_broadcaster_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) { + unsafe { &mut *this_ptr.inner }.broadcaster_htlc_key = val.into_rust(); } -/// B's HTLC Key +/// Countersignatory's HTLC Key #[no_mangle] -pub extern "C" fn TxCreationKeys_get_b_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.b_htlc_key; +pub extern "C" fn TxCreationKeys_get_countersignatory_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.countersignatory_htlc_key; crate::c_types::PublicKey::from_rust(&(*inner_val)) } -/// B's HTLC Key +/// Countersignatory's HTLC Key #[no_mangle] -pub extern "C" fn TxCreationKeys_set_b_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.b_htlc_key = val.into_rust(); +pub extern "C" fn TxCreationKeys_set_countersignatory_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) { + unsafe { &mut *this_ptr.inner }.countersignatory_htlc_key = val.into_rust(); } -/// A's Payment Key (which isn't allowed to be spent from for some delay) +/// Payment Key (which isn't allowed to be spent from for some delay) #[no_mangle] -pub extern "C" fn TxCreationKeys_get_a_delayed_payment_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.a_delayed_payment_key; +pub extern "C" fn TxCreationKeys_get_broadcaster_delayed_payment_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.broadcaster_delayed_payment_key; crate::c_types::PublicKey::from_rust(&(*inner_val)) } -/// A's Payment Key (which isn't allowed to be spent from for some delay) +/// Payment Key (which isn't allowed to be spent from for some delay) #[no_mangle] -pub extern "C" fn TxCreationKeys_set_a_delayed_payment_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.a_delayed_payment_key = val.into_rust(); +pub extern "C" fn TxCreationKeys_set_broadcaster_delayed_payment_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) { + unsafe { &mut *this_ptr.inner }.broadcaster_delayed_payment_key = val.into_rust(); } #[must_use] #[no_mangle] -pub extern "C" fn TxCreationKeys_new(mut per_commitment_point_arg: crate::c_types::PublicKey, mut revocation_key_arg: crate::c_types::PublicKey, mut a_htlc_key_arg: crate::c_types::PublicKey, mut b_htlc_key_arg: crate::c_types::PublicKey, mut a_delayed_payment_key_arg: crate::c_types::PublicKey) -> TxCreationKeys { +pub extern "C" fn TxCreationKeys_new(mut per_commitment_point_arg: crate::c_types::PublicKey, mut revocation_key_arg: crate::c_types::PublicKey, mut broadcaster_htlc_key_arg: crate::c_types::PublicKey, mut countersignatory_htlc_key_arg: crate::c_types::PublicKey, mut broadcaster_delayed_payment_key_arg: crate::c_types::PublicKey) -> TxCreationKeys { TxCreationKeys { inner: Box::into_raw(Box::new(nativeTxCreationKeys { per_commitment_point: per_commitment_point_arg.into_rust(), revocation_key: revocation_key_arg.into_rust(), - a_htlc_key: a_htlc_key_arg.into_rust(), - b_htlc_key: b_htlc_key_arg.into_rust(), - a_delayed_payment_key: a_delayed_payment_key_arg.into_rust(), + broadcaster_htlc_key: broadcaster_htlc_key_arg.into_rust(), + countersignatory_htlc_key: countersignatory_htlc_key_arg.into_rust(), + broadcaster_delayed_payment_key: broadcaster_delayed_payment_key_arg.into_rust(), })), is_owned: true } } #[no_mangle] @@ -347,7 +347,7 @@ pub extern "C" fn ChannelPublicKeys_set_revocation_basepoint(this_ptr: &mut Chan unsafe { &mut *this_ptr.inner }.revocation_basepoint = val.into_rust(); } /// 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. #[no_mangle] pub extern "C" fn ChannelPublicKeys_get_payment_point(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey { @@ -355,7 +355,7 @@ pub extern "C" fn ChannelPublicKeys_get_payment_point(this_ptr: &ChannelPublicKe crate::c_types::PublicKey::from_rust(&(*inner_val)) } /// 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. #[no_mangle] pub extern "C" fn ChannelPublicKeys_set_payment_point(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) { @@ -422,11 +422,11 @@ pub extern "C" fn TxCreationKeys_derive_new(per_commitment_point: crate::c_types } /// A script either spendable by the revocation -/// key or the delayed_payment_key and satisfying the relative-locktime OP_CSV constrain. +/// key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain. /// Encumbering a `to_local` output on a commitment transaction or 2nd-stage HTLC transactions. #[no_mangle] -pub extern "C" fn get_revokeable_redeemscript(revocation_key: crate::c_types::PublicKey, mut to_self_delay: u16, delayed_payment_key: crate::c_types::PublicKey) -> crate::c_types::derived::CVec_u8Z { - let mut ret = lightning::ln::chan_utils::get_revokeable_redeemscript(&revocation_key.into_rust(), to_self_delay, &delayed_payment_key.into_rust()); +pub extern "C" fn get_revokeable_redeemscript(revocation_key: crate::c_types::PublicKey, mut to_self_delay: u16, broadcaster_delayed_payment_key: crate::c_types::PublicKey) -> crate::c_types::derived::CVec_u8Z { + let mut ret = lightning::ln::chan_utils::get_revokeable_redeemscript(&revocation_key.into_rust(), to_self_delay, &broadcaster_delayed_payment_key.into_rust()); ret.into_bytes().into() } @@ -484,7 +484,7 @@ pub(crate) extern "C" fn HTLCOutputInCommitment_clone_void(this_ptr: *const c_vo /// 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. #[no_mangle] pub extern "C" fn HTLCOutputInCommitment_get_offered(this_ptr: &HTLCOutputInCommitment) -> bool { 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 /// 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. #[no_mangle] pub extern "C" fn HTLCOutputInCommitment_set_offered(this_ptr: &mut HTLCOutputInCommitment, mut val: bool) { unsafe { &mut *this_ptr.inner }.offered = val; @@ -563,29 +563,29 @@ pub extern "C" fn make_funding_redeemscript(a: crate::c_types::PublicKey, b: cra /// panics if htlc.transaction_output_index.is_none()! #[no_mangle] -pub extern "C" fn build_htlc_transaction(prev_hash: *const [u8; 32], mut feerate_per_kw: u32, mut to_self_delay: u16, htlc: &crate::ln::chan_utils::HTLCOutputInCommitment, a_delayed_payment_key: crate::c_types::PublicKey, revocation_key: crate::c_types::PublicKey) -> crate::c_types::derived::CVec_u8Z { - let mut ret = lightning::ln::chan_utils::build_htlc_transaction(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*prev_hash }[..]).unwrap(), feerate_per_kw, to_self_delay, unsafe { &*htlc.inner }, &a_delayed_payment_key.into_rust(), &revocation_key.into_rust()); +pub extern "C" fn build_htlc_transaction(prev_hash: *const [u8; 32], mut feerate_per_kw: u32, mut to_self_delay: u16, htlc: &crate::ln::chan_utils::HTLCOutputInCommitment, broadcaster_delayed_payment_key: crate::c_types::PublicKey, revocation_key: crate::c_types::PublicKey) -> crate::c_types::derived::CVec_u8Z { + let mut ret = lightning::ln::chan_utils::build_htlc_transaction(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*prev_hash }[..]).unwrap(), feerate_per_kw, to_self_delay, unsafe { &*htlc.inner }, &broadcaster_delayed_payment_key.into_rust(), &revocation_key.into_rust()); let mut local_ret = ::bitcoin::consensus::encode::serialize(&ret); local_ret.into() } -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 +/// 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. #[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,85 +619,85 @@ 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. +/// 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. /// -/// 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(). #[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, -/// 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. #[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 { - 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 } +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 { + 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 }); }; + 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); + 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 +/// Get the txid of the holder commitment transaction contained in this +/// 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() } } @@ -708,12 +708,12 @@ pub extern "C" fn LocalCommitmentTransaction_txid(this_arg: &LocalCommitmentTran /// 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. #[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 { - 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()); +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 { + 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()); 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 } } } diff --git a/lightning-c-bindings/src/ln/channelmonitor.rs b/lightning-c-bindings/src/ln/channelmonitor.rs index cd6507acffb..c53d7197ac6 100644 --- a/lightning-c-bindings/src/ln/channelmonitor.rs +++ b/lightning-c-bindings/src/ln/channelmonitor.rs @@ -542,8 +542,8 @@ pub extern "C" fn ChannelMonitor_get_and_clear_pending_events(this_arg: &mut Cha /// In any-case, choice is up to the user. #[must_use] #[no_mangle] -pub extern "C" fn ChannelMonitor_get_latest_local_commitment_txn(this_arg: &mut ChannelMonitor, logger: &crate::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionZ { - let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeChannelMonitor)) }.get_latest_local_commitment_txn(logger); +pub extern "C" fn ChannelMonitor_get_latest_holder_commitment_txn(this_arg: &mut ChannelMonitor, logger: &crate::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionZ { + let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeChannelMonitor)) }.get_latest_holder_commitment_txn(logger); let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { let mut local_ret_0 = ::bitcoin::consensus::encode::serialize(&item); local_ret_0.into() }); }; local_ret.into() } diff --git a/lightning/src/chain/keysinterface.rs b/lightning/src/chain/keysinterface.rs index 3c115bc770b..1cc41b0f8fa 100644 --- a/lightning/src/chain/keysinterface.rs +++ b/lightning/src/chain/keysinterface.rs @@ -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}; @@ -71,14 +71,14 @@ pub enum SpendableOutputDescriptor { /// it is an output from an old state which we broadcast (which should never happen). /// /// To derive the delayed_payment key which is used to sign for this input, you must pass the - /// local delayed_payment_base_key (ie the private key which corresponds to the pubkey in + /// holder delayed_payment_base_key (ie the private key which corresponds to the pubkey in /// ChannelKeys::pubkeys().delayed_payment_basepoint) and the provided per_commitment_point to /// chan_utils::derive_private_key. The public key can be generated without the secret key /// using chan_utils::derive_public_key and only the delayed_payment_basepoint which appears in /// ChannelKeys::pubkeys(). /// - /// To derive the remote_revocation_pubkey provided here (which is used in the witness - /// script generation), you must pass the remote revocation_basepoint (which appears in the + /// 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 remote_revocation_pubkey used to derive witnessScript - remote_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). @@ -111,7 +111,7 @@ pub enum SpendableOutputDescriptor { /// /// These are generally the result of our counterparty having broadcast the current state, /// allowing us to claim the non-HTLC-encumbered outputs immediately. - StaticOutputRemotePayment { + StaticOutputCounterpartyPayment { /// The outpoint which is spendable outpoint: OutPoint, /// The output which is reference by the given outpoint @@ -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 remote_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,9 +138,9 @@ impl Writeable for SpendableOutputDescriptor { output.write(writer)?; key_derivation_params.0.write(writer)?; key_derivation_params.1.write(writer)?; - remote_revocation_pubkey.write(writer)?; + revocation_pubkey.write(writer)?; }, - &SpendableOutputDescriptor::StaticOutputRemotePayment { ref outpoint, ref output, ref key_derivation_params } => { + &SpendableOutputDescriptor::StaticOutputCounterpartyPayment { ref outpoint, ref output, ref key_derivation_params } => { 2u8.write(writer)?; outpoint.write(writer)?; output.write(writer)?; @@ -165,9 +165,9 @@ impl Readable for SpendableOutputDescriptor { to_self_delay: Readable::read(reader)?, output: Readable::read(reader)?, key_derivation_params: (Readable::read(reader)?, Readable::read(reader)?), - remote_revocation_pubkey: Readable::read(reader)?, + revocation_pubkey: Readable::read(reader)?, }), - 2u8 => Ok(SpendableOutputDescriptor::StaticOutputRemotePayment { + 2u8 => Ok(SpendableOutputDescriptor::StaticOutputCounterpartyPayment { outpoint: Readable::read(reader)?, output: Readable::read(reader)?, key_derivation_params: (Readable::read(reader)?, Readable::read(reader)?), @@ -219,52 +219,52 @@ pub trait ChannelKeys : Send+Clone { /// Note that the commitment number starts at (1 << 48) - 1 and counts backwards. /// TODO: return a Result so we can signal a validation error fn release_commitment_secret(&self, idx: u64) -> [u8; 32]; - /// Gets the local channel public keys and basepoints + /// Gets the holder's channel public keys and basepoints fn pubkeys(&self) -> &ChannelPublicKeys; /// Gets arbitrary identifiers describing the set of keys which are provided back to you in /// some SpendableOutputDescriptor types. These should be sufficient to identify this /// ChannelKeys object uniquely and lookup or re-derive its keys. fn key_derivation_params(&self) -> (u64, u64); - /// Create a signature for a remote commitment transaction and associated HTLC transactions. + /// Create a signature for a counterparty's commitment transaction and associated HTLC transactions. /// /// Note that if signing fails or is rejected, the channel will be force-closed. // // 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 // making the callee generate it via some util function we expose)! - fn sign_remote_commitment(&self, feerate_per_kw: u32, commitment_tx: &Transaction, keys: &PreCalculatedTxCreationKeys, htlcs: &[&HTLCOutputInCommitment], secp_ctx: &Secp256k1) -> Result<(Signature, Vec), ()>; + fn sign_counterparty_commitment(&self, feerate_per_kw: u32, commitment_tx: &Transaction, keys: &PreCalculatedTxCreationKeys, htlcs: &[&HTLCOutputInCommitment], secp_ctx: &Secp256k1) -> Result<(Signature, Vec), ()>; - /// Create a signature for a local commitment transaction. This will only ever be called with - /// the same local_commitment_tx (or a copy thereof), though there are currently no guarantees + /// Create a signature for a holder's commitment transaction. This will only ever be called with + /// the same holder_commitment_tx (or a copy thereof), though there are currently no guarantees /// that it will not be called multiple times. /// An external signer implementation should check that the commitment has not been revoked. // // 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_local_commitment(&self, local_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1) -> Result; + fn sign_holder_commitment(&self, holder_commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1) -> Result; - /// Same as sign_local_commitment, but exists only for tests to get access to local commitment + /// 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_local_commitment may enforce that we only ever + /// 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_local_commitment(&self, local_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1) -> Result; + fn unsafe_sign_holder_commitment(&self, holder_commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1) -> Result; - /// Create a signature for each HTLC transaction spending a local commitment transaction. + /// Create a signature for each HTLC transaction spending a holder's commitment transaction. /// - /// Unlike sign_local_commitment, this may be called multiple times with *different* - /// local_commitment_tx values. While this will never be called with a revoked - /// local_commitment_tx, it is possible that it is called with the second-latest - /// local_commitment_tx (only if we haven't yet revoked it) if some watchtower/secondary + /// Unlike sign_holder_commitment, this may be called multiple times with *different* + /// holder_commitment_tx values. While this will never be called with a revoked + /// holder_commitment_tx, it is possible that it is called with the second-latest + /// holder_commitment_tx (only if we haven't yet revoked it) if some watchtower/secondary /// ChannelMonitor decided to broadcast before it had been updated to the latest. /// /// Either an Err should be returned, or a Vec with one entry for each HTLC which exists in - /// local_commitment_tx. For those HTLCs which have transaction_output_index set to None + /// holder_commitment_tx. For those HTLCs which have transaction_output_index set to None /// (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_local_commitment_htlc_transactions(&self, local_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1) -> Result>, ()>; + fn sign_holder_commitment_htlc_transactions(&self, holder_commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1) -> Result>, ()>; /// Create a signature for the given input in a transaction spending an HTLC or commitment /// transaction output when our counterparty broadcasts an old state. @@ -277,8 +277,8 @@ pub trait ChannelKeys : Send+Clone { /// Amount is value of the output spent by this input, committed to in the BIP 143 signature. /// /// per_commitment_key is revocation secret which was provided by our counterparty when they - /// revoked the state which they eventually broadcast. It's not a _local_ secret key and does - /// not allow the spending of any funds by itself (you need our local revocation_secret to do + /// revoked the state which they eventually broadcast. It's not a _holder_ secret key and does + /// not allow the spending of any funds by itself (you need our holder revocation_secret to do /// so). /// /// htlc holds HTLC elements (hash, timelock) if the output being spent is a HTLC output, thus @@ -286,7 +286,7 @@ pub trait ChannelKeys : Send+Clone { /// signatures). fn sign_justice_transaction(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, htlc: &Option, secp_ctx: &Secp256k1) -> Result; - /// Create a signature for a claiming transaction for a HTLC output on a remote commitment + /// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment /// transaction, either offered or received. /// /// Such a transaction may claim multiples offered outputs at same time if we know the @@ -303,7 +303,7 @@ pub trait ChannelKeys : Send+Clone { /// detected onchain. It has been generated by our counterparty and is used to derive /// channel state keys, which are then included in the witness script and committed to in the /// BIP 143 signature. - fn sign_remote_htlc_transaction(&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1) -> Result; + fn sign_counterparty_htlc_transaction(&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1) -> Result; /// Create a signature for a (proposed) closing transaction. /// @@ -319,13 +319,13 @@ pub trait ChannelKeys : Send+Clone { /// protocol. fn sign_channel_announcement(&self, msg: &UnsignedChannelAnnouncement, secp_ctx: &Secp256k1) -> Result; - /// Set the remote channel basepoints and remote/local to_self_delay. + /// Set the counterparty channel basepoints and counterparty_selected/holder_selected_contest_delay. /// This is done immediately on incoming channels and as soon as the channel is accepted on outgoing channels. /// - /// We bind local_to_self_delay late here for API convenience. + /// We bind holder_selected_contest_delay late here for API convenience. /// /// Will be called before any signatures are applied. - fn on_accept(&mut self, channel_points: &ChannelPublicKeys, remote_to_self_delay: u16, local_to_self_delay: u16); + fn on_accept(&mut self, channel_points: &ChannelPublicKeys, counterparty_selected_contest_delay: u16, holder_selected_contest_delay: u16); } /// A trait to describe an object which can get user secrets and key material. @@ -354,17 +354,17 @@ pub trait KeysInterface: Send + Sync { /// when receiving an open_channel for an inbound channel or when /// receiving accept_channel for an outbound channel. struct AcceptedChannelData { - /// Remote public keys and base points - remote_channel_pubkeys: ChannelPublicKeys, - /// The to_self_delay value specified by our counterparty and applied on locally-broadcastable + /// Counterparty public keys and base points + counterparty_channel_pubkeys: ChannelPublicKeys, + /// The contest_delay value specified by our counterparty and applied on holder-broadcastable /// transactions, ie the amount of time that we have to wait to recover our funds if we /// broadcast a transaction. You'll likely want to pass this to the - /// ln::chan_utils::build*_transaction functions when signing local transactions. - remote_to_self_delay: u16, - /// The to_self_delay value specified by us and applied on transactions broadcastable + /// ln::chan_utils::build*_transaction functions when signing holder's transactions. + counterparty_selected_contest_delay: u16, + /// The contest_delay value specified by us and applied on transactions broadcastable /// by our counterparty, ie the amount of time that they have to wait to recover their funds /// if they broadcast a transaction. - local_to_self_delay: u16, + holder_selected_contest_delay: u16, } #[derive(Clone)] @@ -372,19 +372,19 @@ struct AcceptedChannelData { pub struct InMemoryChannelKeys { /// Private key of anchor tx pub funding_key: SecretKey, - /// Local secret key for blinded revocation pubkey + /// Holder secret key for blinded revocation pubkey pub revocation_base_key: SecretKey, - /// Local secret key used for our balance in remote-broadcasted commitment transactions + /// Holder secret key used for our balance in counterparty-broadcasted commitment transactions pub payment_key: SecretKey, - /// Local secret key used in HTLC tx + /// Holder secret key used in HTLC tx pub delayed_payment_base_key: SecretKey, - /// Local htlc secret key used in commitment tx htlc outputs + /// Holder htlc secret key used in commitment tx htlc outputs pub htlc_base_key: SecretKey, /// Commitment seed pub commitment_seed: [u8; 32], - /// Local public keys and basepoints - pub(crate) local_channel_pubkeys: ChannelPublicKeys, - /// Remote public keys and remote/local to_self_delay, populated on channel acceptance + /// Holder public keys and basepoints + pub(crate) holder_channel_pubkeys: ChannelPublicKeys, + /// Counterparty public keys and counterparty/holder selected_contest_delay, populated on channel acceptance accepted_channel_data: Option, /// The total value of this channel channel_value_satoshis: u64, @@ -404,8 +404,8 @@ impl InMemoryChannelKeys { commitment_seed: [u8; 32], channel_value_satoshis: u64, key_derivation_params: (u64, u64)) -> InMemoryChannelKeys { - let local_channel_pubkeys = - InMemoryChannelKeys::make_local_keys(secp_ctx, &funding_key, &revocation_base_key, + let holder_channel_pubkeys = + InMemoryChannelKeys::make_holder_keys(secp_ctx, &funding_key, &revocation_base_key, &payment_key, &delayed_payment_base_key, &htlc_base_key); InMemoryChannelKeys { @@ -416,13 +416,13 @@ impl InMemoryChannelKeys { htlc_base_key, commitment_seed, channel_value_satoshis, - local_channel_pubkeys, + holder_channel_pubkeys, accepted_channel_data: None, key_derivation_params, } } - fn make_local_keys(secp_ctx: &Secp256k1, + fn make_holder_keys(secp_ctx: &Secp256k1, funding_key: &SecretKey, revocation_base_key: &SecretKey, payment_key: &SecretKey, @@ -438,22 +438,22 @@ impl InMemoryChannelKeys { } } - /// Remote pubkeys. + /// Counterparty pubkeys. /// Will panic if on_accept wasn't called. - pub fn remote_pubkeys(&self) -> &ChannelPublicKeys { &self.accepted_channel_data.as_ref().unwrap().remote_channel_pubkeys } + pub fn counterparty_pubkeys(&self) -> &ChannelPublicKeys { &self.accepted_channel_data.as_ref().unwrap().counterparty_channel_pubkeys } - /// The to_self_delay value specified by our counterparty and applied on locally-broadcastable + /// The contest_delay value specified by our counterparty and applied on holder-broadcastable /// transactions, ie the amount of time that we have to wait to recover our funds if we /// broadcast a transaction. You'll likely want to pass this to the - /// ln::chan_utils::build*_transaction functions when signing local transactions. + /// ln::chan_utils::build*_transaction functions when signing holder's transactions. /// Will panic if on_accept wasn't called. - pub fn remote_to_self_delay(&self) -> u16 { self.accepted_channel_data.as_ref().unwrap().remote_to_self_delay } + pub fn counterparty_selected_contest_delay(&self) -> u16 { self.accepted_channel_data.as_ref().unwrap().counterparty_selected_contest_delay } - /// The to_self_delay value specified by us and applied on transactions broadcastable + /// The contest_delay value specified by us and applied on transactions broadcastable /// by our counterparty, ie the amount of time that they have to wait to recover their funds /// if they broadcast a transaction. /// Will panic if on_accept wasn't called. - pub fn local_to_self_delay(&self) -> u16 { self.accepted_channel_data.as_ref().unwrap().local_to_self_delay } + pub fn holder_selected_contest_delay(&self) -> u16 { self.accepted_channel_data.as_ref().unwrap().holder_selected_contest_delay } } impl ChannelKeys for InMemoryChannelKeys { @@ -466,16 +466,16 @@ impl ChannelKeys for InMemoryChannelKeys { chan_utils::build_commitment_secret(&self.commitment_seed, idx) } - fn pubkeys(&self) -> &ChannelPublicKeys { &self.local_channel_pubkeys } + fn pubkeys(&self) -> &ChannelPublicKeys { &self.holder_channel_pubkeys } fn key_derivation_params(&self) -> (u64, u64) { self.key_derivation_params } - fn sign_remote_commitment(&self, feerate_per_kw: u32, commitment_tx: &Transaction, pre_keys: &PreCalculatedTxCreationKeys, htlcs: &[&HTLCOutputInCommitment], secp_ctx: &Secp256k1) -> Result<(Signature, Vec), ()> { + fn sign_counterparty_commitment(&self, feerate_per_kw: u32, commitment_tx: &Transaction, pre_keys: &PreCalculatedTxCreationKeys, htlcs: &[&HTLCOutputInCommitment], secp_ctx: &Secp256k1) -> Result<(Signature, Vec), ()> { if commitment_tx.input.len() != 1 { return Err(()); } let keys = pre_keys.trust_key_derivation(); let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key); let accepted_data = self.accepted_channel_data.as_ref().expect("must accept before signing"); - let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &accepted_data.remote_channel_pubkeys.funding_pubkey); + let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &accepted_data.counterparty_channel_pubkeys.funding_pubkey); let commitment_sighash = hash_to_message!(&bip143::SigHashCache::new(commitment_tx).signature_hash(0, &channel_funding_redeemscript, self.channel_value_satoshis, SigHashType::All)[..]); let commitment_sig = secp_ctx.sign(&commitment_sighash, &self.funding_key); @@ -485,7 +485,7 @@ impl ChannelKeys for InMemoryChannelKeys { let mut htlc_sigs = Vec::with_capacity(htlcs.len()); for ref htlc in htlcs { if let Some(_) = htlc.transaction_output_index { - let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, feerate_per_kw, accepted_data.local_to_self_delay, htlc, &keys.a_delayed_payment_key, &keys.revocation_key); + let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, feerate_per_kw, accepted_data.holder_selected_contest_delay, htlc, &keys.broadcaster_delayed_payment_key, &keys.revocation_key); let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, &keys); let htlc_sighash = hash_to_message!(&bip143::SigHashCache::new(&htlc_tx).signature_hash(0, &htlc_redeemscript, htlc.amount_msat / 1000, SigHashType::All)[..]); let our_htlc_key = match chan_utils::derive_private_key(&secp_ctx, &keys.per_commitment_point, &self.htlc_base_key) { @@ -499,26 +499,26 @@ impl ChannelKeys for InMemoryChannelKeys { Ok((commitment_sig, htlc_sigs)) } - fn sign_local_commitment(&self, local_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1) -> Result { + fn sign_holder_commitment(&self, holder_commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1) -> Result { let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key); - let remote_channel_data = self.accepted_channel_data.as_ref().expect("must accept before signing"); - let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &remote_channel_data.remote_channel_pubkeys.funding_pubkey); + 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(local_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_local_commitment(&self, local_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1) -> Result { + fn unsafe_sign_holder_commitment(&self, holder_commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1) -> Result { let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key); - let remote_channel_pubkeys = &self.accepted_channel_data.as_ref().expect("must accept before signing").remote_channel_pubkeys; - let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &remote_channel_pubkeys.funding_pubkey); + 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(local_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_local_commitment_htlc_transactions(&self, local_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1) -> Result>, ()> { - let local_csv = self.accepted_channel_data.as_ref().unwrap().remote_to_self_delay; - local_commitment_tx.get_htlc_sigs(&self.htlc_base_key, local_csv, secp_ctx) + fn sign_holder_commitment_htlc_transactions(&self, holder_commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1) -> Result>, ()> { + 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) } fn sign_justice_transaction(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, htlc: &Option, secp_ctx: &Secp256k1) -> Result { @@ -532,33 +532,33 @@ impl ChannelKeys for InMemoryChannelKeys { Err(_) => return Err(()) }; let witness_script = if let &Some(ref htlc) = htlc { - let remote_htlcpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().htlc_basepoint) { - Ok(remote_htlcpubkey) => remote_htlcpubkey, + let counterparty_htlcpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.counterparty_pubkeys().htlc_basepoint) { + Ok(counterparty_htlcpubkey) => counterparty_htlcpubkey, Err(_) => return Err(()) }; - let local_htlcpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.pubkeys().htlc_basepoint) { - Ok(local_htlcpubkey) => local_htlcpubkey, + let holder_htlcpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.pubkeys().htlc_basepoint) { + Ok(holder_htlcpubkey) => holder_htlcpubkey, Err(_) => return Err(()) }; - chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &remote_htlcpubkey, &local_htlcpubkey, &revocation_pubkey) + chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &counterparty_htlcpubkey, &holder_htlcpubkey, &revocation_pubkey) } else { - let remote_delayedpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().delayed_payment_basepoint) { - Ok(remote_delayedpubkey) => remote_delayedpubkey, + let counterparty_delayedpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.counterparty_pubkeys().delayed_payment_basepoint) { + Ok(counterparty_delayedpubkey) => counterparty_delayedpubkey, Err(_) => return Err(()) }; - chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.local_to_self_delay(), &remote_delayedpubkey) + chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.holder_selected_contest_delay(), &counterparty_delayedpubkey) }; let mut sighash_parts = bip143::SigHashCache::new(justice_tx); let sighash = hash_to_message!(&sighash_parts.signature_hash(input, &witness_script, amount, SigHashType::All)[..]); return Ok(secp_ctx.sign(&sighash, &revocation_key)) } - fn sign_remote_htlc_transaction(&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1) -> Result { + fn sign_counterparty_htlc_transaction(&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1) -> Result { if let Ok(htlc_key) = chan_utils::derive_private_key(&secp_ctx, &per_commitment_point, &self.htlc_base_key) { let witness_script = if let Ok(revocation_pubkey) = chan_utils::derive_public_revocation_key(&secp_ctx, &per_commitment_point, &self.pubkeys().revocation_basepoint) { - if let Ok(remote_htlcpubkey) = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().htlc_basepoint) { - if let Ok(local_htlcpubkey) = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.pubkeys().htlc_basepoint) { - chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &remote_htlcpubkey, &local_htlcpubkey, &revocation_pubkey) + if let Ok(counterparty_htlcpubkey) = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.counterparty_pubkeys().htlc_basepoint) { + if let Ok(htlcpubkey) = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.pubkeys().htlc_basepoint) { + chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &counterparty_htlcpubkey, &htlcpubkey, &revocation_pubkey) } else { return Err(()) } } else { return Err(()) } } else { return Err(()) }; @@ -575,8 +575,8 @@ impl ChannelKeys for InMemoryChannelKeys { if closing_tx.output.len() > 2 { return Err(()); } let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key); - let remote_channel_data = self.accepted_channel_data.as_ref().expect("must accept before signing"); - let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &remote_channel_data.remote_channel_pubkeys.funding_pubkey); + 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); let sighash = hash_to_message!(&bip143::SigHashCache::new(closing_tx) .signature_hash(0, &channel_funding_redeemscript, self.channel_value_satoshis, SigHashType::All)[..]); @@ -588,18 +588,18 @@ impl ChannelKeys for InMemoryChannelKeys { Ok(secp_ctx.sign(&msghash, &self.funding_key)) } - fn on_accept(&mut self, channel_pubkeys: &ChannelPublicKeys, remote_to_self_delay: u16, local_to_self_delay: u16) { + fn on_accept(&mut self, channel_pubkeys: &ChannelPublicKeys, counterparty_selected_contest_delay: u16, holder_selected_contest_delay: u16) { assert!(self.accepted_channel_data.is_none(), "Already accepted"); self.accepted_channel_data = Some(AcceptedChannelData { - remote_channel_pubkeys: channel_pubkeys.clone(), - remote_to_self_delay, - local_to_self_delay, + counterparty_channel_pubkeys: channel_pubkeys.clone(), + counterparty_selected_contest_delay, + holder_selected_contest_delay, }); } } impl_writeable!(AcceptedChannelData, 0, - { remote_channel_pubkeys, remote_to_self_delay, local_to_self_delay }); + { counterparty_channel_pubkeys, counterparty_selected_contest_delay, holder_selected_contest_delay }); impl Writeable for InMemoryChannelKeys { fn write(&self, writer: &mut W) -> Result<(), Error> { @@ -626,11 +626,11 @@ impl Readable for InMemoryChannelKeys { let delayed_payment_base_key = Readable::read(reader)?; let htlc_base_key = Readable::read(reader)?; let commitment_seed = Readable::read(reader)?; - let remote_channel_data = Readable::read(reader)?; + let counterparty_channel_data = Readable::read(reader)?; let channel_value_satoshis = Readable::read(reader)?; let secp_ctx = Secp256k1::signing_only(); - let local_channel_pubkeys = - InMemoryChannelKeys::make_local_keys(&secp_ctx, &funding_key, &revocation_base_key, + let holder_channel_pubkeys = + InMemoryChannelKeys::make_holder_keys(&secp_ctx, &funding_key, &revocation_base_key, &payment_key, &delayed_payment_base_key, &htlc_base_key); let params_1 = Readable::read(reader)?; @@ -644,8 +644,8 @@ impl Readable for InMemoryChannelKeys { htlc_base_key, commitment_seed, channel_value_satoshis, - local_channel_pubkeys, - accepted_channel_data: remote_channel_data, + holder_channel_pubkeys, + accepted_channel_data: counterparty_channel_data, key_derivation_params: (params_1, params_2), }) } diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs index beec838391a..89f39ed8ff8 100644 --- a/lightning/src/ln/chan_utils.rs +++ b/lightning/src/ln/chan_utils.rs @@ -217,15 +217,20 @@ pub fn derive_public_key(secp_ctx: &Secp256k1, per_com /// Derives a per-commitment-transaction revocation key from its constituent parts. /// +/// Only the cheating participant owns a valid witness to propagate a revoked +/// commitment transaction, thus per_commitment_secret always come from cheater +/// and revocation_base_secret always come from punisher, which is the broadcaster +/// of the transaction spending with this key knowledge. +/// /// Note that this is infallible iff we trust that at least one of the two input keys are randomly /// generated (ie our own). -pub fn derive_private_revocation_key(secp_ctx: &Secp256k1, per_commitment_secret: &SecretKey, revocation_base_secret: &SecretKey) -> Result { - let revocation_base_point = PublicKey::from_secret_key(&secp_ctx, &revocation_base_secret); +pub fn derive_private_revocation_key(secp_ctx: &Secp256k1, per_commitment_secret: &SecretKey, countersignatory_revocation_base_secret: &SecretKey) -> Result { + let countersignatory_revocation_base_point = PublicKey::from_secret_key(&secp_ctx, &countersignatory_revocation_base_secret); let per_commitment_point = PublicKey::from_secret_key(&secp_ctx, &per_commitment_secret); let rev_append_commit_hash_key = { let mut sha = Sha256::engine(); - sha.input(&revocation_base_point.serialize()); + sha.input(&countersignatory_revocation_base_point.serialize()); sha.input(&per_commitment_point.serialize()); Sha256::from_engine(sha).into_inner() @@ -233,29 +238,34 @@ pub fn derive_private_revocation_key(secp_ctx: &Secp256k1 let commit_append_rev_hash_key = { let mut sha = Sha256::engine(); sha.input(&per_commitment_point.serialize()); - sha.input(&revocation_base_point.serialize()); + sha.input(&countersignatory_revocation_base_point.serialize()); Sha256::from_engine(sha).into_inner() }; - let mut part_a = revocation_base_secret.clone(); - part_a.mul_assign(&rev_append_commit_hash_key)?; - let mut part_b = per_commitment_secret.clone(); - part_b.mul_assign(&commit_append_rev_hash_key)?; - part_a.add_assign(&part_b[..])?; - Ok(part_a) + let mut countersignatory_contrib = countersignatory_revocation_base_secret.clone(); + countersignatory_contrib.mul_assign(&rev_append_commit_hash_key)?; + let mut broadcaster_contrib = per_commitment_secret.clone(); + broadcaster_contrib.mul_assign(&commit_append_rev_hash_key)?; + countersignatory_contrib.add_assign(&broadcaster_contrib[..])?; + Ok(countersignatory_contrib) } /// Derives a per-commitment-transaction revocation public key from its constituent parts. This is /// the public equivalend of derive_private_revocation_key - using only public keys to derive a /// public key instead of private keys. /// +/// Only the cheating participant owns a valid witness to propagate a revoked +/// commitment transaction, thus per_commitment_point always come from cheater +/// and revocation_base_point always come from punisher, which is the broadcaster +/// of the transaction spending with this key knowledge. +/// /// Note that this is infallible iff we trust that at least one of the two input keys are randomly /// generated (ie our own). -pub fn derive_public_revocation_key(secp_ctx: &Secp256k1, per_commitment_point: &PublicKey, revocation_base_point: &PublicKey) -> Result { +pub fn derive_public_revocation_key(secp_ctx: &Secp256k1, per_commitment_point: &PublicKey, countersignatory_revocation_base_point: &PublicKey) -> Result { let rev_append_commit_hash_key = { let mut sha = Sha256::engine(); - sha.input(&revocation_base_point.serialize()); + sha.input(&countersignatory_revocation_base_point.serialize()); sha.input(&per_commitment_point.serialize()); Sha256::from_engine(sha).into_inner() @@ -263,41 +273,46 @@ pub fn derive_public_revocation_key(secp_ctx: &Secp2 let commit_append_rev_hash_key = { let mut sha = Sha256::engine(); sha.input(&per_commitment_point.serialize()); - sha.input(&revocation_base_point.serialize()); + sha.input(&countersignatory_revocation_base_point.serialize()); Sha256::from_engine(sha).into_inner() }; - let mut part_a = revocation_base_point.clone(); - part_a.mul_assign(&secp_ctx, &rev_append_commit_hash_key)?; - let mut part_b = per_commitment_point.clone(); - part_b.mul_assign(&secp_ctx, &commit_append_rev_hash_key)?; - part_a.combine(&part_b) + let mut countersignatory_contrib = countersignatory_revocation_base_point.clone(); + countersignatory_contrib.mul_assign(&secp_ctx, &rev_append_commit_hash_key)?; + let mut broadcaster_contrib = per_commitment_point.clone(); + broadcaster_contrib.mul_assign(&secp_ctx, &commit_append_rev_hash_key)?; + countersignatory_contrib.combine(&broadcaster_contrib) } /// The set of public keys which are used in the creation of one commitment transaction. /// These are derived from the channel base keys and per-commitment data. /// +/// A broadcaster key is provided from potential broadcaster of the computed transaction. +/// A countersignatory key is coming from a protocol participant unable to broadcast the +/// transaction. +/// /// These keys are assumed to be good, either because the code derived them from /// channel basepoints via the new function, or they were obtained via /// PreCalculatedTxCreationKeys.trust_key_derivation because we trusted the source of the /// pre-calculated keys. #[derive(PartialEq, Clone)] pub struct TxCreationKeys { - /// The per-commitment public key which was used to derive the other keys. + /// The broadcaster's per-commitment public key which was used to derive the other keys. pub per_commitment_point: PublicKey, - /// The revocation key which is used to allow the owner of the commitment transaction to - /// provide their counterparty the ability to punish them if they broadcast an old state. + /// The revocation key which is used to allow the broadcaster of the commitment + /// transaction to provide their counterparty the ability to punish them if they broadcast + /// an old state. pub revocation_key: PublicKey, - /// A's HTLC Key - pub a_htlc_key: PublicKey, - /// B's HTLC Key - pub b_htlc_key: PublicKey, - /// A's Payment Key (which isn't allowed to be spent from for some delay) - pub a_delayed_payment_key: PublicKey, + /// Broadcaster's HTLC Key + pub broadcaster_htlc_key: PublicKey, + /// Countersignatory's HTLC Key + pub countersignatory_htlc_key: PublicKey, + /// Broadcaster's Payment Key (which isn't allowed to be spent from for some delay) + pub broadcaster_delayed_payment_key: PublicKey, } impl_writeable!(TxCreationKeys, 33*6, - { per_commitment_point, revocation_key, a_htlc_key, b_htlc_key, a_delayed_payment_key }); + { per_commitment_point, revocation_key, broadcaster_htlc_key, countersignatory_htlc_key, broadcaster_delayed_payment_key }); /// The per-commitment point and a set of pre-calculated public keys used for transaction creation /// in the signer. @@ -334,8 +349,8 @@ pub struct ChannelPublicKeys { /// counterparty to create a secret which the counterparty can reveal to revoke previous /// 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 + /// The public key which receives an immediately spendable primary channel balance in + /// a broadcaster's 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 @@ -358,28 +373,28 @@ impl_writeable!(ChannelPublicKeys, 33*5, { impl TxCreationKeys { /// Create a new TxCreationKeys from channel base points and the per-commitment point - pub fn derive_new(secp_ctx: &Secp256k1, per_commitment_point: &PublicKey, a_delayed_payment_base: &PublicKey, a_htlc_base: &PublicKey, b_revocation_base: &PublicKey, b_htlc_base: &PublicKey) -> Result { + pub fn derive_new(secp_ctx: &Secp256k1, per_commitment_point: &PublicKey, broadcaster_delayed_payment_base: &PublicKey, broadcaster_htlc_base: &PublicKey, countersignatory_revocation_base: &PublicKey, countersignatory_htlc_base: &PublicKey) -> Result { Ok(TxCreationKeys { per_commitment_point: per_commitment_point.clone(), - revocation_key: derive_public_revocation_key(&secp_ctx, &per_commitment_point, &b_revocation_base)?, - a_htlc_key: derive_public_key(&secp_ctx, &per_commitment_point, &a_htlc_base)?, - b_htlc_key: derive_public_key(&secp_ctx, &per_commitment_point, &b_htlc_base)?, - a_delayed_payment_key: derive_public_key(&secp_ctx, &per_commitment_point, &a_delayed_payment_base)?, + revocation_key: derive_public_revocation_key(&secp_ctx, &per_commitment_point, &countersignatory_revocation_base)?, + broadcaster_htlc_key: derive_public_key(&secp_ctx, &per_commitment_point, &broadcaster_htlc_base)?, + countersignatory_htlc_key: derive_public_key(&secp_ctx, &per_commitment_point, &countersignatory_htlc_base)?, + broadcaster_delayed_payment_key: derive_public_key(&secp_ctx, &per_commitment_point, &broadcaster_delayed_payment_base)?, }) } } /// A script either spendable by the revocation -/// key or the delayed_payment_key and satisfying the relative-locktime OP_CSV constrain. -/// Encumbering a `to_local` output on a commitment transaction or 2nd-stage HTLC transactions. -pub fn get_revokeable_redeemscript(revocation_key: &PublicKey, to_self_delay: u16, delayed_payment_key: &PublicKey) -> Script { +/// key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain. +/// Encumbering a `to_holder` output on a commitment transaction or 2nd-stage HTLC transactions. +pub fn get_revokeable_redeemscript(revocation_key: &PublicKey, contest_delay: u16, broadcaster_delayed_payment_key: &PublicKey) -> Script { Builder::new().push_opcode(opcodes::all::OP_IF) .push_slice(&revocation_key.serialize()) .push_opcode(opcodes::all::OP_ELSE) - .push_int(to_self_delay as i64) + .push_int(contest_delay as i64) .push_opcode(opcodes::all::OP_CSV) .push_opcode(opcodes::all::OP_DROP) - .push_slice(&delayed_payment_key.serialize()) + .push_slice(&broadcaster_delayed_payment_key.serialize()) .push_opcode(opcodes::all::OP_ENDIF) .push_opcode(opcodes::all::OP_CHECKSIG) .into_script() @@ -391,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. @@ -415,7 +430,7 @@ impl_writeable!(HTLCOutputInCommitment, 1 + 8 + 4 + 32 + 5, { }); #[inline] -pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommitment, a_htlc_key: &PublicKey, b_htlc_key: &PublicKey, revocation_key: &PublicKey) -> Script { +pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommitment, broadcaster_htlc_key: &PublicKey, countersignatory_htlc_key: &PublicKey, revocation_key: &PublicKey) -> Script { let payment_hash160 = Ripemd160::hash(&htlc.payment_hash.0[..]).into_inner(); if htlc.offered { Builder::new().push_opcode(opcodes::all::OP_DUP) @@ -425,7 +440,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit .push_opcode(opcodes::all::OP_IF) .push_opcode(opcodes::all::OP_CHECKSIG) .push_opcode(opcodes::all::OP_ELSE) - .push_slice(&b_htlc_key.serialize()[..]) + .push_slice(&countersignatory_htlc_key.serialize()[..]) .push_opcode(opcodes::all::OP_SWAP) .push_opcode(opcodes::all::OP_SIZE) .push_int(32) @@ -434,7 +449,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit .push_opcode(opcodes::all::OP_DROP) .push_int(2) .push_opcode(opcodes::all::OP_SWAP) - .push_slice(&a_htlc_key.serialize()[..]) + .push_slice(&broadcaster_htlc_key.serialize()[..]) .push_int(2) .push_opcode(opcodes::all::OP_CHECKMULTISIG) .push_opcode(opcodes::all::OP_ELSE) @@ -453,7 +468,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit .push_opcode(opcodes::all::OP_IF) .push_opcode(opcodes::all::OP_CHECKSIG) .push_opcode(opcodes::all::OP_ELSE) - .push_slice(&b_htlc_key.serialize()[..]) + .push_slice(&countersignatory_htlc_key.serialize()[..]) .push_opcode(opcodes::all::OP_SWAP) .push_opcode(opcodes::all::OP_SIZE) .push_int(32) @@ -464,7 +479,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit .push_opcode(opcodes::all::OP_EQUALVERIFY) .push_int(2) .push_opcode(opcodes::all::OP_SWAP) - .push_slice(&a_htlc_key.serialize()[..]) + .push_slice(&broadcaster_htlc_key.serialize()[..]) .push_int(2) .push_opcode(opcodes::all::OP_CHECKMULTISIG) .push_opcode(opcodes::all::OP_ELSE) @@ -479,31 +494,31 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit } } -/// note here that 'a_revocation_key' is generated using b_revocation_basepoint and a's -/// commitment secret. 'htlc' does *not* need to have its previous_output_index filled. +/// Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc +/// does not need to have its previous_output_index filled. #[inline] pub fn get_htlc_redeemscript(htlc: &HTLCOutputInCommitment, keys: &TxCreationKeys) -> Script { - get_htlc_redeemscript_with_explicit_keys(htlc, &keys.a_htlc_key, &keys.b_htlc_key, &keys.revocation_key) + get_htlc_redeemscript_with_explicit_keys(htlc, &keys.broadcaster_htlc_key, &keys.countersignatory_htlc_key, &keys.revocation_key) } /// Gets the redeemscript for a funding output from the two funding public keys. /// Note that the order of funding public keys does not matter. -pub fn make_funding_redeemscript(a: &PublicKey, b: &PublicKey) -> Script { - let our_funding_key = a.serialize(); - let their_funding_key = b.serialize(); +pub fn make_funding_redeemscript(broadcaster: &PublicKey, countersignatory: &PublicKey) -> Script { + let broadcaster_funding_key = broadcaster.serialize(); + let countersignatory_funding_key = countersignatory.serialize(); let builder = Builder::new().push_opcode(opcodes::all::OP_PUSHNUM_2); - if our_funding_key[..] < their_funding_key[..] { - builder.push_slice(&our_funding_key) - .push_slice(&their_funding_key) + if broadcaster_funding_key[..] < countersignatory_funding_key[..] { + builder.push_slice(&broadcaster_funding_key) + .push_slice(&countersignatory_funding_key) } else { - builder.push_slice(&their_funding_key) - .push_slice(&our_funding_key) + builder.push_slice(&countersignatory_funding_key) + .push_slice(&broadcaster_funding_key) }.push_opcode(opcodes::all::OP_PUSHNUM_2).push_opcode(opcodes::all::OP_CHECKMULTISIG).into_script() } /// panics if htlc.transaction_output_index.is_none()! -pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u32, to_self_delay: u16, htlc: &HTLCOutputInCommitment, a_delayed_payment_key: &PublicKey, revocation_key: &PublicKey) -> Transaction { +pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u32, contest_delay: u16, htlc: &HTLCOutputInCommitment, broadcaster_delayed_payment_key: &PublicKey, revocation_key: &PublicKey) -> Transaction { let mut txins: Vec = Vec::new(); txins.push(TxIn { previous_output: OutPoint { @@ -523,7 +538,7 @@ pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u32, to_self_del let mut txouts: Vec = Vec::new(); txouts.push(TxOut { - script_pubkey: get_revokeable_redeemscript(revocation_key, to_self_delay, a_delayed_payment_key).to_v0_p2wsh(), + script_pubkey: get_revokeable_redeemscript(revocation_key, contest_delay, broadcaster_delayed_payment_key).to_v0_p2wsh(), value: htlc.amount_msat / 1000 - total_fee //TODO: BOLT 3 does not specify if we should add amount_msat before dividing or if we should divide by 1000 before subtracting (as we do here) }); @@ -536,35 +551,35 @@ pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u32, to_self_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)>, } -impl LocalCommitmentTransaction { +impl HolderCommitmentTransaction { #[cfg(test)] pub fn dummy() -> Self { let dummy_input = TxIn { @@ -585,26 +600,26 @@ 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(), - a_htlc_key: dummy_key.clone(), - b_htlc_key: dummy_key.clone(), - a_delayed_payment_key: dummy_key.clone(), + broadcaster_htlc_key: dummy_key.clone(), + countersignatory_htlc_key: dummy_key.clone(), + broadcaster_delayed_payment_key: dummy_key.clone(), }, feerate_per_kw: 0, per_htlc: Vec::new() } } - /// 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)>) -> 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)>) -> 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?"); } @@ -622,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, } @@ -633,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(&self, funding_key: &SecretKey, funding_redeemscript: &Script, channel_value_satoshis: u64, secp_ctx: &Secp256k1) -> Signature { + pub fn get_holder_sig(&self, funding_key: &SecretKey, funding_redeemscript: &Script, channel_value_satoshis: u64, secp_ctx: &Secp256k1) -> 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); @@ -681,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(&self, htlc_base_key: &SecretKey, local_csv: u16, secp_ctx: &Secp256k1) -> Result>, ()> { + pub fn get_htlc_sigs(&self, htlc_base_key: &SecretKey, counterparty_selected_contest_delay: u16, secp_ctx: &Secp256k1) -> Result>, ()> { 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.a_delayed_payment_key, &self.local_keys.revocation_key); + let htlc_tx = build_htlc_transaction(&txid, self.feerate_per_kw, counterparty_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.a_htlc_key, &self.local_keys.b_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); } @@ -701,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, 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, counterparty_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()); @@ -711,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.a_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, counterparty_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.a_htlc_key, &self.local_keys.b_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()); @@ -737,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(&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() { @@ -763,7 +778,7 @@ impl Writeable for LocalCommitmentTransaction { Ok(()) } } -impl Readable for LocalCommitmentTransaction { +impl Readable for HolderCommitmentTransaction { fn read(reader: &mut R) -> Result { let unsigned_tx = match Transaction::consensus_decode(reader.by_ref()) { Ok(tx) => tx, @@ -772,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)>())); @@ -790,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, }) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 9a4fd1adaeb..2699e461806 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -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; @@ -52,8 +52,8 @@ pub struct ChannelValueStat { pub pending_outbound_htlcs_amount_msat: u64, pub pending_inbound_htlcs_amount_msat: u64, pub holding_cell_outbound_amount_msat: u64, - pub their_max_htlc_value_in_flight_msat: u64, // outgoing - pub their_dust_limit_msat: u64, + pub counterparty_max_htlc_value_in_flight_msat: u64, // outgoing + pub counterparty_dust_limit_msat: u64, } enum InboundHTLCRemovalReason { @@ -262,6 +262,9 @@ enum UpdateStatus { // has been completed, and then turn into a Channel to get compiler-time enforcement of things like // calling channel_id() before we're set up or things like get_outbound_funding_signed on an // inbound channel. +// +// Holder designates channel data owned for the benefice of the user client. +// Counterparty designates channel data owned by the another channel participant entity. pub(super) struct Channel { config: ChannelConfig, @@ -276,9 +279,9 @@ pub(super) struct Channel { latest_monitor_update_id: u64, #[cfg(not(test))] - local_keys: ChanSigner, + holder_keys: ChanSigner, #[cfg(test)] - pub(super) local_keys: ChanSigner, + pub(super) holder_keys: ChanSigner, shutdown_pubkey: PublicKey, destination_script: Script, @@ -286,8 +289,8 @@ pub(super) struct Channel { // generation start at 0 and count up...this simplifies some parts of implementation at the // cost of others, but should really just be changed. - cur_local_commitment_transaction_number: u64, - cur_remote_commitment_transaction_number: u64, + cur_holder_commitment_transaction_number: u64, + cur_counterparty_commitment_transaction_number: u64, value_to_self_msat: u64, // Excluding all pending_htlcs, excluding fees pending_inbound_htlcs: Vec, pending_outbound_htlcs: Vec, @@ -325,19 +328,19 @@ pub(super) struct Channel { // is received. holding_cell_update_fee is updated when there are additional // update_fee() during ChannelState::AwaitingRemoteRevoke. holding_cell_update_fee: Option, - next_local_htlc_id: u64, - next_remote_htlc_id: u64, + next_holder_htlc_id: u64, + next_counterparty_htlc_id: u64, update_time_counter: u32, feerate_per_kw: u32, #[cfg(debug_assertions)] /// Max to_local and to_remote outputs in a locally-generated commitment transaction - max_commitment_tx_output_local: ::std::sync::Mutex<(u64, u64)>, + holder_max_commitment_tx_output: ::std::sync::Mutex<(u64, u64)>, #[cfg(debug_assertions)] /// Max to_local and to_remote outputs in a remote-generated commitment transaction - max_commitment_tx_output_remote: ::std::sync::Mutex<(u64, u64)>, + counterparty_max_commitment_tx_output: ::std::sync::Mutex<(u64, u64)>, - last_sent_closing_fee: Option<(u32, u64, Signature)>, // (feerate, fee, our_sig) + last_sent_closing_fee: Option<(u32, u64, Signature)>, // (feerate, fee, holder_sig) funding_txo: Option, @@ -352,38 +355,38 @@ pub(super) struct Channel { pub(super) last_block_connected: BlockHash, funding_tx_confirmations: u64, - their_dust_limit_satoshis: u64, + counterparty_dust_limit_satoshis: u64, #[cfg(test)] - pub(super) our_dust_limit_satoshis: u64, + pub(super) holder_dust_limit_satoshis: u64, #[cfg(not(test))] - our_dust_limit_satoshis: u64, + holder_dust_limit_satoshis: u64, #[cfg(test)] - pub(super) their_max_htlc_value_in_flight_msat: u64, + pub(super) counterparty_max_htlc_value_in_flight_msat: u64, #[cfg(not(test))] - their_max_htlc_value_in_flight_msat: u64, - //get_our_max_htlc_value_in_flight_msat(): u64, + counterparty_max_htlc_value_in_flight_msat: u64, + //get_holder_max_htlc_value_in_flight_msat(): u64, /// minimum channel reserve for self to maintain - set by them. - local_channel_reserve_satoshis: u64, - // get_remote_channel_reserve_satoshis(channel_value_sats: u64): u64 - their_htlc_minimum_msat: u64, - our_htlc_minimum_msat: u64, - their_to_self_delay: u16, - our_to_self_delay: u16, + counterparty_selected_channel_reserve_satoshis: u64, + // get_holder_selected_channel_reserve_satoshis(channel_value_sats: u64): u64 + counterparty_htlc_minimum_msat: u64, + holder_htlc_minimum_msat: u64, + counterparty_selected_contest_delay: u16, + holder_selected_contest_delay: u16, #[cfg(test)] - pub their_max_accepted_htlcs: u16, + pub counterparty_max_accepted_htlcs: u16, #[cfg(not(test))] - their_max_accepted_htlcs: u16, - //implied by OUR_MAX_HTLCS: our_max_accepted_htlcs: u16, + counterparty_max_accepted_htlcs: u16, + //implied by OUR_MAX_HTLCS: max_accepted_htlcs: u16, minimum_depth: u32, - their_pubkeys: Option, + counterparty_pubkeys: Option, - their_cur_commitment_point: Option, + counterparty_cur_commitment_point: Option, - their_prev_commitment_point: Option, - their_node_id: PublicKey, + counterparty_prev_commitment_point: Option, + counterparty_node_id: PublicKey, - their_shutdown_scriptpubkey: Option