Skip to content

Commit 03dceca

Browse files
guggeroffranr
authored andcommitted
multi: add incoming htlc amount to interceptor
1 parent 8025296 commit 03dceca

File tree

7 files changed

+223
-181
lines changed

7 files changed

+223
-181
lines changed

htlcswitch/interceptable_switch.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ type FwdResolution struct {
125125
// FwdActionSettle.
126126
Preimage lntypes.Preimage
127127

128+
// IncomingAmountMsat is the amount that is to be used for validating if
129+
// Action is FwdActionResumeModified.
130+
IncomingAmountMsat fn.Option[lnwire.MilliSatoshi]
131+
128132
// OutgoingAmountMsat is the amount that is to be used for forwarding if
129133
// Action is FwdActionResumeModified.
130134
OutgoingAmountMsat fn.Option[lnwire.MilliSatoshi]
@@ -391,7 +395,8 @@ func (s *InterceptableSwitch) resolve(res *FwdResolution) error {
391395

392396
case FwdActionResumeModified:
393397
return intercepted.ResumeModified(
394-
res.OutgoingAmountMsat, res.CustomRecords,
398+
res.IncomingAmountMsat, res.OutgoingAmountMsat,
399+
res.CustomRecords,
395400
)
396401

397402
case FwdActionSettle:
@@ -638,9 +643,15 @@ func (f *interceptedForward) Resume() error {
638643

639644
// ResumeModified resumes the default behavior with field modifications.
640645
func (f *interceptedForward) ResumeModified(
646+
incomingAmountMsat fn.Option[lnwire.MilliSatoshi],
641647
outgoingAmountMsat fn.Option[lnwire.MilliSatoshi],
642648
customRecords fn.Option[record.CustomSet]) error {
643649

650+
// Set the incoming amount, if it is provided, on the packet.
651+
incomingAmountMsat.WhenSome(func(amount lnwire.MilliSatoshi) {
652+
f.packet.incomingAmount = amount
653+
})
654+
644655
// Modify the wire message contained in the packet.
645656
switch htlc := f.packet.htlc.(type) {
646657
case *lnwire.UpdateAddHTLC:

htlcswitch/interfaces.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,8 @@ type InterceptedForward interface {
378378

379379
// ResumeModified notifies the intention to resume an existing hold
380380
// forward with modified fields.
381-
ResumeModified(outgoingAmountMsat fn.Option[lnwire.MilliSatoshi],
381+
ResumeModified(incomingAmountMsat,
382+
outgoingAmountMsat fn.Option[lnwire.MilliSatoshi],
382383
customRecords fn.Option[record.CustomSet]) error
383384

384385
// Settle notifies the intention to settle an existing hold

intercepted_forward.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (f *interceptedForward) Resume() error {
5555

5656
// ResumeModified notifies the intention to resume an existing hold forward with
5757
// a modified htlc.
58-
func (f *interceptedForward) ResumeModified(_ fn.Option[lnwire.MilliSatoshi],
58+
func (f *interceptedForward) ResumeModified(_, _ fn.Option[lnwire.MilliSatoshi],
5959
_ fn.Option[record.CustomSet]) error {
6060

6161
return ErrCannotResume

lnrpc/routerrpc/forward_interceptor.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ func (r *forwardInterceptor) resolveFromClient(
123123

124124
case ResolveHoldForwardAction_RESUME_MODIFIED:
125125
// Modify HTLC and resume forward.
126+
incomingAmtMsat := fn.None[lnwire.MilliSatoshi]()
127+
if in.IncomingAmountMsat > 0 {
128+
incomingAmtMsat = fn.Some[lnwire.MilliSatoshi](
129+
lnwire.MilliSatoshi(in.IncomingAmountMsat),
130+
)
131+
}
132+
126133
outgoingAmtMsat := fn.None[lnwire.MilliSatoshi]()
127134
if in.OutgoingAmountMsat > 0 {
128135
outgoingAmtMsat = fn.Some[lnwire.MilliSatoshi](
@@ -148,6 +155,7 @@ func (r *forwardInterceptor) resolveFromClient(
148155
return r.htlcSwitch.Resolve(&htlcswitch.FwdResolution{
149156
Key: circuitKey,
150157
Action: htlcswitch.FwdActionResumeModified,
158+
IncomingAmountMsat: incomingAmtMsat,
151159
OutgoingAmountMsat: outgoingAmtMsat,
152160
CustomRecords: customRecords,
153161
})

lnrpc/routerrpc/router.pb.go

Lines changed: 189 additions & 176 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lnrpc/routerrpc/router.proto

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,13 +993,17 @@ message ForwardHtlcInterceptResponse {
993993
// default value for this field.
994994
lnrpc.Failure.FailureCode failure_code = 5;
995995

996+
// incoming_amount_msat is used to set the p2p message incoming amount field
997+
// for validating an incoming HTLC.
998+
uint64 incoming_amount_msat = 6;
999+
9961000
// outgoing_amount_msat is used to set the p2p message outgoing amount field
9971001
// for resuming a HTLC.
998-
uint64 outgoing_amount_msat = 6;
1002+
uint64 outgoing_amount_msat = 7;
9991003

10001004
// custom_records is used to set the p2p message custom records field for
10011005
// resuming a HTLC.
1002-
map<uint64, bytes> custom_records = 7;
1006+
map<uint64, bytes> custom_records = 8;
10031007
}
10041008

10051009
enum ResolveHoldForwardAction {

lnrpc/routerrpc/router.swagger.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,11 @@
13441344
"$ref": "#/definitions/FailureFailureCode",
13451345
"description": "Return the specified failure code in case the resolve action is Fail. The\nmessage data fields are populated automatically.\n\nIf a non-zero failure_code is specified, failure_message must not be set.\n\nFor backwards-compatibility reasons, TEMPORARY_CHANNEL_FAILURE is the\ndefault value for this field."
13461346
},
1347+
"incoming_amount_msat": {
1348+
"type": "string",
1349+
"format": "uint64",
1350+
"description": "incoming_amount_msat is used to set the p2p message incoming amount field\nfor validating an incoming HTLC."
1351+
},
13471352
"outgoing_amount_msat": {
13481353
"type": "string",
13491354
"format": "uint64",

0 commit comments

Comments
 (0)