Skip to content

Commit bd5de43

Browse files
committed
routerrpc: extend HTLC forward interceptor resp with modification fields
This commit extends the forward HTLC intercept response with fields that can be used in conjunction with a `ResumeModified` action to modify the intercepted HTLC p2p message.
1 parent 31ee274 commit bd5de43

File tree

4 files changed

+336
-230
lines changed

4 files changed

+336
-230
lines changed

lnrpc/routerrpc/forward_interceptor.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import (
44
"errors"
55

66
"github.com/lightningnetwork/lnd/channeldb/models"
7+
"github.com/lightningnetwork/lnd/fn"
78
"github.com/lightningnetwork/lnd/htlcswitch"
89
"github.com/lightningnetwork/lnd/lnrpc"
910
"github.com/lightningnetwork/lnd/lntypes"
1011
"github.com/lightningnetwork/lnd/lnwire"
12+
"github.com/lightningnetwork/lnd/record"
1113
"google.golang.org/grpc/codes"
1214
"google.golang.org/grpc/status"
1315
)
@@ -119,6 +121,37 @@ func (r *forwardInterceptor) resolveFromClient(
119121
Action: htlcswitch.FwdActionResume,
120122
})
121123

124+
case ResolveHoldForwardAction_RESUME_MODIFIED:
125+
// Modify HTLC and resume forward.
126+
outgoingAmtMsat := fn.None[lnwire.MilliSatoshi]()
127+
if in.OutgoingAmountMsat > 0 {
128+
outgoingAmtMsat = fn.Some[lnwire.MilliSatoshi](
129+
lnwire.MilliSatoshi(in.OutgoingAmountMsat),
130+
)
131+
}
132+
133+
customRecords := fn.None[record.CustomSet]()
134+
if len(in.CustomRecords) > 0 {
135+
// Validate custom records.
136+
cr := record.CustomSet(in.CustomRecords)
137+
if err := cr.Validate(); err != nil {
138+
return status.Errorf(
139+
codes.InvalidArgument,
140+
"failed to validate custom records: %v",
141+
err,
142+
)
143+
}
144+
145+
customRecords = fn.Some[record.CustomSet](cr)
146+
}
147+
148+
return r.htlcSwitch.Resolve(&htlcswitch.FwdResolution{
149+
Key: circuitKey,
150+
Action: htlcswitch.FwdActionResumeModified,
151+
OutgoingAmountMsat: outgoingAmtMsat,
152+
CustomRecords: customRecords,
153+
})
154+
122155
case ResolveHoldForwardAction_FAIL:
123156
// Fail with an encrypted reason.
124157
if in.FailureMessage != nil {

0 commit comments

Comments
 (0)