mulit: don't set customData on the lnrpc route level

We now make sure we only set the custom channel data in the
lnrpc.Route only if it contains relevant data.
This commit is contained in:
ziggie authored and yyforyongyu committed 2025-11-12 22:54:03 +08:00
1 parent f35c295bd8
commit cbfc0e0dc2
4 files changed
+26 -17

No files matched your search

+3 -13
View File
@@ -1,7 +1,6 @@
package itest package itest
import ( import (
"bytes"
"fmt" "fmt"
"reflect" "reflect"
"strings" "strings"
@@ -15,7 +14,6 @@ import (
"github.com/lightningnetwork/lnd/lntest/node" "github.com/lightningnetwork/lnd/lntest/node"
"github.com/lightningnetwork/lnd/lntest/wait" "github.com/lightningnetwork/lnd/lntest/wait"
"github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing/route" "github.com/lightningnetwork/lnd/routing/route"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
@@ -477,17 +475,9 @@ func testForwardInterceptorRestart(ht *lntest.HarnessTest) {
rt.FirstHopAmountMsat) rt.FirstHopAmountMsat)
} }
cr := lnwire.CustomRecords(p.FirstHopCustomRecords) // Make sure the custom channel data is nil because
recordData, err := cr.Serialize() // this is not a custom channel payment.
if err != nil { require.Nil(ht, rt.CustomChannelData)
return err
}
if !bytes.Equal(rt.CustomChannelData, recordData) {
return fmt.Errorf("expected custom records to "+
"be equal, got %x expected %x",
rt.CustomChannelData, recordData)
}
return nil return nil
}, },
+17
View File
@@ -1,6 +1,7 @@
package routerrpc package routerrpc
import ( import (
"bytes"
"context" "context"
"crypto/rand" "crypto/rand"
"encoding/hex" "encoding/hex"
@@ -622,10 +623,26 @@ func (r *RouterBackend) MarshallRoute(route *route.Route) (*lnrpc.Route, error)
// Allow the aux data parser to parse the custom records into // Allow the aux data parser to parse the custom records into
// a human-readable JSON (if available). // a human-readable JSON (if available).
if r.ParseCustomChannelData != nil { if r.ParseCustomChannelData != nil {
// Store the original custom data to check if parsing
// changed it.
originalCustomData := make([]byte, len(customData))
copy(originalCustomData, customData)
err := r.ParseCustomChannelData(resp) err := r.ParseCustomChannelData(resp)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// We make sure we only set this field if the parser
// changed the data otherwise we might mistakenly
// show other tlv custom wire data as custom channel
// data.
if bytes.Equal(
originalCustomData, resp.CustomChannelData,
) {
resp.CustomChannelData = nil
}
} }
} }
+2 -1
View File
@@ -90,7 +90,8 @@ type PaymentCreationInfo struct {
// FirstHopCustomRecords are the TLV records that are to be sent to the // FirstHopCustomRecords are the TLV records that are to be sent to the
// first hop of this payment. These records will be transmitted via the // first hop of this payment. These records will be transmitted via the
// wire message only and therefore do not affect the onion payload size. // wire message (UpdateAddHTLC) only and therefore do not affect the
// onion payload size.
FirstHopCustomRecords lnwire.CustomRecords FirstHopCustomRecords lnwire.CustomRecords
} }
+4 -3
View File
@@ -524,9 +524,10 @@ type Route struct {
] ]
// FirstHopWireCustomRecords is a set of custom records that should be // FirstHopWireCustomRecords is a set of custom records that should be
// included in the wire message sent to the first hop. This is only set // included in the wire message sent to the first hop. This is for
// on custom channels and is used to include additional information // example used in custom channels. Besides custom channels we use it
// about the actual value of the payment. // also for the endorsement bit. This data will be sent to the first
// hop in the UpdateAddHTLC message.
// //
// NOTE: Since these records already represent TLV records, and we // NOTE: Since these records already represent TLV records, and we
// enforce them to be in the custom range (e.g. >= 65536), we don't use // enforce them to be in the custom range (e.g. >= 65536), we don't use