lnwallet: choose HTLC scripts based on channel type

This commit is contained in:
Johan T. Halseth 2020-03-06 16:11:47 +01:00
parent 21c5a957bc
commit 6810912c86
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -615,6 +615,12 @@ func genHtlcScript(chanType channeldb.ChannelType, isIncoming, ourCommit bool,
err error err error
) )
// Choose scripts based on channel type.
confirmedHtlcSpends := false
if chanType.HasAnchors() {
confirmedHtlcSpends = true
}
// Generate the proper redeem scripts for the HTLC output modified by // Generate the proper redeem scripts for the HTLC output modified by
// two-bits denoting if this is an incoming HTLC, and if the HTLC is // two-bits denoting if this is an incoming HTLC, and if the HTLC is
// being applied to their commitment transaction or ours. // being applied to their commitment transaction or ours.
@ -623,30 +629,37 @@ func genHtlcScript(chanType channeldb.ChannelType, isIncoming, ourCommit bool,
// transaction. So we need to use the receiver's version of HTLC the // transaction. So we need to use the receiver's version of HTLC the
// script. // script.
case isIncoming && ourCommit: case isIncoming && ourCommit:
witnessScript, err = input.ReceiverHTLCScript(timeout, witnessScript, err = input.ReceiverHTLCScript(
keyRing.RemoteHtlcKey, keyRing.LocalHtlcKey, timeout, keyRing.RemoteHtlcKey, keyRing.LocalHtlcKey,
keyRing.RevocationKey, rHash[:], false) keyRing.RevocationKey, rHash[:], confirmedHtlcSpends,
)
// We're being paid via an HTLC by the remote party, and the HTLC is // We're being paid via an HTLC by the remote party, and the HTLC is
// being added to their commitment transaction, so we use the sender's // being added to their commitment transaction, so we use the sender's
// version of the HTLC script. // version of the HTLC script.
case isIncoming && !ourCommit: case isIncoming && !ourCommit:
witnessScript, err = input.SenderHTLCScript(keyRing.RemoteHtlcKey, witnessScript, err = input.SenderHTLCScript(
keyRing.LocalHtlcKey, keyRing.RevocationKey, rHash[:], false) keyRing.RemoteHtlcKey, keyRing.LocalHtlcKey,
keyRing.RevocationKey, rHash[:], confirmedHtlcSpends,
)
// We're sending an HTLC which is being added to our commitment // We're sending an HTLC which is being added to our commitment
// transaction. Therefore, we need to use the sender's version of the // transaction. Therefore, we need to use the sender's version of the
// HTLC script. // HTLC script.
case !isIncoming && ourCommit: case !isIncoming && ourCommit:
witnessScript, err = input.SenderHTLCScript(keyRing.LocalHtlcKey, witnessScript, err = input.SenderHTLCScript(
keyRing.RemoteHtlcKey, keyRing.RevocationKey, rHash[:], false) keyRing.LocalHtlcKey, keyRing.RemoteHtlcKey,
keyRing.RevocationKey, rHash[:], confirmedHtlcSpends,
)
// Finally, we're paying the remote party via an HTLC, which is being // Finally, we're paying the remote party via an HTLC, which is being
// added to their commitment transaction. Therefore, we use the // added to their commitment transaction. Therefore, we use the
// receiver's version of the HTLC script. // receiver's version of the HTLC script.
case !isIncoming && !ourCommit: case !isIncoming && !ourCommit:
witnessScript, err = input.ReceiverHTLCScript(timeout, keyRing.LocalHtlcKey, witnessScript, err = input.ReceiverHTLCScript(
keyRing.RemoteHtlcKey, keyRing.RevocationKey, rHash[:], false) timeout, keyRing.LocalHtlcKey, keyRing.RemoteHtlcKey,
keyRing.RevocationKey, rHash[:], confirmedHtlcSpends,
)
} }
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err