Skip to content

Commit 212c41a

Browse files
committed
Set the SigHashType of htlc signatures w/ anchors to SinglePlusAnyoneCanPay
1 parent 2a8a396 commit 212c41a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,8 @@ impl<'a> TrustedCommitmentTransaction<'a> {
14071407

14081408
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);
14091409

1410-
let sighash = hash_to_message!(&bip143::SigHashCache::new(&htlc_tx).signature_hash(0, &htlc_redeemscript, this_htlc.amount_msat / 1000, SigHashType::All)[..]);
1410+
let sighashtype = if self.opt_anchors() { SigHashType::SinglePlusAnyoneCanPay } else { SigHashType::All };
1411+
let sighash = hash_to_message!(&bip143::SigHashCache::new(&htlc_tx).signature_hash(0, &htlc_redeemscript, this_htlc.amount_msat / 1000, sighashtype)[..]);
14111412
ret.push(secp_ctx.sign(&sighash, &holder_htlc_key));
14121413
}
14131414
Ok(ret)
@@ -1429,13 +1430,15 @@ impl<'a> TrustedCommitmentTransaction<'a> {
14291430

14301431
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);
14311432

1433+
let sighashtype = if self.opt_anchors() { SigHashType::SinglePlusAnyoneCanPay } else { SigHashType::All };
1434+
14321435
// First push the multisig dummy, note that due to BIP147 (NULLDUMMY) it must be a zero-length element.
14331436
htlc_tx.input[0].witness.push(Vec::new());
14341437

14351438
htlc_tx.input[0].witness.push(counterparty_signature.serialize_der().to_vec());
14361439
htlc_tx.input[0].witness.push(signature.serialize_der().to_vec());
1437-
htlc_tx.input[0].witness[1].push(SigHashType::All as u8);
1438-
htlc_tx.input[0].witness[2].push(SigHashType::All as u8);
1440+
htlc_tx.input[0].witness[1].push(sighashtype as u8);
1441+
htlc_tx.input[0].witness[2].push(sighashtype as u8);
14391442

14401443
if this_htlc.offered {
14411444
// Due to BIP146 (MINIMALIF) this must be a zero-length element to relay.

0 commit comments

Comments
 (0)