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.
This commit is contained in:
ffranr
2024-04-13 11:42:20 +01:00
committed by Oliver Gugger
parent abca4b8234
commit fb14d8c96e
7 changed files with 436 additions and 271 deletions

View File

@@ -128,6 +128,10 @@ type FwdResolution struct {
// FwdActionSettle.
Preimage lntypes.Preimage
// InAmountMsat is the amount that is to be used for validating if
// Action is FwdActionResumeModified.
InAmountMsat fn.Option[lnwire.MilliSatoshi]
// OutAmountMsat is the amount that is to be used for forwarding if
// Action is FwdActionResumeModified.
OutAmountMsat fn.Option[lnwire.MilliSatoshi]
@@ -414,7 +418,8 @@ func (s *InterceptableSwitch) resolve(res *FwdResolution) error {
case FwdActionResumeModified:
return intercepted.ResumeModified(
res.OutAmountMsat, res.OutWireCustomRecords,
res.InAmountMsat, res.OutAmountMsat,
res.OutWireCustomRecords,
)
case FwdActionSettle:
@@ -665,6 +670,7 @@ func (f *interceptedForward) Resume() error {
// validation. The presence of an output amount and/or custom records indicates
// that those values should be modified on the outgoing HTLC.
func (f *interceptedForward) ResumeModified(
inAmountMsat fn.Option[lnwire.MilliSatoshi],
outAmountMsat fn.Option[lnwire.MilliSatoshi],
outWireCustomRecords fn.Option[lnwire.CustomRecords]) error {
@@ -694,6 +700,11 @@ func (f *interceptedForward) ResumeModified(
err)
}
// Set the incoming amount, if it is provided, on the packet.
inAmountMsat.WhenSome(func(amount lnwire.MilliSatoshi) {
f.packet.incomingAmount = amount
})
// Modify the wire message contained in the packet.
switch htlc := f.packet.htlc.(type) {
case *lnwire.UpdateAddHTLC:

View File

@@ -385,8 +385,9 @@ type InterceptedForward interface {
// ResumeModified notifies the intention to resume an existing hold
// forward with modified fields.
ResumeModified(outgoingAmountMsat fn.Option[lnwire.MilliSatoshi],
customRecords fn.Option[lnwire.CustomRecords]) error
ResumeModified(inAmountMsat,
outAmountMsat fn.Option[lnwire.MilliSatoshi],
outWireCustomRecords fn.Option[lnwire.CustomRecords]) error
// Settle notifies the intention to settle an existing hold
// forward with a given preimage.