X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fchan_utils.rs;h=2d0af708f2c5e801759d391bec6f3d15e68afa56;hb=HEAD;hp=9be3f38a78e6c027c7328a6d5e6c35e69013c8bd;hpb=ea4ccf63c7b8a8af5107c536bb6ab01ee04cbdc4;p=rust-lightning diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs index 9be3f38a..2d0af708 100644 --- a/lightning/src/ln/chan_utils.rs +++ b/lightning/src/ln/chan_utils.rs @@ -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 { - 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 @@ -262,11 +262,9 @@ pub struct TxCreationKeys { pub(crate) b_htlc_key: PublicKey, /// A's Payment Key (which isn't allowed to be spent from for some delay) pub(crate) a_delayed_payment_key: PublicKey, - /// B's Payment Key - pub(crate) b_payment_key: PublicKey, } impl_writeable!(TxCreationKeys, 33*6, - { per_commitment_point, revocation_key, a_htlc_key, b_htlc_key, a_delayed_payment_key, b_payment_key }); + { per_commitment_point, revocation_key, a_htlc_key, b_htlc_key, a_delayed_payment_key }); /// One counterparty's public keys which do not change over the life of a channel. #[derive(Clone, PartialEq)] @@ -279,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). @@ -294,21 +293,20 @@ pub struct ChannelPublicKeys { impl_writeable!(ChannelPublicKeys, 33*5, { funding_pubkey, revocation_basepoint, - payment_basepoint, + payment_point, delayed_payment_basepoint, htlc_basepoint }); impl TxCreationKeys { - pub(crate) fn new(secp_ctx: &Secp256k1, per_commitment_point: &PublicKey, a_delayed_payment_base: &PublicKey, a_htlc_base: &PublicKey, b_revocation_base: &PublicKey, b_payment_base: &PublicKey, b_htlc_base: &PublicKey) -> Result { + pub(crate) fn 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 { 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)?, - b_payment_key: derive_public_key(&secp_ctx, &per_commitment_point, &b_payment_base)?, }) } } @@ -387,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) @@ -418,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() } } @@ -454,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(), }); @@ -537,7 +541,6 @@ impl LocalCommitmentTransaction { a_htlc_key: dummy_key.clone(), b_htlc_key: dummy_key.clone(), a_delayed_payment_key: dummy_key.clone(), - b_payment_key: dummy_key.clone(), }, feerate_per_kw: 0, per_htlc: Vec::new()