Move ln/channelmonitor.rs to chain/chainmonitor.rs
[rust-lightning] / lightning / src / ln / chan_utils.rs
index 7b35fb3d98c8f5d1e1195a3af63420c2317acb5d..a9be581b8f18935eaccbeb42374eea2fee70eb79 100644 (file)
@@ -81,7 +81,7 @@ pub fn build_commitment_secret(commitment_seed: &[u8; 32], idx: u64) -> [u8; 32]
 /// Allows us to keep track of all of the revocation secrets of counterarties in just 50*32 bytes
 /// or so.
 #[derive(Clone)]
-pub(super) struct CounterpartyCommitmentSecrets {
+pub(crate) struct CounterpartyCommitmentSecrets {
        old_secrets: [([u8; 32], u64); 49],
 }
 
@@ -97,7 +97,7 @@ impl PartialEq for CounterpartyCommitmentSecrets {
 }
 
 impl CounterpartyCommitmentSecrets {
-       pub(super) fn new() -> Self {
+       pub(crate) fn new() -> Self {
                Self { old_secrets: [([0; 32], 1 << 48); 49], }
        }
 
@@ -111,7 +111,7 @@ impl CounterpartyCommitmentSecrets {
                48
        }
 
-       pub(super) fn get_min_seen_secret(&self) -> u64 {
+       pub(crate) fn get_min_seen_secret(&self) -> u64 {
                //TODO This can be optimized?
                let mut min = 1 << 48;
                for &(_, idx) in self.old_secrets.iter() {
@@ -135,7 +135,7 @@ impl CounterpartyCommitmentSecrets {
                res
        }
 
-       pub(super) fn provide_secret(&mut self, idx: u64, secret: [u8; 32]) -> Result<(), ()> {
+       pub(crate) fn provide_secret(&mut self, idx: u64, secret: [u8; 32]) -> Result<(), ()> {
                let pos = Self::place_secret(idx);
                for i in 0..pos {
                        let (old_secret, old_idx) = self.old_secrets[i as usize];
@@ -151,7 +151,7 @@ impl CounterpartyCommitmentSecrets {
        }
 
        /// Can only fail if idx is < get_min_seen_secret
-       pub(super) fn get_secret(&self, idx: u64) -> Option<[u8; 32]> {
+       pub(crate) fn get_secret(&self, idx: u64) -> Option<[u8; 32]> {
                for i in 0..self.old_secrets.len() {
                        if (idx & (!((1 << i) - 1))) == self.old_secrets[i].1 {
                                return Some(Self::derive_secret(self.old_secrets[i].0, i as u8, idx))
@@ -349,9 +349,9 @@ 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
-       /// counterparty-broadcasted commitment transactions. This key is static across every commitment
-       /// transaction.
+       /// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
+       /// spendable primary channel balance on the broadcaster's commitment transaction. 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
        /// public key which receives non-HTLC-encumbered funds which are only available for spending
@@ -386,7 +386,7 @@ impl TxCreationKeys {
 
 /// A script either spendable by the revocation
 /// 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.
+/// 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())
@@ -494,8 +494,8 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
        }
 }
 
-/// note here that 'revocation_key' is generated using countersignatory_revocation_basepoint and broadcaster'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.broadcaster_htlc_key, &keys.countersignatory_htlc_key, &keys.revocation_key)
@@ -696,14 +696,14 @@ impl HolderCommitmentTransaction {
        /// The returned Vec has one entry for each HTLC, and in the same order. For HTLCs which were
        /// considered dust and not included, a None entry exists, for all others a signature is
        /// included.
-       pub fn get_htlc_sigs<T: secp256k1::Signing + secp256k1::Verification>(&self, htlc_base_key: &SecretKey, holder_selected_contest_delay: u16, secp_ctx: &Secp256k1<T>) -> Result<Vec<Option<Signature>>, ()> {
+       pub fn get_htlc_sigs<T: secp256k1::Signing + secp256k1::Verification>(&self, htlc_base_key: &SecretKey, counterparty_selected_contest_delay: u16, secp_ctx: &Secp256k1<T>) -> Result<Vec<Option<Signature>>, ()> {
                let txid = self.txid();
                let mut ret = Vec::with_capacity(self.per_htlc.len());
                let 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, holder_selected_contest_delay, &this_htlc.0, &self.keys.broadcaster_delayed_payment_key, &self.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.keys.broadcaster_htlc_key, &self.keys.countersignatory_htlc_key, &self.keys.revocation_key);
 
@@ -717,7 +717,7 @@ impl HolderCommitmentTransaction {
        }
 
        /// Gets a signed HTLC transaction given a preimage (for !htlc.offered) and the holder HTLC transaction signature.
-       pub(crate) fn get_signed_htlc_tx(&self, htlc_index: usize, signature: &Signature, preimage: &Option<PaymentPreimage>, holder_selected_contest_delay: u16) -> Transaction {
+       pub(crate) fn get_signed_htlc_tx(&self, htlc_index: usize, signature: &Signature, preimage: &Option<PaymentPreimage>, 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());
@@ -726,7 +726,7 @@ impl HolderCommitmentTransaction {
                // 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, holder_selected_contest_delay, &this_htlc.0, &self.keys.broadcaster_delayed_payment_key, &self.keys.revocation_key);
+               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());