lnwallet/channel: properly set SignDesc.Output
Only value was populated for some, which would cause code to rely on the PkScript being there to fail.
This commit is contained in:
parent
08bb8abaa3
commit
eb8d22e194
@ -3034,16 +3034,15 @@ func genRemoteHtlcSigJobs(keyRing *CommitmentKeyRing,
|
|||||||
// Finally, we'll generate a sign descriptor to generate a
|
// Finally, we'll generate a sign descriptor to generate a
|
||||||
// signature to give to the remote party for this commitment
|
// signature to give to the remote party for this commitment
|
||||||
// transaction. Note we use the raw HTLC amount.
|
// transaction. Note we use the raw HTLC amount.
|
||||||
|
txOut := remoteCommitView.txn.TxOut[htlc.remoteOutputIndex]
|
||||||
sigJob.SignDesc = input.SignDescriptor{
|
sigJob.SignDesc = input.SignDescriptor{
|
||||||
KeyDesc: localChanCfg.HtlcBasePoint,
|
KeyDesc: localChanCfg.HtlcBasePoint,
|
||||||
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
||||||
WitnessScript: htlc.theirWitnessScript,
|
WitnessScript: htlc.theirWitnessScript,
|
||||||
Output: &wire.TxOut{
|
Output: txOut,
|
||||||
Value: int64(htlc.Amount.ToSatoshis()),
|
HashType: sigHashType,
|
||||||
},
|
SigHashes: txscript.NewTxSigHashes(sigJob.Tx),
|
||||||
HashType: sigHashType,
|
InputIndex: 0,
|
||||||
SigHashes: txscript.NewTxSigHashes(sigJob.Tx),
|
|
||||||
InputIndex: 0,
|
|
||||||
}
|
}
|
||||||
sigJob.OutputIndex = htlc.remoteOutputIndex
|
sigJob.OutputIndex = htlc.remoteOutputIndex
|
||||||
|
|
||||||
@ -3087,16 +3086,15 @@ func genRemoteHtlcSigJobs(keyRing *CommitmentKeyRing,
|
|||||||
// Finally, we'll generate a sign descriptor to generate a
|
// Finally, we'll generate a sign descriptor to generate a
|
||||||
// signature to give to the remote party for this commitment
|
// signature to give to the remote party for this commitment
|
||||||
// transaction. Note we use the raw HTLC amount.
|
// transaction. Note we use the raw HTLC amount.
|
||||||
|
txOut := remoteCommitView.txn.TxOut[htlc.remoteOutputIndex]
|
||||||
sigJob.SignDesc = input.SignDescriptor{
|
sigJob.SignDesc = input.SignDescriptor{
|
||||||
KeyDesc: localChanCfg.HtlcBasePoint,
|
KeyDesc: localChanCfg.HtlcBasePoint,
|
||||||
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
||||||
WitnessScript: htlc.theirWitnessScript,
|
WitnessScript: htlc.theirWitnessScript,
|
||||||
Output: &wire.TxOut{
|
Output: txOut,
|
||||||
Value: int64(htlc.Amount.ToSatoshis()),
|
HashType: sigHashType,
|
||||||
},
|
SigHashes: txscript.NewTxSigHashes(sigJob.Tx),
|
||||||
HashType: sigHashType,
|
InputIndex: 0,
|
||||||
SigHashes: txscript.NewTxSigHashes(sigJob.Tx),
|
|
||||||
InputIndex: 0,
|
|
||||||
}
|
}
|
||||||
sigJob.OutputIndex = htlc.remoteOutputIndex
|
sigJob.OutputIndex = htlc.remoteOutputIndex
|
||||||
|
|
||||||
@ -5396,7 +5394,7 @@ func NewUnilateralCloseSummary(chanState *channeldb.OpenChannel, signer input.Si
|
|||||||
htlcResolutions, err := extractHtlcResolutions(
|
htlcResolutions, err := extractHtlcResolutions(
|
||||||
chainfee.SatPerKWeight(remoteCommit.FeePerKw), false, signer,
|
chainfee.SatPerKWeight(remoteCommit.FeePerKw), false, signer,
|
||||||
remoteCommit.Htlcs, keyRing, &chanState.LocalChanCfg,
|
remoteCommit.Htlcs, keyRing, &chanState.LocalChanCfg,
|
||||||
&chanState.RemoteChanCfg, *commitSpend.SpenderTxHash,
|
&chanState.RemoteChanCfg, commitSpend.SpendingTx,
|
||||||
chanState.ChanType,
|
chanState.ChanType,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -5599,13 +5597,13 @@ type HtlcResolutions struct {
|
|||||||
// allowing the caller to sweep an outgoing HTLC present on either their, or
|
// allowing the caller to sweep an outgoing HTLC present on either their, or
|
||||||
// the remote party's commitment transaction.
|
// the remote party's commitment transaction.
|
||||||
func newOutgoingHtlcResolution(signer input.Signer,
|
func newOutgoingHtlcResolution(signer input.Signer,
|
||||||
localChanCfg *channeldb.ChannelConfig, commitHash chainhash.Hash,
|
localChanCfg *channeldb.ChannelConfig, commitTx *wire.MsgTx,
|
||||||
htlc *channeldb.HTLC, keyRing *CommitmentKeyRing,
|
htlc *channeldb.HTLC, keyRing *CommitmentKeyRing,
|
||||||
feePerKw chainfee.SatPerKWeight, csvDelay uint32,
|
feePerKw chainfee.SatPerKWeight, csvDelay uint32,
|
||||||
localCommit bool, chanType channeldb.ChannelType) (*OutgoingHtlcResolution, error) {
|
localCommit bool, chanType channeldb.ChannelType) (*OutgoingHtlcResolution, error) {
|
||||||
|
|
||||||
op := wire.OutPoint{
|
op := wire.OutPoint{
|
||||||
Hash: commitHash,
|
Hash: commitTx.TxHash(),
|
||||||
Index: uint32(htlc.OutputIndex),
|
Index: uint32(htlc.OutputIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5664,16 +5662,15 @@ func newOutgoingHtlcResolution(signer input.Signer,
|
|||||||
// With the transaction created, we can generate a sign descriptor
|
// With the transaction created, we can generate a sign descriptor
|
||||||
// that's capable of generating the signature required to spend the
|
// that's capable of generating the signature required to spend the
|
||||||
// HTLC output using the timeout transaction.
|
// HTLC output using the timeout transaction.
|
||||||
|
txOut := commitTx.TxOut[htlc.OutputIndex]
|
||||||
timeoutSignDesc := input.SignDescriptor{
|
timeoutSignDesc := input.SignDescriptor{
|
||||||
KeyDesc: localChanCfg.HtlcBasePoint,
|
KeyDesc: localChanCfg.HtlcBasePoint,
|
||||||
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
||||||
WitnessScript: htlcScript,
|
WitnessScript: htlcScript,
|
||||||
Output: &wire.TxOut{
|
Output: txOut,
|
||||||
Value: int64(htlc.Amt.ToSatoshis()),
|
HashType: txscript.SigHashAll,
|
||||||
},
|
SigHashes: txscript.NewTxSigHashes(timeoutTx),
|
||||||
HashType: txscript.SigHashAll,
|
InputIndex: 0,
|
||||||
SigHashes: txscript.NewTxSigHashes(timeoutTx),
|
|
||||||
InputIndex: 0,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
htlcSig, err := btcec.ParseDERSignature(htlc.Signature, btcec.S256())
|
htlcSig, err := btcec.ParseDERSignature(htlc.Signature, btcec.S256())
|
||||||
@ -5738,13 +5735,13 @@ func newOutgoingHtlcResolution(signer input.Signer,
|
|||||||
//
|
//
|
||||||
// TODO(roasbeef) consolidate code with above func
|
// TODO(roasbeef) consolidate code with above func
|
||||||
func newIncomingHtlcResolution(signer input.Signer,
|
func newIncomingHtlcResolution(signer input.Signer,
|
||||||
localChanCfg *channeldb.ChannelConfig, commitHash chainhash.Hash,
|
localChanCfg *channeldb.ChannelConfig, commitTx *wire.MsgTx,
|
||||||
htlc *channeldb.HTLC, keyRing *CommitmentKeyRing,
|
htlc *channeldb.HTLC, keyRing *CommitmentKeyRing,
|
||||||
feePerKw chainfee.SatPerKWeight, csvDelay uint32, localCommit bool,
|
feePerKw chainfee.SatPerKWeight, csvDelay uint32, localCommit bool,
|
||||||
chanType channeldb.ChannelType) (*IncomingHtlcResolution, error) {
|
chanType channeldb.ChannelType) (*IncomingHtlcResolution, error) {
|
||||||
|
|
||||||
op := wire.OutPoint{
|
op := wire.OutPoint{
|
||||||
Hash: commitHash,
|
Hash: commitTx.TxHash(),
|
||||||
Index: uint32(htlc.OutputIndex),
|
Index: uint32(htlc.OutputIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5795,16 +5792,15 @@ func newIncomingHtlcResolution(signer input.Signer,
|
|||||||
|
|
||||||
// Once we've created the second-level transaction, we'll generate the
|
// Once we've created the second-level transaction, we'll generate the
|
||||||
// SignDesc needed spend the HTLC output using the success transaction.
|
// SignDesc needed spend the HTLC output using the success transaction.
|
||||||
|
txOut := commitTx.TxOut[htlc.OutputIndex]
|
||||||
successSignDesc := input.SignDescriptor{
|
successSignDesc := input.SignDescriptor{
|
||||||
KeyDesc: localChanCfg.HtlcBasePoint,
|
KeyDesc: localChanCfg.HtlcBasePoint,
|
||||||
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
||||||
WitnessScript: htlcScript,
|
WitnessScript: htlcScript,
|
||||||
Output: &wire.TxOut{
|
Output: txOut,
|
||||||
Value: int64(htlc.Amt.ToSatoshis()),
|
HashType: txscript.SigHashAll,
|
||||||
},
|
SigHashes: txscript.NewTxSigHashes(successTx),
|
||||||
HashType: txscript.SigHashAll,
|
InputIndex: 0,
|
||||||
SigHashes: txscript.NewTxSigHashes(successTx),
|
|
||||||
InputIndex: 0,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
htlcSig, err := btcec.ParseDERSignature(htlc.Signature, btcec.S256())
|
htlcSig, err := btcec.ParseDERSignature(htlc.Signature, btcec.S256())
|
||||||
@ -5892,7 +5888,7 @@ func (r *OutgoingHtlcResolution) HtlcPoint() wire.OutPoint {
|
|||||||
func extractHtlcResolutions(feePerKw chainfee.SatPerKWeight, ourCommit bool,
|
func extractHtlcResolutions(feePerKw chainfee.SatPerKWeight, ourCommit bool,
|
||||||
signer input.Signer, htlcs []channeldb.HTLC, keyRing *CommitmentKeyRing,
|
signer input.Signer, htlcs []channeldb.HTLC, keyRing *CommitmentKeyRing,
|
||||||
localChanCfg, remoteChanCfg *channeldb.ChannelConfig,
|
localChanCfg, remoteChanCfg *channeldb.ChannelConfig,
|
||||||
commitHash chainhash.Hash, chanType channeldb.ChannelType) (
|
commitTx *wire.MsgTx, chanType channeldb.ChannelType) (
|
||||||
*HtlcResolutions, error) {
|
*HtlcResolutions, error) {
|
||||||
|
|
||||||
// TODO(roasbeef): don't need to swap csv delay?
|
// TODO(roasbeef): don't need to swap csv delay?
|
||||||
@ -5924,7 +5920,7 @@ func extractHtlcResolutions(feePerKw chainfee.SatPerKWeight, ourCommit bool,
|
|||||||
// Otherwise, we'll create an incoming HTLC resolution
|
// Otherwise, we'll create an incoming HTLC resolution
|
||||||
// as we can satisfy the contract.
|
// as we can satisfy the contract.
|
||||||
ihr, err := newIncomingHtlcResolution(
|
ihr, err := newIncomingHtlcResolution(
|
||||||
signer, localChanCfg, commitHash, &htlc,
|
signer, localChanCfg, commitTx, &htlc,
|
||||||
keyRing, feePerKw, uint32(csvDelay), ourCommit,
|
keyRing, feePerKw, uint32(csvDelay), ourCommit,
|
||||||
chanType,
|
chanType,
|
||||||
)
|
)
|
||||||
@ -5937,7 +5933,7 @@ func extractHtlcResolutions(feePerKw chainfee.SatPerKWeight, ourCommit bool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ohr, err := newOutgoingHtlcResolution(
|
ohr, err := newOutgoingHtlcResolution(
|
||||||
signer, localChanCfg, commitHash, &htlc, keyRing,
|
signer, localChanCfg, commitTx, &htlc, keyRing,
|
||||||
feePerKw, uint32(csvDelay), ourCommit, chanType,
|
feePerKw, uint32(csvDelay), ourCommit, chanType,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -6138,12 +6134,11 @@ func NewLocalForceCloseSummary(chanState *channeldb.OpenChannel,
|
|||||||
// outgoing HTLC's that we'll need to claim as well. If this is after
|
// outgoing HTLC's that we'll need to claim as well. If this is after
|
||||||
// recovery there is not much we can do with HTLCs, so we'll always
|
// recovery there is not much we can do with HTLCs, so we'll always
|
||||||
// use what we have in our latest state when extracting resolutions.
|
// use what we have in our latest state when extracting resolutions.
|
||||||
txHash := commitTx.TxHash()
|
|
||||||
localCommit := chanState.LocalCommitment
|
localCommit := chanState.LocalCommitment
|
||||||
htlcResolutions, err := extractHtlcResolutions(
|
htlcResolutions, err := extractHtlcResolutions(
|
||||||
chainfee.SatPerKWeight(localCommit.FeePerKw), true, signer,
|
chainfee.SatPerKWeight(localCommit.FeePerKw), true, signer,
|
||||||
localCommit.Htlcs, keyRing, &chanState.LocalChanCfg,
|
localCommit.Htlcs, keyRing, &chanState.LocalChanCfg,
|
||||||
&chanState.RemoteChanCfg, txHash, chanState.ChanType,
|
&chanState.RemoteChanCfg, commitTx, chanState.ChanType,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user