record+htlcswitch: convert BlindedRouteData fields to optional
For the final hop in a blinded route, the SCID and RelayInfo fields will _not_ be set. So these fields need to be converted to optional records. The existing BlindedRouteData constructor is also renamed to `NewNonFinalBlindedRouteData` in preparation for a `NewFinalBlindedRouteData` constructor which will be used to construct the blinded data for the final hop which will contain a much smaller set of data. The SCID and RelayInfo parameters of the constructor are left as non-pointers in order to force the caller to set them in the case that the constructor is called for non-final nodes. The other option would be to create a single constructor where all parameters are optional but I think this makes it easier for the caller to make a mistake.
This commit is contained in:
6 files changed
+71
-28
No files matched your search
@@ -360,6 +360,7 @@ func (b *BlindingKit) DecryptAndValidateFwdInfo(payload *Payload,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Validate the data in the blinded route against our incoming htlc's
|
||||
// information.
|
||||
if err := ValidateBlindedRouteData(
|
||||
@@ -368,9 +369,31 @@ func (b *BlindingKit) DecryptAndValidateFwdInfo(payload *Payload,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Exit early if this onion is for the exit hop of the route since
|
||||
// route blinding receives are not yet supported.
|
||||
if isFinalHop {
|
||||
return nil, fmt.Errorf("being the final hop in a blinded " +
|
||||
"path is not yet supported")
|
||||
}
|
||||
|
||||
// At this point, we know we are a forwarding node for this onion
|
||||
// and so we expect the relay info and next SCID fields to be set.
|
||||
relayInfo, err := routeData.RelayInfo.UnwrapOrErr(
|
||||
fmt.Errorf("relay info not set for non-final blinded hop"),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
nextSCID, err := routeData.ShortChannelID.UnwrapOrErr(
|
||||
fmt.Errorf("next SCID not set for non-final blinded hop"),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fwdAmt, err := calculateForwardingAmount(
|
||||
b.IncomingAmount, routeData.RelayInfo.Val.BaseFee,
|
||||
routeData.RelayInfo.Val.FeeRate,
|
||||
b.IncomingAmount, relayInfo.Val.BaseFee, relayInfo.Val.FeeRate,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -400,10 +423,10 @@ func (b *BlindingKit) DecryptAndValidateFwdInfo(payload *Payload,
|
||||
}
|
||||
|
||||
return &ForwardingInfo{
|
||||
NextHop: routeData.ShortChannelID.Val,
|
||||
NextHop: nextSCID.Val,
|
||||
AmountToForward: fwdAmt,
|
||||
OutgoingCTLV: b.IncomingCltv - uint32(
|
||||
routeData.RelayInfo.Val.CltvExpiryDelta,
|
||||
relayInfo.Val.CltvExpiryDelta,
|
||||
),
|
||||
// Remap from blinding override type to blinding point type.
|
||||
NextBlinding: tlv.SomeRecordT(
|
||||
|
||||
Reference in new issue
Block a user