lnwallet+nursery+input: set sequence=1 for direct HTLC spends

This commit is contained in:
Johan T. Halseth 2020-03-06 16:11:47 +01:00
parent c5d58b4762
commit 92af2342da
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
5 changed files with 22 additions and 14 deletions

View File

@ -118,6 +118,7 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) {
&h.htlcResolution.SweepSignDesc, &h.htlcResolution.SweepSignDesc,
h.htlcResolution.Preimage[:], h.htlcResolution.Preimage[:],
h.broadcastHeight, h.broadcastHeight,
h.htlcResolution.CsvDelay,
) )
// With the input created, we can now generate the full // With the input created, we can now generate the full

View File

@ -156,15 +156,16 @@ type HtlcSucceedInput struct {
// MakeHtlcSucceedInput assembles a new redeem input that can be used to // MakeHtlcSucceedInput assembles a new redeem input that can be used to
// construct a sweep transaction. // construct a sweep transaction.
func MakeHtlcSucceedInput(outpoint *wire.OutPoint, func MakeHtlcSucceedInput(outpoint *wire.OutPoint,
signDescriptor *SignDescriptor, signDescriptor *SignDescriptor, preimage []byte, heightHint,
preimage []byte, heightHint uint32) HtlcSucceedInput { blocksToMaturity uint32) HtlcSucceedInput {
return HtlcSucceedInput{ return HtlcSucceedInput{
inputKit: inputKit{ inputKit: inputKit{
outpoint: *outpoint, outpoint: *outpoint,
witnessType: HtlcAcceptedRemoteSuccess, witnessType: HtlcAcceptedRemoteSuccess,
signDesc: *signDescriptor, signDesc: *signDescriptor,
heightHint: heightHint, heightHint: heightHint,
blockToMaturity: blocksToMaturity,
}, },
preimage: preimage, preimage: preimage,
} }

View File

@ -5253,7 +5253,8 @@ type IncomingHtlcResolution struct {
// pass after the SignedSuccessTx is confirmed in the chain before the // pass after the SignedSuccessTx is confirmed in the chain before the
// output can be swept. // output can be swept.
// //
// NOTE: If SignedSuccessTx is nil, then this field isn't needed. // NOTE: If SignedTimeoutTx is nil, then this field denotes the CSV
// delay needed to spend from the commitment transaction.
CsvDelay uint32 CsvDelay uint32
// ClaimOutpoint is the final outpoint that needs to be spent in order // ClaimOutpoint is the final outpoint that needs to be spent in order
@ -5293,7 +5294,8 @@ type OutgoingHtlcResolution struct {
// pass after the SignedTimeoutTx is confirmed in the chain before the // pass after the SignedTimeoutTx is confirmed in the chain before the
// output can be swept. // output can be swept.
// //
// NOTE: If SignedTimeoutTx is nil, then this field isn't needed. // NOTE: If SignedTimeoutTx is nil, then this field denotes the CSV
// delay needed to spend from the commitment transaction.
CsvDelay uint32 CsvDelay uint32
// ClaimOutpoint is the final outpoint that needs to be spent in order // ClaimOutpoint is the final outpoint that needs to be spent in order
@ -5366,6 +5368,7 @@ func newOutgoingHtlcResolution(signer input.Signer,
}, },
HashType: txscript.SigHashAll, HashType: txscript.SigHashAll,
}, },
CsvDelay: HtlcSecondLevelInputSequence(chanType),
}, nil }, nil
} }
@ -5487,7 +5490,6 @@ func newIncomingHtlcResolution(signer input.Signer,
// SignDescriptor needed to sweep the output. // SignDescriptor needed to sweep the output.
return &IncomingHtlcResolution{ return &IncomingHtlcResolution{
ClaimOutpoint: op, ClaimOutpoint: op,
CsvDelay: csvDelay,
SweepSignDesc: input.SignDescriptor{ SweepSignDesc: input.SignDescriptor{
KeyDesc: localChanCfg.HtlcBasePoint, KeyDesc: localChanCfg.HtlcBasePoint,
SingleTweak: keyRing.LocalHtlcKeyTweak, SingleTweak: keyRing.LocalHtlcKeyTweak,
@ -5498,6 +5500,7 @@ func newIncomingHtlcResolution(signer input.Signer,
}, },
HashType: txscript.SigHashAll, HashType: txscript.SigHashAll,
}, },
CsvDelay: HtlcSecondLevelInputSequence(chanType),
}, nil }, nil
} }

View File

@ -397,10 +397,11 @@ func (u *utxoNursery) IncubateOutputs(chanPoint wire.OutPoint,
// Otherwise, this is actually a kid output as we can sweep it // Otherwise, this is actually a kid output as we can sweep it
// once the commitment transaction confirms, and the absolute // once the commitment transaction confirms, and the absolute
// CLTV lock has expired. We set the CSV delay to zero to // CLTV lock has expired. We set the CSV delay what the
// indicate this is actually a CLTV output. // resolution encodes, since the sequence number must be set
// accordingly.
htlcOutput := makeKidOutput( htlcOutput := makeKidOutput(
&htlcRes.ClaimOutpoint, &chanPoint, 0, &htlcRes.ClaimOutpoint, &chanPoint, htlcRes.CsvDelay,
input.HtlcOfferedRemoteTimeout, input.HtlcOfferedRemoteTimeout,
&htlcRes.SweepSignDesc, htlcRes.Expiry, &htlcRes.SweepSignDesc, htlcRes.Expiry,
) )
@ -1271,7 +1272,8 @@ type kidOutput struct {
// output. // output.
// //
// NOTE: This will be set for: commitment outputs, and incoming HTLC's. // NOTE: This will be set for: commitment outputs, and incoming HTLC's.
// Otherwise, this will be zero. // Otherwise, this will be zero. It will also be non-zero for
// commitment types which requires confirmed spends.
blocksToMaturity uint32 blocksToMaturity uint32
// absoluteMaturity is the absolute height that this output will be // absoluteMaturity is the absolute height that this output will be

View File

@ -603,7 +603,6 @@ func createOutgoingRes(onLocalCommitment bool) *lnwallet.OutgoingHtlcResolution
Value: 10000, Value: 10000,
}, },
}, },
CsvDelay: 2,
} }
if onLocalCommitment { if onLocalCommitment {
@ -620,8 +619,10 @@ func createOutgoingRes(onLocalCommitment bool) *lnwallet.OutgoingHtlcResolution
} }
outgoingRes.SignedTimeoutTx = timeoutTx outgoingRes.SignedTimeoutTx = timeoutTx
outgoingRes.CsvDelay = 2
} else { } else {
outgoingRes.ClaimOutpoint = htlcOp outgoingRes.ClaimOutpoint = htlcOp
outgoingRes.CsvDelay = 0
} }
return &outgoingRes return &outgoingRes