Skip to content

Commit 2df5f4d

Browse files
committed
Added anchor support to build_htlc_transaction
1 parent d9e2bf8 commit 2df5f4d

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

Diff for: lightning/src/chain/keysinterface.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ impl BaseSign for InMemorySigner {
597597

598598
let mut htlc_sigs = Vec::with_capacity(commitment_tx.htlcs().len());
599599
for htlc in commitment_tx.htlcs() {
600-
let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, commitment_tx.feerate_per_kw(), self.holder_selected_contest_delay(), htlc, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
600+
let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, commitment_tx.feerate_per_kw(), self.holder_selected_contest_delay(), htlc, self.opt_anchors(), &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
601601
let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, self.opt_anchors(), &keys);
602602
let htlc_sighash = hash_to_message!(&bip143::SigHashCache::new(&htlc_tx).signature_hash(0, &htlc_redeemscript, htlc.amount_msat / 1000, SigHashType::All)[..]);
603603
let holder_htlc_key = chan_utils::derive_private_key(&secp_ctx, &keys.per_commitment_point, &self.htlc_base_key).map_err(|_| ())?;

Diff for: lightning/src/ln/chan_utils.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -588,15 +588,15 @@ pub fn make_funding_redeemscript(broadcaster: &PublicKey, countersignatory: &Pub
588588
///
589589
/// Panics if htlc.transaction_output_index.is_none() (as such HTLCs do not appear in the
590590
/// commitment transaction).
591-
pub fn build_htlc_transaction(commitment_txid: &Txid, feerate_per_kw: u32, contest_delay: u16, htlc: &HTLCOutputInCommitment, broadcaster_delayed_payment_key: &PublicKey, revocation_key: &PublicKey) -> Transaction {
591+
pub fn build_htlc_transaction(commitment_txid: &Txid, feerate_per_kw: u32, contest_delay: u16, htlc: &HTLCOutputInCommitment, opt_anchors: bool, broadcaster_delayed_payment_key: &PublicKey, revocation_key: &PublicKey) -> Transaction {
592592
let mut txins: Vec<TxIn> = Vec::new();
593593
txins.push(TxIn {
594594
previous_output: OutPoint {
595595
txid: commitment_txid.clone(),
596596
vout: htlc.transaction_output_index.expect("Can't build an HTLC transaction for a dust output"),
597597
},
598598
script_sig: Script::new(),
599-
sequence: 0,
599+
sequence: if opt_anchors { 1 } else { 0 },
600600
witness: Vec::new(),
601601
});
602602

@@ -1389,7 +1389,7 @@ impl<'a> TrustedCommitmentTransaction<'a> {
13891389

13901390
for this_htlc in inner.htlcs.iter() {
13911391
assert!(this_htlc.transaction_output_index.is_some());
1392-
let htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
1392+
let htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, self.opt_anchors(), &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
13931393

13941394
let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(&this_htlc, self.opt_anchors(), &keys.broadcaster_htlc_key, &keys.countersignatory_htlc_key, &keys.revocation_key);
13951395

@@ -1411,7 +1411,7 @@ impl<'a> TrustedCommitmentTransaction<'a> {
14111411
// Further, we should never be provided the preimage for an HTLC-Timeout transaction.
14121412
if this_htlc.offered && preimage.is_some() { unreachable!(); }
14131413

1414-
let mut htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
1414+
let mut htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, self.opt_anchors(), &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
14151415

14161416
let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(&this_htlc, self.opt_anchors(), &keys.broadcaster_htlc_key, &keys.countersignatory_htlc_key, &keys.revocation_key);
14171417

Diff for: lightning/src/ln/channel.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,7 @@ impl<Signer: Sign> Channel<Signer> {
24642464
for (idx, (htlc, source)) in htlcs_cloned.drain(..).enumerate() {
24652465
if let Some(_) = htlc.transaction_output_index {
24662466
let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, feerate_per_kw,
2467-
self.get_counterparty_selected_contest_delay().unwrap(), &htlc,
2467+
self.get_counterparty_selected_contest_delay().unwrap(), &htlc, self.opt_anchors(),
24682468
&keys.broadcaster_delayed_payment_key, &keys.revocation_key);
24692469

24702470
let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, self.opt_anchors(), &keys);
@@ -4743,7 +4743,7 @@ impl<Signer: Sign> Channel<Signer> {
47434743

47444744
for (ref htlc_sig, ref htlc) in htlc_signatures.iter().zip(htlcs) {
47454745
log_trace!(logger, "Signed remote HTLC tx {} with redeemscript {} with pubkey {} -> {} in channel {}",
4746-
encode::serialize_hex(&chan_utils::build_htlc_transaction(&counterparty_commitment_txid, feerate_per_kw, self.get_holder_selected_contest_delay(), htlc, &counterparty_keys.broadcaster_delayed_payment_key, &counterparty_keys.revocation_key)),
4746+
encode::serialize_hex(&chan_utils::build_htlc_transaction(&counterparty_commitment_txid, feerate_per_kw, self.get_holder_selected_contest_delay(), htlc, self.opt_anchors(), &counterparty_keys.broadcaster_delayed_payment_key, &counterparty_keys.revocation_key)),
47474747
encode::serialize_hex(&chan_utils::get_htlc_redeemscript(&htlc, self.opt_anchors(), &counterparty_keys)),
47484748
log_bytes!(counterparty_keys.broadcaster_htlc_key.serialize()),
47494749
log_bytes!(htlc_sig.serialize_compact()[..]), log_bytes!(self.channel_id()));
@@ -6002,10 +6002,10 @@ mod tests {
60026002
let remote_signature = Signature::from_der(&hex::decode($counterparty_htlc_sig_hex).unwrap()[..]).unwrap();
60036003

60046004
let ref htlc = htlcs[$htlc_idx];
6005+
let opt_anchors = false;
60056006
let htlc_tx = chan_utils::build_htlc_transaction(&unsigned_tx.txid, chan.feerate_per_kw,
60066007
chan.get_counterparty_selected_contest_delay().unwrap(),
6007-
&htlc, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
6008-
let opt_anchors = false;
6008+
&htlc, opt_anchors, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
60096009
let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, opt_anchors, &keys);
60106010
let htlc_sighash = Message::from_slice(&bip143::SigHashCache::new(&htlc_tx).signature_hash(0, &htlc_redeemscript, htlc.amount_msat / 1000, SigHashType::All)[..]).unwrap();
60116011
secp_ctx.verify(&htlc_sighash, &remote_signature, &keys.countersignatory_htlc_key).unwrap();

Diff for: lightning/src/util/enforcing_trait_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl BaseSign for EnforcingSigner {
156156
for (this_htlc, sig) in trusted_tx.htlcs().iter().zip(&commitment_tx.counterparty_htlc_sigs) {
157157
assert!(this_htlc.transaction_output_index.is_some());
158158
let keys = trusted_tx.keys();
159-
let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, trusted_tx.feerate_per_kw(), holder_csv, &this_htlc, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
159+
let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, trusted_tx.feerate_per_kw(), holder_csv, &this_htlc, self.opt_anchors(), &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
160160

161161
let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&this_htlc, self.opt_anchors(), &keys);
162162

0 commit comments

Comments
 (0)