lnwallet: in extractHtlcResolutions use csvDelay gated on commitment ownership

This commit fixes a bug wherein we would use the incorrect csvDelay
when crafting HTLC resolutions after a unilateral channel closure.
Previously, we would always use the csvDelay of the local party, as in
the force close case that’s the correct value. However, a unilateral
channel closure instead requires the _remote_ delay.
This commit is contained in:
Olaoluwa Osuntokun 2017-09-26 19:03:04 -07:00
parent 21782374c9
commit 0086e6e427
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -3414,7 +3414,7 @@ type OutgoingHtlcResolution struct {
func newHtlcResolution(signer Signer, localChanCfg *channeldb.ChannelConfig, func newHtlcResolution(signer Signer, localChanCfg *channeldb.ChannelConfig,
commitHash chainhash.Hash, htlc *channeldb.HTLC, commitTweak []byte, commitHash chainhash.Hash, htlc *channeldb.HTLC, commitTweak []byte,
delayKey, localKey, remoteKey *btcec.PublicKey, revokeKey *btcec.PublicKey, delayKey, localKey, remoteKey *btcec.PublicKey, revokeKey *btcec.PublicKey,
feePewKw, dustLimit btcutil.Amount) (*OutgoingHtlcResolution, error) { feePewKw, dustLimit btcutil.Amount, csvDelay uint32) (*OutgoingHtlcResolution, error) {
op := wire.OutPoint{ op := wire.OutPoint{
Hash: commitHash, Hash: commitHash,
@ -3429,8 +3429,8 @@ func newHtlcResolution(signer Signer, localChanCfg *channeldb.ChannelConfig,
// With the fee calculated, re-construct the second level timeout // With the fee calculated, re-construct the second level timeout
// transaction. // transaction.
timeoutTx, err := createHtlcTimeoutTx(op, secondLevelOutputAmt, timeoutTx, err := createHtlcTimeoutTx(
htlc.RefundTimeout, uint32(localChanCfg.CsvDelay), op, secondLevelOutputAmt, htlc.RefundTimeout, csvDelay,
revokeKey, delayKey, revokeKey, delayKey,
) )
if err != nil { if err != nil {
@ -3469,8 +3469,9 @@ func newHtlcResolution(signer Signer, localChanCfg *channeldb.ChannelConfig,
// Finally, we'll generate the script output that the timeout // Finally, we'll generate the script output that the timeout
// transaction creates so we can generate the signDesc required to // transaction creates so we can generate the signDesc required to
// complete the claim process after a delay period. // complete the claim process after a delay period.
htlcSweepScript, err := secondLevelHtlcScript(revokeKey, htlcSweepScript, err := secondLevelHtlcScript(
delayKey, uint32(localChanCfg.CsvDelay)) revokeKey, delayKey, csvDelay,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -3509,8 +3510,10 @@ func extractHtlcResolutions(feePerKw btcutil.Amount, ourCommit bool,
remoteKey := TweakPubKey(remoteChanCfg.PaymentBasePoint, commitPoint) remoteKey := TweakPubKey(remoteChanCfg.PaymentBasePoint, commitPoint)
dustLimit := remoteChanCfg.DustLimit dustLimit := remoteChanCfg.DustLimit
csvDelay := remoteChanCfg.CsvDelay
if ourCommit { if ourCommit {
dustLimit = localChanCfg.DustLimit dustLimit = localChanCfg.DustLimit
csvDelay = localChanCfg.CsvDelay
} }
htlcResolutions := make([]OutgoingHtlcResolution, len(htlcs)) htlcResolutions := make([]OutgoingHtlcResolution, len(htlcs))
@ -3530,9 +3533,11 @@ func extractHtlcResolutions(feePerKw btcutil.Amount, ourCommit bool,
continue continue
} }
ohr, err := newHtlcResolution(signer, localChanCfg, commitHash, ohr, err := newHtlcResolution(
htlc, commitTweak, delayKey, localKey, remoteKey, signer, localChanCfg, commitHash, htlc, commitTweak,
revokeKey, feePerKw, dustLimit) delayKey, localKey, remoteKey, revokeKey, feePerKw,
dustLimit, uint32(csvDelay),
)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }