Skip to content

Commit a626007

Browse files
committed
htlcswitch+channeldb+lnwallet: fix CustomRecord decoding
It doesn't make sense to do multiple encode/decode round trips on the custom data of an HTLC. So we just use the same custom record type everywhere, which also simplifies some of the code again.
1 parent f59c0c1 commit a626007

File tree

3 files changed

+52
-237
lines changed

3 files changed

+52
-237
lines changed

channeldb/channel.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,6 +2750,8 @@ func (h *HTLC) Copy() HTLC {
27502750
copy(clone.Signature[:], h.Signature)
27512751
copy(clone.RHash[:], h.RHash[:])
27522752
copy(clone.ExtraData, h.ExtraData)
2753+
clone.BlindingPoint = h.BlindingPoint
2754+
clone.CustomRecords = h.CustomRecords.Copy()
27532755

27542756
return clone
27552757
}

htlcswitch/link.go

Lines changed: 30 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3358,27 +3358,6 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
33583358
continue
33593359
}
33603360

3361-
var customRecords record.CustomSet
3362-
err = fn.MapOptionZ(
3363-
pd.CustomRecords, func(b tlv.Blob) error {
3364-
r, err := lnwire.ParseCustomRecords(b)
3365-
if err != nil {
3366-
return err
3367-
}
3368-
3369-
customRecords = record.CustomSet(r)
3370-
3371-
return nil
3372-
},
3373-
)
3374-
if err != nil {
3375-
l.fail(LinkFailureError{
3376-
code: ErrInternalError,
3377-
}, err.Error())
3378-
3379-
return
3380-
}
3381-
33823361
switch fwdPkg.State {
33833362
case channeldb.FwdStateProcessed:
33843363
// This add was not forwarded on the previous
@@ -3412,21 +3391,22 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
34123391

34133392
inboundFee := l.cfg.FwrdingPolicy.InboundFee
34143393

3415-
//nolint:lll
34163394
updatePacket := &htlcPacket{
3417-
incomingChanID: l.ShortChanID(),
3418-
incomingHTLCID: pd.HtlcIndex,
3419-
outgoingChanID: fwdInfo.NextHop,
3420-
sourceRef: pd.SourceRef,
3421-
incomingAmount: pd.Amount,
3422-
amount: addMsg.Amount,
3423-
htlc: addMsg,
3424-
obfuscator: obfuscator,
3425-
incomingTimeout: pd.Timeout,
3426-
outgoingTimeout: fwdInfo.OutgoingCTLV,
3427-
customRecords: pld.CustomRecords(),
3428-
inboundFee: inboundFee,
3429-
incomingCustomRecords: customRecords,
3395+
incomingChanID: l.ShortChanID(),
3396+
incomingHTLCID: pd.HtlcIndex,
3397+
outgoingChanID: fwdInfo.NextHop,
3398+
sourceRef: pd.SourceRef,
3399+
incomingAmount: pd.Amount,
3400+
amount: addMsg.Amount,
3401+
htlc: addMsg,
3402+
obfuscator: obfuscator,
3403+
incomingTimeout: pd.Timeout,
3404+
outgoingTimeout: fwdInfo.OutgoingCTLV,
3405+
customRecords: pld.CustomRecords(),
3406+
inboundFee: inboundFee,
3407+
incomingCustomRecords: record.CustomSet(
3408+
pd.CustomRecords,
3409+
),
34303410
}
34313411
switchPackets = append(
34323412
switchPackets, updatePacket,
@@ -3482,21 +3462,22 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
34823462
if fwdPkg.State == channeldb.FwdStateLockedIn {
34833463
inboundFee := l.cfg.FwrdingPolicy.InboundFee
34843464

3485-
//nolint:lll
34863465
updatePacket := &htlcPacket{
3487-
incomingChanID: l.ShortChanID(),
3488-
incomingHTLCID: pd.HtlcIndex,
3489-
outgoingChanID: fwdInfo.NextHop,
3490-
sourceRef: pd.SourceRef,
3491-
incomingAmount: pd.Amount,
3492-
amount: addMsg.Amount,
3493-
htlc: addMsg,
3494-
obfuscator: obfuscator,
3495-
incomingTimeout: pd.Timeout,
3496-
outgoingTimeout: fwdInfo.OutgoingCTLV,
3497-
customRecords: pld.CustomRecords(),
3498-
inboundFee: inboundFee,
3499-
incomingCustomRecords: customRecords,
3466+
incomingChanID: l.ShortChanID(),
3467+
incomingHTLCID: pd.HtlcIndex,
3468+
outgoingChanID: fwdInfo.NextHop,
3469+
sourceRef: pd.SourceRef,
3470+
incomingAmount: pd.Amount,
3471+
amount: addMsg.Amount,
3472+
htlc: addMsg,
3473+
obfuscator: obfuscator,
3474+
incomingTimeout: pd.Timeout,
3475+
outgoingTimeout: fwdInfo.OutgoingCTLV,
3476+
customRecords: pld.CustomRecords(),
3477+
inboundFee: inboundFee,
3478+
incomingCustomRecords: record.CustomSet(
3479+
pd.CustomRecords,
3480+
),
35003481
}
35013482

35023483
fwdPkg.FwdFilter.Set(idx)

0 commit comments

Comments
 (0)