lnwallet: ForceCloseSummary should check if to-local output exists
If the value of the to-local output is below the dust limit, the ForceCloseSummary should not include a sign descriptor for this output. We also find the proper to-self output by looking for the expected public key script and not assume that no HTLC outputs exist.
This commit is contained in:
parent
52b56b8cf2
commit
a6a503bf28
@ -2146,28 +2146,12 @@ func (lc *LightningChannel) ForceClose() (*ForceCloseSummary, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Locate the output index of the delayed commitment output back to us.
|
// Re-derive the original pkScript for to-self output within the
|
||||||
// We'll return the details of this output to the caller so they can
|
// commitment transaction. We'll need this to find the corresponding
|
||||||
// sweep it once it's mature.
|
// output in the commitment transaction and potentially for creating
|
||||||
// TODO(roasbeef): also return HTLC info, assumes only p2wsh is commit
|
// the sign descriptor.
|
||||||
// tx
|
|
||||||
var delayIndex uint32
|
|
||||||
var delayScript []byte
|
|
||||||
for i, txOut := range commitTx.TxOut {
|
|
||||||
if !txscript.IsPayToWitnessScriptHash(txOut.PkScript) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
delayIndex = uint32(i)
|
|
||||||
delayScript = txOut.PkScript
|
|
||||||
}
|
|
||||||
|
|
||||||
csvTimeout := lc.channelState.LocalCsvDelay
|
csvTimeout := lc.channelState.LocalCsvDelay
|
||||||
selfKey := lc.channelState.OurCommitKey
|
selfKey := lc.channelState.OurCommitKey
|
||||||
|
|
||||||
// Re-derive the original pkScript for out to-self output within the
|
|
||||||
// commitment transaction. We'll need this for the created sign
|
|
||||||
// descriptor.
|
|
||||||
producer := lc.channelState.RevocationProducer
|
producer := lc.channelState.RevocationProducer
|
||||||
unusedRevocation, err := producer.AtIndex(lc.currentHeight)
|
unusedRevocation, err := producer.AtIndex(lc.currentHeight)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -2179,19 +2163,44 @@ func (lc *LightningChannel) ForceClose() (*ForceCloseSummary, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
payToUsScriptHash, err := witnessScriptHash(selfScript)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// sweep it once it's mature.
|
||||||
|
// TODO(roasbeef): also return HTLC info, assumes only p2wsh is commit
|
||||||
|
// tx
|
||||||
|
var delayIndex uint32
|
||||||
|
var delayScript []byte
|
||||||
|
var selfSignDesc *SignDescriptor
|
||||||
|
for i, txOut := range commitTx.TxOut {
|
||||||
|
if !bytes.Equal(payToUsScriptHash, txOut.PkScript) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
delayIndex = uint32(i)
|
||||||
|
delayScript = txOut.PkScript
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
// With the necessary information gathered above, create a new sign
|
// With the necessary information gathered above, create a new sign
|
||||||
// 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.
|
||||||
selfSignDesc := &SignDescriptor{
|
// If the output is non-existant (dust), have the sign descriptor be nil.
|
||||||
PubKey: selfKey,
|
if len(delayScript) != 0 {
|
||||||
WitnessScript: selfScript,
|
selfSignDesc = &SignDescriptor{
|
||||||
Output: &wire.TxOut{
|
PubKey: selfKey,
|
||||||
PkScript: delayScript,
|
WitnessScript: selfScript,
|
||||||
Value: int64(lc.channelState.OurBalance),
|
Output: &wire.TxOut{
|
||||||
},
|
PkScript: delayScript,
|
||||||
HashType: txscript.SigHashAll,
|
Value: int64(lc.channelState.OurBalance),
|
||||||
|
},
|
||||||
|
HashType: txscript.SigHashAll,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, close the channel force close signal which notifies any
|
// Finally, close the channel force close signal which notifies any
|
||||||
|
Loading…
Reference in New Issue
Block a user