WIP
[rust-lightning] / lightning / src / ln / chan_utils.rs
index a57fafcd99216a03b6de02f3a56c0b56bb2a873d..2d0af708f2c5e801759d391bec6f3d15e68afa56 100644 (file)
@@ -26,8 +26,8 @@ use std::{cmp, mem};
 
 const MAX_ALLOC_SIZE: usize = 64*1024;
 
-pub(super) const HTLC_SUCCESS_TX_WEIGHT: u64 = 703;
-pub(super) const HTLC_TIMEOUT_TX_WEIGHT: u64 = 663;
+pub(super) const HTLC_SUCCESS_TX_WEIGHT: u64 = 703; // XXX
+pub(super) const HTLC_TIMEOUT_TX_WEIGHT: u64 = 663; // XXX
 
 #[derive(PartialEq)]
 pub(crate) enum HTLCType {
@@ -38,9 +38,9 @@ pub(crate) enum HTLCType {
 impl HTLCType {
        /// Check if a given tx witnessScript len matchs one of a pre-signed HTLC
        pub(crate) fn scriptlen_to_htlctype(witness_script_len: usize) ->  Option<HTLCType> {
-               if witness_script_len == 133 {
+               if witness_script_len == 136 {
                        Some(HTLCType::OfferedHTLC)
-               } else if witness_script_len >= 136 && witness_script_len <= 139 {
+               } else if witness_script_len >= 139 && witness_script_len <= 142 {
                        Some(HTLCType::AcceptedHTLC)
                } else {
                        None
@@ -277,9 +277,10 @@ pub struct ChannelPublicKeys {
        /// a commitment transaction so that their counterparty can claim all available funds if they
        /// broadcast an old state.
        pub revocation_basepoint: PublicKey,
-       /// The base point which is used (with derive_public_key) to derive a per-commitment payment
-       /// public key which receives immediately-spendable non-HTLC-encumbered funds.
-       pub payment_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
+       /// 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
        /// after some delay (or can be claimed via the revocation path).
@@ -292,7 +293,7 @@ pub struct ChannelPublicKeys {
 impl_writeable!(ChannelPublicKeys, 33*5, {
        funding_pubkey,
        revocation_basepoint,
-       payment_basepoint,
+       payment_point,
        delayed_payment_basepoint,
        htlc_basepoint
 });
@@ -384,6 +385,9 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
                              .push_opcode(opcodes::all::OP_CHECKSIG)
                              .push_opcode(opcodes::all::OP_ENDIF)
                              .push_opcode(opcodes::all::OP_ENDIF)
+                             .push_int(1)
+                             .push_opcode(opcodes::all::OP_CSV)
+                             .push_opcode(opcodes::all::OP_DROP)
                              .into_script()
        } else {
                Builder::new().push_opcode(opcodes::all::OP_DUP)
@@ -415,6 +419,9 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
                              .push_opcode(opcodes::all::OP_CHECKSIG)
                              .push_opcode(opcodes::all::OP_ENDIF)
                              .push_opcode(opcodes::all::OP_ENDIF)
+                             .push_int(1)
+                             .push_opcode(opcodes::all::OP_CSV)
+                             .push_opcode(opcodes::all::OP_DROP)
                              .into_script()
        }
 }
@@ -451,7 +458,7 @@ pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u64, to_self_del
                        vout: htlc.transaction_output_index.expect("Can't build an HTLC transaction for a dust output"),
                },
                script_sig: Script::new(),
-               sequence: 0,
+               sequence: 1,
                witness: Vec::new(),
        });