lnwallet: populate HTLC resolutions within the ForceCloseSummary

This commit is contained in:
Olaoluwa Osuntokun 2017-07-30 13:21:26 -07:00
parent 83e0116d7e
commit 01aa4eb2ae
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
1 changed files with 35 additions and 15 deletions

View File

@ -3479,16 +3479,20 @@ func (lc *LightningChannel) ForceClose() (*ForceCloseSummary, error) {
// commitment transaction. We'll need this to find the corresponding // commitment transaction. We'll need this to find the corresponding
// output in the commitment transaction and potentially for creating // output in the commitment transaction and potentially for creating
// the sign descriptor. // the sign descriptor.
csvTimeout := lc.channelState.LocalCsvDelay csvTimeout := uint32(lc.localChanCfg.CsvDelay)
selfKey := lc.channelState.OurCommitKey unusedRevocation, err := lc.channelState.RevocationProducer.AtIndex(
producer := lc.channelState.RevocationProducer lc.currentHeight,
unusedRevocation, err := producer.AtIndex(lc.currentHeight) )
if err != nil { if err != nil {
return nil, err return nil, err
} }
revokeKey := DeriveRevocationPubkey(lc.channelState.TheirCommitKey, commitPoint := ComputeCommitmentPoint(unusedRevocation[:])
unusedRevocation[:]) revokeKey := DeriveRevocationPubkey(
selfScript, err := commitScriptToSelf(csvTimeout, selfKey, revokeKey) lc.remoteChanCfg.RevocationBasePoint,
commitPoint,
)
delayKey := TweakPubKey(lc.localChanCfg.DelayBasePoint, commitPoint)
selfScript, err := commitScriptToSelf(csvTimeout, delayKey, revokeKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -3500,11 +3504,11 @@ func (lc *LightningChannel) ForceClose() (*ForceCloseSummary, error) {
// Locate the output index of the delayed commitment output back to us. // Locate the output index of the delayed commitment output back to us.
// We'll return the details of this output to the caller so they can // We'll return the details of this output to the caller so they can
// sweep it once it's mature. // sweep it once it's mature.
// TODO(roasbeef): also return HTLC info, assumes only p2wsh is commit var (
// tx delayIndex uint32
var delayIndex uint32 delayScript []byte
var delayScript []byte selfSignDesc *SignDescriptor
var selfSignDesc *SignDescriptor )
for i, txOut := range commitTx.TxOut { for i, txOut := range commitTx.TxOut {
if !bytes.Equal(payToUsScriptHash, txOut.PkScript) { if !bytes.Equal(payToUsScriptHash, txOut.PkScript) {
continue continue
@ -3519,10 +3523,14 @@ func (lc *LightningChannel) ForceClose() (*ForceCloseSummary, error) {
// descriptor which is capable of generating the signature the caller // descriptor which is capable of generating the signature the caller
// needs to sweep this output. The hash cache, and input index are not // needs to sweep this output. The hash cache, and input index are not
// set as the caller will decide these values once sweeping the output. // set as the caller will decide these values once sweeping the output.
// If the output is non-existant (dust), have the sign descriptor be nil. // If the output is non-existent (dust), have the sign descriptor be
// nil.
if len(delayScript) != 0 { if len(delayScript) != 0 {
singleTweak := SingleTweakBytes(commitPoint,
lc.localChanCfg.DelayBasePoint)
selfSignDesc = &SignDescriptor{ selfSignDesc = &SignDescriptor{
PubKey: selfKey, PubKey: lc.localChanCfg.DelayBasePoint,
SingleTweak: singleTweak,
WitnessScript: selfScript, WitnessScript: selfScript,
Output: &wire.TxOut{ Output: &wire.TxOut{
PkScript: delayScript, PkScript: delayScript,
@ -3532,6 +3540,17 @@ func (lc *LightningChannel) ForceClose() (*ForceCloseSummary, error) {
} }
} }
// Once the delay output has been found (if it exists), then we'll also
// need to create a series of sign descriptors for any lingering
// outgoing HTLC's that we'll need to claim as well.
txHash := commitTx.TxHash()
htlcResolutions, _, err := extractHtlcResolutions(
lc.channelState.FeePerKw, true, lc.signer, lc.channelState.Htlcs,
commitPoint, revokeKey, lc.localChanCfg, lc.remoteChanCfg, txHash)
if err != nil {
return nil, err
}
// Finally, close the channel force close signal which notifies any // Finally, close the channel force close signal which notifies any
// subscribers that the channel has now been forcibly closed. This // subscribers that the channel has now been forcibly closed. This
// allows callers to begin to carry out any post channel closure // allows callers to begin to carry out any post channel closure
@ -3544,9 +3563,10 @@ func (lc *LightningChannel) ForceClose() (*ForceCloseSummary, error) {
Hash: commitTx.TxHash(), Hash: commitTx.TxHash(),
Index: delayIndex, Index: delayIndex,
}, },
SelfOutputMaturity: csvTimeout,
CloseTx: commitTx, CloseTx: commitTx,
SelfOutputSignDesc: selfSignDesc, SelfOutputSignDesc: selfSignDesc,
SelfOutputMaturity: csvTimeout,
HtlcResolutions: htlcResolutions,
}, nil }, nil
} }