Skip to content

Commit 2903505

Browse files
committed
htlcswitch: expose custom records on intercepted packet
1 parent 363142d commit 2903505

9 files changed

+216
-165
lines changed

Diff for: htlcswitch/interceptable_switch.go

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func (f *interceptedForward) Packet() InterceptedPacket {
127127
OutgoingAmount: f.htlc.Amount,
128128
IncomingAmount: f.packet.incomingAmount,
129129
IncomingExpiry: f.packet.incomingTimeout,
130+
CustomRecords: f.packet.customRecords,
130131
}
131132
}
132133

Diff for: htlcswitch/interfaces.go

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/lightningnetwork/lnd/lntypes"
99
"github.com/lightningnetwork/lnd/lnwallet"
1010
"github.com/lightningnetwork/lnd/lnwire"
11+
"github.com/lightningnetwork/lnd/record"
1112
)
1213

1314
// InvoiceDatabase is an interface which represents the persistent subsystem
@@ -226,6 +227,10 @@ type InterceptedPacket struct {
226227

227228
// IncomingAmount is the amount of the accepted htlc.
228229
IncomingAmount lnwire.MilliSatoshi
230+
231+
// CustomRecords are user-defined records in the custom type range that
232+
// were included in the payload.
233+
CustomRecords record.CustomSet
229234
}
230235

231236
// InterceptedForward is passed to the ForwardInterceptor for every forwarded

Diff for: htlcswitch/link.go

+2
Original file line numberDiff line numberDiff line change
@@ -2731,6 +2731,7 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
27312731
obfuscator: obfuscator,
27322732
incomingTimeout: pd.Timeout,
27332733
outgoingTimeout: fwdInfo.OutgoingCTLV,
2734+
customRecords: pld.CustomRecords(),
27342735
}
27352736
switchPackets = append(
27362737
switchPackets, updatePacket,
@@ -2794,6 +2795,7 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
27942795
obfuscator: obfuscator,
27952796
incomingTimeout: pd.Timeout,
27962797
outgoingTimeout: fwdInfo.OutgoingCTLV,
2798+
customRecords: pld.CustomRecords(),
27972799
}
27982800

27992801
fwdPkg.FwdFilter.Set(idx)

Diff for: htlcswitch/packet.go

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/lightningnetwork/lnd/channeldb"
55
"github.com/lightningnetwork/lnd/htlcswitch/hop"
66
"github.com/lightningnetwork/lnd/lnwire"
7+
"github.com/lightningnetwork/lnd/record"
78
)
89

910
// htlcPacket is a wrapper around htlc lnwire update, which adds additional
@@ -91,6 +92,10 @@ type htlcPacket struct {
9192
// will be extraced from the hop payload recevived by the incoming
9293
// link.
9394
outgoingTimeout uint32
95+
96+
// customRecords are user-defined records in the custom type range that
97+
// were included in the payload.
98+
customRecords record.CustomSet
9499
}
95100

96101
// inKey returns the circuit key used to identify the incoming htlc.

Diff for: lnrpc/routerrpc/forward_interceptor.go

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ func (r *forwardInterceptor) holdAndForwardToClient(
163163
OutgoingExpiry: htlc.OutgoingExpiry,
164164
IncomingAmountMsat: uint64(htlc.IncomingAmount),
165165
IncomingExpiry: htlc.IncomingExpiry,
166+
CustomRecords: htlc.CustomRecords,
166167
}
167168

168169
return r.stream.Send(interceptionRequest)

Diff for: lnrpc/routerrpc/router.pb.go

+177-165
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: lnrpc/routerrpc/router.proto

+3
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,9 @@ message ForwardHtlcInterceptRequest {
628628

629629
// The outgoing htlc expiry.
630630
uint32 outgoing_expiry = 4;
631+
632+
// Any custom records that were present in the payload.
633+
map<uint64, bytes> custom_records = 8;
631634
}
632635

633636
/**

Diff for: lnrpc/routerrpc/router.swagger.json

+8
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,14 @@
936936
"type": "integer",
937937
"format": "int64",
938938
"description": "The outgoing htlc expiry."
939+
},
940+
"custom_records": {
941+
"type": "object",
942+
"additionalProperties": {
943+
"type": "string",
944+
"format": "byte"
945+
},
946+
"description": "Any custom records that were present in the payload."
939947
}
940948
}
941949
},

Diff for: lntest/itest/lnd_forward_interceptor_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import (
2121
"google.golang.org/grpc/status"
2222
)
2323

24+
var (
25+
customTestKey uint64 = 394829
26+
customTestValue = []byte{1, 3, 5}
27+
)
28+
2429
type interceptorTestCase struct {
2530
amountMsat int64
2631
invoice *lnrpc.Invoice
@@ -149,6 +154,10 @@ func testForwardInterceptor(net *lntest.NetworkHarness, t *harnessTest) {
149154
request.IncomingAmountMsat,
150155
)
151156

157+
value, ok := request.CustomRecords[customTestKey]
158+
require.True(t.t, ok, "expected custom record")
159+
require.Equal(t.t, customTestValue, value)
160+
152161
testCase := testCases[i]
153162

154163
// For held packets we ignore, keeping them in hold status.
@@ -369,6 +378,11 @@ func (c *interceptorTestContext) sendAliceToCarolPayment(ctx context.Context,
369378
Route: route,
370379
}
371380

381+
// Send a custom record to the forwarding node.
382+
route.Hops[0].CustomRecords = map[uint64][]byte{
383+
customTestKey: customTestValue,
384+
}
385+
372386
// Send the payment.
373387
return c.alice.RouterClient.SendToRouteV2(ctx, sendReq)
374388
}

0 commit comments

Comments
 (0)