Skip to content

Commit d0ac5af

Browse files
authored
Merge pull request #10256 from ziggie1984/small-wire-custom-data-cleanup
Clarify Wire Custom Record data
2 parents 30decfc + 49f76c1 commit d0ac5af

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

itest/lnd_forward_interceptor_test.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package itest
22

33
import (
4-
"bytes"
54
"fmt"
65
"reflect"
76
"strings"
@@ -15,7 +14,6 @@ import (
1514
"github.com/lightningnetwork/lnd/lntest/node"
1615
"github.com/lightningnetwork/lnd/lntest/wait"
1716
"github.com/lightningnetwork/lnd/lntypes"
18-
"github.com/lightningnetwork/lnd/lnwire"
1917
"github.com/lightningnetwork/lnd/routing/route"
2018
"github.com/stretchr/testify/require"
2119
"google.golang.org/grpc/codes"
@@ -477,17 +475,9 @@ func testForwardInterceptorRestart(ht *lntest.HarnessTest) {
477475
rt.FirstHopAmountMsat)
478476
}
479477

480-
cr := lnwire.CustomRecords(p.FirstHopCustomRecords)
481-
recordData, err := cr.Serialize()
482-
if err != nil {
483-
return err
484-
}
485-
486-
if !bytes.Equal(rt.CustomChannelData, recordData) {
487-
return fmt.Errorf("expected custom records to "+
488-
"be equal, got %x expected %x",
489-
rt.CustomChannelData, recordData)
490-
}
478+
// Make sure the custom channel data is nil because
479+
// this is not a custom channel payment.
480+
require.Nil(ht, rt.CustomChannelData)
491481

492482
return nil
493483
},

lnrpc/routerrpc/router_backend.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package routerrpc
22

33
import (
4+
"bytes"
45
"context"
56
"crypto/rand"
67
"encoding/hex"
@@ -622,10 +623,26 @@ func (r *RouterBackend) MarshallRoute(route *route.Route) (*lnrpc.Route, error)
622623
// Allow the aux data parser to parse the custom records into
623624
// a human-readable JSON (if available).
624625
if r.ParseCustomChannelData != nil {
626+
// Store the original custom data to check if parsing
627+
// changed it.
628+
originalCustomData := make([]byte, len(customData))
629+
copy(originalCustomData, customData)
630+
625631
err := r.ParseCustomChannelData(resp)
626632
if err != nil {
627633
return nil, err
628634
}
635+
636+
// We make sure we only set this field if the parser
637+
// changed the data otherwise we might mistakenly
638+
// show other tlv custom wire data as custom channel
639+
// data.
640+
if bytes.Equal(
641+
originalCustomData, resp.CustomChannelData,
642+
) {
643+
644+
resp.CustomChannelData = nil
645+
}
629646
}
630647
}
631648

payments/db/payment.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ type PaymentCreationInfo struct {
9090

9191
// FirstHopCustomRecords are the TLV records that are to be sent to the
9292
// first hop of this payment. These records will be transmitted via the
93-
// wire message only and therefore do not affect the onion payload size.
93+
// wire message (UpdateAddHTLC) only and therefore do not affect the
94+
// onion payload size.
9495
FirstHopCustomRecords lnwire.CustomRecords
9596
}
9697

routing/route/route.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,10 @@ type Route struct {
524524
]
525525

526526
// FirstHopWireCustomRecords is a set of custom records that should be
527-
// included in the wire message sent to the first hop. This is only set
528-
// on custom channels and is used to include additional information
529-
// about the actual value of the payment.
527+
// included in the wire message sent to the first hop. This is for
528+
// example used in custom channels. Besides custom channels we use it
529+
// also for the endorsement bit. This data will be sent to the first
530+
// hop in the UpdateAddHTLC message.
530531
//
531532
// NOTE: Since these records already represent TLV records, and we
532533
// enforce them to be in the custom range (e.g. >= 65536), we don't use

0 commit comments

Comments
 (0)