From: Antoine Riard Date: Wed, 26 Aug 2020 19:27:12 +0000 (-0400) Subject: Change variable nomenclature for to_self_delay X-Git-Tag: v0.0.12~28^2~5 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=c6a91f2ebd301455c7ebae04eb1f308935666439;p=rust-lightning Change variable nomenclature for to_self_delay To avoid reviewers confusion, rename counterparty_to_self_delay to counteparty_selected_contest_delay, i.e the justice delay announced by a channel counterparty restraining our transactions, and to_self_delay to locally_selected_contest_delay, i.e the justice delay announced by us restraining counterparty's transactions We deviate from wider nomenclature by prefixing local data with a locally_ extension due to the leak of this value in transactions/scripts builder, where the confusion may happen. Rename further AcceptChannelData to the new nomenclature. --- diff --git a/lightning-c-bindings/src/chain/keysinterface.rs b/lightning-c-bindings/src/chain/keysinterface.rs index 5443e4e76..1a871ce9d 100644 --- a/lightning-c-bindings/src/chain/keysinterface.rs +++ b/lightning-c-bindings/src/chain/keysinterface.rs @@ -670,8 +670,8 @@ pub extern "C" fn InMemoryChannelKeys_new(mut funding_key: crate::c_types::Secre /// 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 } } @@ -682,8 +682,8 @@ pub extern "C" fn InMemoryChannelKeys_remote_pubkeys(this_arg: &InMemoryChannelK /// Will panic if on_accept wasn't called. #[must_use] #[no_mangle] -pub extern "C" fn InMemoryChannelKeys_counterparty_to_self_delay(this_arg: &InMemoryChannelKeys) -> u16 { - let mut ret = unsafe { &*this_arg.inner }.counterparty_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 } @@ -693,8 +693,8 @@ pub extern "C" fn InMemoryChannelKeys_counterparty_to_self_delay(this_arg: &InMe /// 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_locally_selected_contest_delay(this_arg: &InMemoryChannelKeys) -> u16 { + let mut ret = unsafe { &*this_arg.inner }.locally_selected_contest_delay(); ret } diff --git a/lightning/src/chain/keysinterface.rs b/lightning/src/chain/keysinterface.rs index 9ae939543..f922a6925 100644 --- a/lightning/src/chain/keysinterface.rs +++ b/lightning/src/chain/keysinterface.rs @@ -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 counterparty/local_to_self_delay. + /// Set the counterparty channel basepoints and counterparty_selected/locally_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 locally_selected_contest_delay late here for API convenience. /// /// Will be called before any signatures are applied. - fn on_accept(&mut self, channel_points: &ChannelPublicKeys, counterparty_to_self_delay: u16, local_to_self_delay: u16); + fn on_accept(&mut self, channel_points: &ChannelPublicKeys, counterparty_selected_contest_delay: u16, locally_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 locally-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. - counterparty_to_self_delay: u16, - /// The to_self_delay value specified by us and applied on transactions broadcastable + 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, + locally_selected_contest_delay: u16, } #[derive(Clone)] @@ -384,7 +384,7 @@ pub struct InMemoryChannelKeys { pub commitment_seed: [u8; 32], /// Local public keys and basepoints pub(crate) local_channel_pubkeys: ChannelPublicKeys, - /// Remote public keys and counterparty/local to_self_delay, populated on channel acceptance + /// Counterparty public keys and counterparty/locally selected_contest_delay, populated on channel acceptance accepted_channel_data: Option, /// The total value of this channel channel_value_satoshis: u64, @@ -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 locally-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. /// Will panic if on_accept wasn't called. - pub fn counterparty_to_self_delay(&self) -> u16 { self.accepted_channel_data.as_ref().unwrap().counterparty_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 locally_selected_contest_delay(&self) -> u16 { self.accepted_channel_data.as_ref().unwrap().locally_selected_contest_delay } } impl ChannelKeys for InMemoryChannelKeys { @@ -475,7 +475,7 @@ impl ChannelKeys for InMemoryChannelKeys { 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.delayed_payment_key, &keys.revocation_key); + let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, feerate_per_kw, accepted_data.locally_selected_contest_delay, htlc, &keys.delayed_payment_key, &keys.revocation_key); 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) { @@ -501,8 +501,8 @@ impl ChannelKeys for InMemoryChannelKeys { fn sign_local_commitment(&self, local_commitment_tx: &LocalCommitmentTransaction, 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)) } @@ -510,14 +510,14 @@ impl ChannelKeys for InMemoryChannelKeys { #[cfg(any(test,feature = "unsafe_revoked_tx_signing"))] fn unsafe_sign_local_commitment(&self, local_commitment_tx: &LocalCommitmentTransaction, 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)) } 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().counterparty_to_self_delay; + let local_csv = self.accepted_channel_data.as_ref().unwrap().counterparty_selected_contest_delay; local_commitment_tx.get_htlc_sigs(&self.htlc_base_key, local_csv, secp_ctx) } @@ -532,7 +532,7 @@ impl ChannelKeys for InMemoryChannelKeys { Err(_) => return Err(()) }; let witness_script = if let &Some(ref htlc) = htlc { - let counterparty_htlcpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().htlc_basepoint) { + 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(()) }; @@ -542,11 +542,11 @@ impl ChannelKeys for InMemoryChannelKeys { }; chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &counterparty_htlcpubkey, &local_htlcpubkey, &revocation_pubkey) } else { - let counterparty_delayedpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().delayed_payment_basepoint) { + 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(), &counterparty_delayedpubkey) + chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.locally_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)[..]); @@ -556,7 +556,7 @@ impl ChannelKeys for InMemoryChannelKeys { fn sign_remote_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(counterparty_htlcpubkey) = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().htlc_basepoint) { + 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(()) } @@ -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, counterparty_to_self_delay: u16, local_to_self_delay: u16) { + fn on_accept(&mut self, channel_pubkeys: &ChannelPublicKeys, counterparty_selected_contest_delay: u16, locally_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(), - counterparty_to_self_delay, - local_to_self_delay, + counterparty_channel_pubkeys: channel_pubkeys.clone(), + counterparty_selected_contest_delay, + locally_selected_contest_delay, }); } } impl_writeable!(AcceptedChannelData, 0, - { remote_channel_pubkeys, counterparty_to_self_delay, local_to_self_delay }); + { counterparty_channel_pubkeys, counterparty_selected_contest_delay, locally_selected_contest_delay }); impl Writeable for InMemoryChannelKeys { fn write(&self, writer: &mut W) -> Result<(), Error> { @@ -626,7 +626,7 @@ 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 = @@ -645,7 +645,7 @@ impl Readable for InMemoryChannelKeys { commitment_seed, channel_value_satoshis, local_channel_pubkeys, - accepted_channel_data: remote_channel_data, + 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 d57f987d0..ebd553e39 100644 --- a/lightning/src/ln/chan_utils.rs +++ b/lightning/src/ln/chan_utils.rs @@ -385,11 +385,11 @@ impl TxCreationKeys { /// 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 { +pub fn get_revokeable_redeemscript(revocation_key: &PublicKey, contest_delay: u16, 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()) @@ -516,7 +516,7 @@ pub fn make_funding_redeemscript(broadcaster: &PublicKey, countersignatory: &Pub } /// 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, 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, delayed_payment_key: &PublicKey, revocation_key: &PublicKey) -> Transaction { let mut txins: Vec = Vec::new(); txins.push(TxIn { previous_output: OutPoint { @@ -536,7 +536,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, delayed_payment_key).to_v0_p2wsh(), + script_pubkey: get_revokeable_redeemscript(revocation_key, contest_delay, 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) }); diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 5a55e3e79..394016a12 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -367,8 +367,8 @@ pub(super) struct Channel { // get_holder_selected_channel_reserve_satoshis(channel_value_sats: u64): u64 counterparty_htlc_minimum_msat: u64, holder_htlc_minimum_msat: u64, - counterparty_to_self_delay: u16, - to_self_delay: u16, + counterparty_selected_contest_delay: u16, + holder_selected_contest_delay: u16, #[cfg(test)] pub counterparty_max_accepted_htlcs: u16, #[cfg(not(test))] @@ -463,7 +463,7 @@ impl Channel { where K::Target: KeysInterface, F::Target: FeeEstimator, { - let to_self_delay = config.own_channel_config.our_to_self_delay; + let holder_selected_contest_delay = config.own_channel_config.our_to_self_delay; let chan_keys = keys_provider.get_channel_keys(false, channel_value_satoshis); if channel_value_satoshis >= MAX_FUNDING_SATOSHIS { @@ -473,8 +473,8 @@ impl Channel { if push_msat > channel_value_msat { return Err(APIError::APIMisuseError { err: format!("Push value ({}) was larger than channel_value ({})", push_msat, channel_value_msat) }); } - if to_self_delay < BREAKDOWN_TIMEOUT { - return Err(APIError::APIMisuseError {err: format!("Configured with an unreasonable our_to_self_delay ({}) putting user funds at risks", to_self_delay)}); + if holder_selected_contest_delay < BREAKDOWN_TIMEOUT { + return Err(APIError::APIMisuseError {err: format!("Configured with an unreasonable our_to_self_delay ({}) putting user funds at risks", holder_selected_contest_delay)}); } let background_feerate = fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::Background); if Channel::::get_holder_selected_channel_reserve_satoshis(channel_value_satoshis) < Channel::::derive_holder_dust_limit_satoshis(background_feerate) { @@ -540,8 +540,8 @@ impl Channel { counterparty_selected_channel_reserve_satoshis: 0, counterparty_htlc_minimum_msat: 0, holder_htlc_minimum_msat: if config.own_channel_config.our_htlc_minimum_msat == 0 { 1 } else { config.own_channel_config.our_htlc_minimum_msat }, - counterparty_to_self_delay: 0, - to_self_delay, + counterparty_selected_contest_delay: 0, + holder_selected_contest_delay, counterparty_max_accepted_htlcs: 0, minimum_depth: 0, // Filled in in accept_channel @@ -768,8 +768,8 @@ impl Channel { counterparty_selected_channel_reserve_satoshis: msg.channel_reserve_satoshis, counterparty_htlc_minimum_msat: msg.htlc_minimum_msat, holder_htlc_minimum_msat: if config.own_channel_config.our_htlc_minimum_msat == 0 { 1 } else { config.own_channel_config.our_htlc_minimum_msat }, - counterparty_to_self_delay: msg.to_self_delay, - to_self_delay: config.own_channel_config.our_to_self_delay, + counterparty_selected_contest_delay: msg.to_self_delay, + holder_selected_contest_delay: config.own_channel_config.our_to_self_delay, counterparty_max_accepted_htlcs: msg.max_accepted_htlcs, minimum_depth: config.own_channel_config.minimum_depth, @@ -989,7 +989,7 @@ impl Channel { log_trace!(logger, " ...including {} output with value {}", if local { "to_local" } else { "to_remote" }, value_to_a); txouts.push((TxOut { script_pubkey: chan_utils::get_revokeable_redeemscript(&keys.revocation_key, - if local { self.counterparty_to_self_delay } else { self.to_self_delay }, + if local { self.counterparty_selected_contest_delay } else { self.holder_selected_contest_delay }, &keys.delayed_payment_key).to_v0_p2wsh(), value: value_to_a as u64 }, None)); @@ -1153,7 +1153,7 @@ impl Channel { /// @local is used only to convert relevant internal structures which refer to remote vs local /// to decide value of outputs and direction of HTLCs. fn build_htlc_transaction(&self, prev_hash: &Txid, htlc: &HTLCOutputInCommitment, local: bool, keys: &TxCreationKeys, feerate_per_kw: u32) -> Transaction { - chan_utils::build_htlc_transaction(prev_hash, feerate_per_kw, if local { self.counterparty_to_self_delay } else { self.to_self_delay }, htlc, &keys.delayed_payment_key, &keys.revocation_key) + chan_utils::build_htlc_transaction(prev_hash, feerate_per_kw, if local { self.counterparty_selected_contest_delay } else { self.holder_selected_contest_delay }, htlc, &keys.delayed_payment_key, &keys.revocation_key) } /// Per HTLC, only one get_update_fail_htlc or get_update_fulfill_htlc call may be made. @@ -1448,7 +1448,7 @@ impl Channel { self.counterparty_max_htlc_value_in_flight_msat = cmp::min(msg.max_htlc_value_in_flight_msat, self.channel_value_satoshis * 1000); self.counterparty_selected_channel_reserve_satoshis = msg.channel_reserve_satoshis; self.counterparty_htlc_minimum_msat = msg.htlc_minimum_msat; - self.counterparty_to_self_delay = msg.to_self_delay; + self.counterparty_selected_contest_delay = msg.to_self_delay; self.counterparty_max_accepted_htlcs = msg.max_accepted_htlcs; self.minimum_depth = msg.minimum_depth; @@ -1460,7 +1460,7 @@ impl Channel { htlc_basepoint: msg.htlc_basepoint }; - self.holder_keys.on_accept(&counterparty_pubkeys, msg.to_self_delay, self.to_self_delay); + self.holder_keys.on_accept(&counterparty_pubkeys, msg.to_self_delay, self.holder_selected_contest_delay); self.counterparty_pubkeys = Some(counterparty_pubkeys); self.counterparty_cur_commitment_point = Some(msg.first_per_commitment_point); @@ -1533,10 +1533,10 @@ impl Channel { macro_rules! create_monitor { () => { { let mut channel_monitor = ChannelMonitor::new(self.holder_keys.clone(), - &self.shutdown_pubkey, self.to_self_delay, + &self.shutdown_pubkey, self.holder_selected_contest_delay, &self.destination_script, (funding_txo, funding_txo_script.clone()), &counterparty_pubkeys.htlc_basepoint, &counterparty_pubkeys.delayed_payment_basepoint, - self.counterparty_to_self_delay, funding_redeemscript.clone(), self.channel_value_satoshis, + self.counterparty_selected_contest_delay, funding_redeemscript.clone(), self.channel_value_satoshis, self.get_commitment_transaction_number_obscure_factor(), initial_commitment_tx.clone()); @@ -1578,8 +1578,8 @@ impl Channel { let counterparty_keys = self.build_remote_transaction_keys()?; let counterparty_initial_commitment_tx = self.build_commitment_transaction(self.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, self.feerate_per_kw, logger).0; - let keys = self.build_holder_transaction_keys(self.cur_holder_commitment_transaction_number)?; - let initial_commitment_tx = self.build_commitment_transaction(self.cur_holder_commitment_transaction_number, &keys, true, false, self.feerate_per_kw, logger).0; + let holder_keys = self.build_holder_transaction_keys(self.cur_holder_commitment_transaction_number)?; + let initial_commitment_tx = self.build_commitment_transaction(self.cur_holder_commitment_transaction_number, &holder_keys, true, false, self.feerate_per_kw, logger).0; let sighash = hash_to_message!(&bip143::SigHashCache::new(&initial_commitment_tx).signature_hash(0, &funding_script, self.channel_value_satoshis, SigHashType::All)[..]); let counterparty_funding_pubkey = &self.counterparty_pubkeys.as_ref().unwrap().funding_pubkey; @@ -1595,12 +1595,12 @@ impl Channel { let funding_txo_script = funding_redeemscript.to_v0_p2wsh(); macro_rules! create_monitor { () => { { - let commitment_tx = LocalCommitmentTransaction::new_missing_local_sig(initial_commitment_tx.clone(), msg.signature.clone(), &self.holder_keys.pubkeys().funding_pubkey, counterparty_funding_pubkey, keys.clone(), self.feerate_per_kw, Vec::new()); + let commitment_tx = LocalCommitmentTransaction::new_missing_local_sig(initial_commitment_tx.clone(), msg.signature.clone(), &self.holder_keys.pubkeys().funding_pubkey, counterparty_funding_pubkey, holder_keys.clone(), self.feerate_per_kw, Vec::new()); let mut channel_monitor = ChannelMonitor::new(self.holder_keys.clone(), - &self.shutdown_pubkey, self.to_self_delay, + &self.shutdown_pubkey, self.holder_selected_contest_delay, &self.destination_script, (funding_txo.clone(), funding_txo_script.clone()), &counterparty_pubkeys.htlc_basepoint, &counterparty_pubkeys.delayed_payment_basepoint, - self.counterparty_to_self_delay, funding_redeemscript.clone(), self.channel_value_satoshis, + self.counterparty_selected_contest_delay, funding_redeemscript.clone(), self.channel_value_satoshis, self.get_commitment_transaction_number_obscure_factor(), commitment_tx); @@ -3466,7 +3466,7 @@ impl Channel { channel_reserve_satoshis: Channel::::get_holder_selected_channel_reserve_satoshis(self.channel_value_satoshis), htlc_minimum_msat: self.holder_htlc_minimum_msat, feerate_per_kw: self.feerate_per_kw as u32, - to_self_delay: self.to_self_delay, + to_self_delay: self.holder_selected_contest_delay, max_accepted_htlcs: OUR_MAX_HTLCS, funding_pubkey: keys.funding_pubkey, revocation_basepoint: keys.revocation_basepoint, @@ -3500,7 +3500,7 @@ impl Channel { channel_reserve_satoshis: Channel::::get_holder_selected_channel_reserve_satoshis(self.channel_value_satoshis), htlc_minimum_msat: self.holder_htlc_minimum_msat, minimum_depth: self.minimum_depth, - to_self_delay: self.to_self_delay, + to_self_delay: self.holder_selected_contest_delay, max_accepted_htlcs: OUR_MAX_HTLCS, funding_pubkey: keys.funding_pubkey, revocation_basepoint: keys.revocation_basepoint, @@ -3883,7 +3883,7 @@ impl Channel { for (ref htlc_sig, ref htlc) in htlc_signatures.iter().zip(htlcs) { log_trace!(logger, "Signed remote HTLC tx {} with redeemscript {} with pubkey {} -> {}", - encode::serialize_hex(&chan_utils::build_htlc_transaction(&counterparty_commitment_tx.0.txid(), feerate_per_kw, self.to_self_delay, htlc, &counterparty_keys.delayed_payment_key, &counterparty_keys.revocation_key)), + encode::serialize_hex(&chan_utils::build_htlc_transaction(&counterparty_commitment_tx.0.txid(), feerate_per_kw, self.holder_selected_contest_delay, htlc, &counterparty_keys.delayed_payment_key, &counterparty_keys.revocation_key)), encode::serialize_hex(&chan_utils::get_htlc_redeemscript(&htlc, counterparty_keys)), log_bytes!(counterparty_keys.broadcaster_htlc_key.serialize()), log_bytes!(htlc_sig.serialize_compact()[..])); @@ -4201,8 +4201,8 @@ impl Writeable for Channel { self.counterparty_selected_channel_reserve_satoshis.write(writer)?; self.counterparty_htlc_minimum_msat.write(writer)?; self.holder_htlc_minimum_msat.write(writer)?; - self.counterparty_to_self_delay.write(writer)?; - self.to_self_delay.write(writer)?; + self.counterparty_selected_contest_delay.write(writer)?; + self.holder_selected_contest_delay.write(writer)?; self.counterparty_max_accepted_htlcs.write(writer)?; self.minimum_depth.write(writer)?; @@ -4355,8 +4355,8 @@ impl Readable for Channel { let counterparty_selected_channel_reserve_satoshis = Readable::read(reader)?; let counterparty_htlc_minimum_msat = Readable::read(reader)?; let holder_htlc_minimum_msat = Readable::read(reader)?; - let counterparty_to_self_delay = Readable::read(reader)?; - let to_self_delay = Readable::read(reader)?; + let counterparty_selected_contest_delay = Readable::read(reader)?; + let holder_selected_contest_delay = Readable::read(reader)?; let counterparty_max_accepted_htlcs = Readable::read(reader)?; let minimum_depth = Readable::read(reader)?; @@ -4427,8 +4427,8 @@ impl Readable for Channel { counterparty_selected_channel_reserve_satoshis, counterparty_htlc_minimum_msat, holder_htlc_minimum_msat, - counterparty_to_self_delay, - to_self_delay, + counterparty_selected_contest_delay, + holder_selected_contest_delay, counterparty_max_accepted_htlcs, minimum_depth, @@ -4639,7 +4639,7 @@ mod tests { let mut config = UserConfig::default(); config.channel_options.announced_channel = false; let mut chan = Channel::::new_outbound(&&feeest, &&keys_provider, counterparty_node_id, 10_000_000, 100000, 42, &config).unwrap(); // Nothing uses their network key in this test - chan.counterparty_to_self_delay = 144; + chan.counterparty_selected_contest_delay = 144; chan.holder_dust_limit_satoshis = 546; let funding_info = OutPoint{ txid: Txid::from_hex("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(), index: 0 }; @@ -4652,7 +4652,7 @@ mod tests { delayed_payment_basepoint: public_from_secret_hex(&secp_ctx, "1552dfba4f6cf29a62a0af13c8d6981d36d0ef8d61ba10fb0fe90da7634d7e13"), htlc_basepoint: public_from_secret_hex(&secp_ctx, "4444444444444444444444444444444444444444444444444444444444444444") }; - chan_keys.on_accept(&counterparty_pubkeys, chan.counterparty_to_self_delay, chan.to_self_delay); + chan_keys.on_accept(&counterparty_pubkeys, chan.counterparty_selected_contest_delay, chan.holder_selected_contest_delay); assert_eq!(counterparty_pubkeys.payment_point.serialize()[..], hex::decode("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991").unwrap()[..]); @@ -4738,7 +4738,7 @@ mod tests { let signature = Signature::from_der(&hex::decode($htlc_sig_hex).unwrap()[..]).unwrap(); assert_eq!(Some(signature), *(htlc_sig.1).1); - assert_eq!(serialize(&localtx.get_signed_htlc_tx((htlc_sig.1).0, &(htlc_sig.1).1.unwrap(), &preimage, chan.counterparty_to_self_delay))[..], + assert_eq!(serialize(&localtx.get_signed_htlc_tx((htlc_sig.1).0, &(htlc_sig.1).1.unwrap(), &preimage, chan.counterparty_selected_contest_delay))[..], hex::decode($htlc_tx_hex).unwrap()[..]); })* loop { diff --git a/lightning/src/util/enforcing_trait_impls.rs b/lightning/src/util/enforcing_trait_impls.rs index b001fb1a6..e31e774fe 100644 --- a/lightning/src/util/enforcing_trait_impls.rs +++ b/lightning/src/util/enforcing_trait_impls.rs @@ -44,7 +44,7 @@ impl EnforcingChannelKeys { impl EnforcingChannelKeys { fn check_keys(&self, secp_ctx: &Secp256k1, keys: &TxCreationKeys) { - let remote_points = self.inner.remote_pubkeys(); + let remote_points = self.inner.counterparty_pubkeys(); let keys_expected = TxCreationKeys::derive_new(secp_ctx, &keys.per_commitment_point, @@ -100,7 +100,7 @@ impl ChannelKeys for EnforcingChannelKeys { fn sign_local_commitment_htlc_transactions(&self, local_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1) -> Result>, ()> { let commitment_txid = local_commitment_tx.txid(); - let local_csv = self.inner.counterparty_to_self_delay(); + let local_csv = self.inner.counterparty_selected_contest_delay(); for this_htlc in local_commitment_tx.per_htlc.iter() { if this_htlc.0.transaction_output_index.is_some() { @@ -132,8 +132,8 @@ impl ChannelKeys for EnforcingChannelKeys { self.inner.sign_channel_announcement(msg, secp_ctx) } - fn on_accept(&mut self, channel_pubkeys: &ChannelPublicKeys, remote_to_self_delay: u16, local_to_self_delay: u16) { - self.inner.on_accept(channel_pubkeys, remote_to_self_delay, local_to_self_delay) + fn on_accept(&mut self, channel_pubkeys: &ChannelPublicKeys, remote_locally_selected_delay: u16, locally_selected_delay: u16) { + self.inner.on_accept(channel_pubkeys, remote_locally_selected_delay, locally_selected_delay) } }