lnwallet: properly populate the signDesc within UnilateralCloseSummary
This commit modifies the closeObserver code to populate the signDesc in the case we have a non-trimmed balance. Additionally, we now also add a *wire.OutPoint field to the struct in order to allow receivers of the message to construct a witness that can spend the newly created output to their wallet.
This commit is contained in:
parent
8a23de5303
commit
899fa1ea3e
@ -1366,24 +1366,42 @@ func (lc *LightningChannel) closeObserver(channelCloseNtfn *chainntnfs.SpendEven
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// With the HTLC's taken care of, we'll generate the sign
|
// Before we can generate the proper sign descriptor, we'll
|
||||||
// descriptor necessary to sweep our commitment output.
|
// need to locate the output index of our non-delayed output on
|
||||||
selfWitnessScript, err := commitScriptUnencumbered(localKey)
|
// the commitment transaction.
|
||||||
|
selfP2WKH, err := commitScriptUnencumbered(localKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
walletLog.Errorf("unable to create self commit "+
|
walletLog.Errorf("unable to create self commit "+
|
||||||
"script: %v", err)
|
"script: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
localPayBase := lc.localChanCfg.PaymentBasePoint
|
var selfPoint *wire.OutPoint
|
||||||
selfSignDesc := SignDescriptor{
|
for outputIndex, txOut := range commitTxBroadcast.TxOut {
|
||||||
PubKey: localPayBase,
|
if bytes.Equal(txOut.PkScript, selfP2WKH) {
|
||||||
SingleTweak: SingleTweakBytes(commitPoint, localPayBase),
|
selfPoint = &wire.OutPoint{
|
||||||
WitnessScript: selfWitnessScript,
|
Hash: *commitSpend.SpenderTxHash,
|
||||||
Output: &wire.TxOut{
|
Index: uint32(outputIndex),
|
||||||
Value: int64(remoteChanState.LocalBalance),
|
}
|
||||||
PkScript: selfWitnessScript,
|
break
|
||||||
},
|
}
|
||||||
HashType: txscript.SigHashAll,
|
}
|
||||||
|
|
||||||
|
// With the HTLC's taken care of, we'll generate the sign
|
||||||
|
// descriptor necessary to sweep our commitment output, but
|
||||||
|
// only if we had a non-trimmed balance.
|
||||||
|
var selfSignDesc *SignDescriptor
|
||||||
|
if selfPoint != nil {
|
||||||
|
localPayBase := lc.localChanCfg.PaymentBasePoint
|
||||||
|
selfSignDesc = &SignDescriptor{
|
||||||
|
PubKey: localPayBase,
|
||||||
|
SingleTweak: SingleTweakBytes(commitPoint, localPayBase),
|
||||||
|
WitnessScript: selfP2WKH,
|
||||||
|
Output: &wire.TxOut{
|
||||||
|
Value: int64(lc.channelState.LocalBalance),
|
||||||
|
PkScript: selfP2WKH,
|
||||||
|
},
|
||||||
|
HashType: txscript.SigHashAll,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(roasbeef): send msg before writing to disk
|
// TODO(roasbeef): send msg before writing to disk
|
||||||
@ -1400,6 +1418,7 @@ func (lc *LightningChannel) closeObserver(channelCloseNtfn *chainntnfs.SpendEven
|
|||||||
lc.UnilateralClose <- &UnilateralCloseSummary{
|
lc.UnilateralClose <- &UnilateralCloseSummary{
|
||||||
SpendDetail: commitSpend,
|
SpendDetail: commitSpend,
|
||||||
ChannelCloseSummary: closeSummary,
|
ChannelCloseSummary: closeSummary,
|
||||||
|
SelfOutPoint: selfPoint,
|
||||||
SelfOutputSignDesc: selfSignDesc,
|
SelfOutputSignDesc: selfSignDesc,
|
||||||
HtlcResolutions: htlcResolutions,
|
HtlcResolutions: htlcResolutions,
|
||||||
}
|
}
|
||||||
@ -3303,9 +3322,14 @@ type UnilateralCloseSummary struct {
|
|||||||
// channel and in which state is was closed.
|
// channel and in which state is was closed.
|
||||||
channeldb.ChannelCloseSummary
|
channeldb.ChannelCloseSummary
|
||||||
|
|
||||||
|
// SelfOutPoint is the full outpoint that points to our non-delayed
|
||||||
|
// pay-to-self output within the commitment transaction of the remote
|
||||||
|
// party.
|
||||||
|
SelfOutPoint *wire.OutPoint
|
||||||
|
|
||||||
// SelfOutputSignDesc is a fully populated sign descriptor capable of
|
// SelfOutputSignDesc is a fully populated sign descriptor capable of
|
||||||
// generating a valid signature to sweep the output paying to us
|
// generating a valid signature to sweep the output paying to us
|
||||||
SelfOutputSignDesc SignDescriptor
|
SelfOutputSignDesc *SignDescriptor
|
||||||
|
|
||||||
// HtlcResolutions is a slice of HTLC resolutions which allows the
|
// HtlcResolutions is a slice of HTLC resolutions which allows the
|
||||||
// local node to sweep any outgoing HTLC"s after the timeout period has
|
// local node to sweep any outgoing HTLC"s after the timeout period has
|
||||||
|
Loading…
Reference in New Issue
Block a user