mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-11 07:39:41 +02:00
htlcswitch: remove PaymentDescriptor from the processExitHop's call signature
This is part of a systematic removal of PaymentDescriptor from the mechanics of the htlcswitch package.
This commit is contained in:
@@ -3606,8 +3606,12 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
|
|||||||
|
|
||||||
switch fwdInfo.NextHop {
|
switch fwdInfo.NextHop {
|
||||||
case hop.Exit:
|
case hop.Exit:
|
||||||
|
addMsg := pd.ToLogUpdate().UpdateMsg
|
||||||
|
//nolint:forcetypeassert
|
||||||
|
add := *addMsg.(*lnwire.UpdateAddHTLC)
|
||||||
err := l.processExitHop(
|
err := l.processExitHop(
|
||||||
pd, obfuscator, fwdInfo, heightNow, pld,
|
add, *pd.SourceRef, obfuscator, fwdInfo,
|
||||||
|
heightNow, pld,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.failf(LinkFailureError{
|
l.failf(LinkFailureError{
|
||||||
@@ -3790,9 +3794,10 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
|
|||||||
|
|
||||||
// processExitHop handles an htlc for which this link is the exit hop. It
|
// processExitHop handles an htlc for which this link is the exit hop. It
|
||||||
// returns a boolean indicating whether the commitment tx needs an update.
|
// returns a boolean indicating whether the commitment tx needs an update.
|
||||||
func (l *channelLink) processExitHop(pd *lnwallet.PaymentDescriptor,
|
func (l *channelLink) processExitHop(add lnwire.UpdateAddHTLC,
|
||||||
obfuscator hop.ErrorEncrypter, fwdInfo hop.ForwardingInfo,
|
sourceRef channeldb.AddRef, obfuscator hop.ErrorEncrypter,
|
||||||
heightNow uint32, payload invoices.Payload) error {
|
fwdInfo hop.ForwardingInfo, heightNow uint32,
|
||||||
|
payload invoices.Payload) error {
|
||||||
|
|
||||||
// If hodl.ExitSettle is requested, we will not validate the final hop's
|
// If hodl.ExitSettle is requested, we will not validate the final hop's
|
||||||
// ADD, nor will we settle the corresponding invoice or respond with the
|
// ADD, nor will we settle the corresponding invoice or respond with the
|
||||||
@@ -3806,38 +3811,31 @@ func (l *channelLink) processExitHop(pd *lnwallet.PaymentDescriptor,
|
|||||||
// As we're the exit hop, we'll double check the hop-payload included in
|
// As we're the exit hop, we'll double check the hop-payload included in
|
||||||
// the HTLC to ensure that it was crafted correctly by the sender and
|
// the HTLC to ensure that it was crafted correctly by the sender and
|
||||||
// is compatible with the HTLC we were extended.
|
// is compatible with the HTLC we were extended.
|
||||||
if pd.Amount < fwdInfo.AmountToForward {
|
if add.Amount < fwdInfo.AmountToForward {
|
||||||
l.log.Errorf("onion payload of incoming htlc(%x) has "+
|
l.log.Errorf("onion payload of incoming htlc(%x) has "+
|
||||||
"incompatible value: expected <=%v, got %v", pd.RHash,
|
"incompatible value: expected <=%v, got %v",
|
||||||
pd.Amount, fwdInfo.AmountToForward)
|
add.PaymentHash, add.Amount, fwdInfo.AmountToForward)
|
||||||
|
|
||||||
failure := NewLinkError(
|
failure := NewLinkError(
|
||||||
lnwire.NewFinalIncorrectHtlcAmount(pd.Amount),
|
lnwire.NewFinalIncorrectHtlcAmount(add.Amount),
|
||||||
)
|
)
|
||||||
|
l.sendHTLCError(add, sourceRef, failure, obfuscator, true)
|
||||||
addMsg := pd.ToLogUpdate().UpdateMsg
|
|
||||||
//nolint:forcetypeassert
|
|
||||||
add := *addMsg.(*lnwire.UpdateAddHTLC)
|
|
||||||
l.sendHTLCError(add, *pd.SourceRef, failure, obfuscator, true)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// We'll also ensure that our time-lock value has been computed
|
// We'll also ensure that our time-lock value has been computed
|
||||||
// correctly.
|
// correctly.
|
||||||
if pd.Timeout < fwdInfo.OutgoingCTLV {
|
if add.Expiry < fwdInfo.OutgoingCTLV {
|
||||||
l.log.Errorf("onion payload of incoming htlc(%x) has "+
|
l.log.Errorf("onion payload of incoming htlc(%x) has "+
|
||||||
"incompatible time-lock: expected <=%v, got %v",
|
"incompatible time-lock: expected <=%v, got %v",
|
||||||
pd.RHash[:], pd.Timeout, fwdInfo.OutgoingCTLV)
|
add.PaymentHash, add.Expiry, fwdInfo.OutgoingCTLV)
|
||||||
|
|
||||||
failure := NewLinkError(
|
failure := NewLinkError(
|
||||||
lnwire.NewFinalIncorrectCltvExpiry(pd.Timeout),
|
lnwire.NewFinalIncorrectCltvExpiry(add.Expiry),
|
||||||
)
|
)
|
||||||
|
|
||||||
addMsg := pd.ToLogUpdate().UpdateMsg
|
l.sendHTLCError(add, sourceRef, failure, obfuscator, true)
|
||||||
//nolint:forcetypeassert
|
|
||||||
add := *addMsg.(*lnwire.UpdateAddHTLC)
|
|
||||||
l.sendHTLCError(add, *pd.SourceRef, failure, obfuscator, true)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -3845,15 +3843,15 @@ func (l *channelLink) processExitHop(pd *lnwallet.PaymentDescriptor,
|
|||||||
// Notify the invoiceRegistry of the exit hop htlc. If we crash right
|
// Notify the invoiceRegistry of the exit hop htlc. If we crash right
|
||||||
// after this, this code will be re-executed after restart. We will
|
// after this, this code will be re-executed after restart. We will
|
||||||
// receive back a resolution event.
|
// receive back a resolution event.
|
||||||
invoiceHash := lntypes.Hash(pd.RHash)
|
invoiceHash := lntypes.Hash(add.PaymentHash)
|
||||||
|
|
||||||
circuitKey := models.CircuitKey{
|
circuitKey := models.CircuitKey{
|
||||||
ChanID: l.ShortChanID(),
|
ChanID: l.ShortChanID(),
|
||||||
HtlcID: pd.HtlcIndex,
|
HtlcID: add.ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
event, err := l.cfg.Registry.NotifyExitHopHtlc(
|
event, err := l.cfg.Registry.NotifyExitHopHtlc(
|
||||||
invoiceHash, pd.Amount, pd.Timeout, int32(heightNow),
|
invoiceHash, add.Amount, add.Expiry, int32(heightNow),
|
||||||
circuitKey, l.hodlQueue.ChanIn(), payload,
|
circuitKey, l.hodlQueue.ChanIn(), payload,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -3862,7 +3860,16 @@ func (l *channelLink) processExitHop(pd *lnwallet.PaymentDescriptor,
|
|||||||
|
|
||||||
// Create a hodlHtlc struct and decide either resolved now or later.
|
// Create a hodlHtlc struct and decide either resolved now or later.
|
||||||
htlc := hodlHtlc{
|
htlc := hodlHtlc{
|
||||||
pd: pd,
|
pd: &lnwallet.PaymentDescriptor{
|
||||||
|
EntryType: lnwallet.Add,
|
||||||
|
ChanID: add.ChanID,
|
||||||
|
RHash: add.PaymentHash,
|
||||||
|
Timeout: add.Expiry,
|
||||||
|
Amount: add.Amount,
|
||||||
|
HtlcIndex: add.ID,
|
||||||
|
SourceRef: &sourceRef,
|
||||||
|
BlindingPoint: add.BlindingPoint,
|
||||||
|
},
|
||||||
obfuscator: obfuscator,
|
obfuscator: obfuscator,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user