Skip to content

Commit ca91e17

Browse files
committed
invoicesrpc: move blinded path config to AddInvoiceData
since `AddInvoiceData` is config _per invoice_ where as `AddInvoiceConfig` is config for the invoice server itself and so pretty much should stay the same for the lifetime of LND. This change sets us up for moving some of the blinded path config options to be changeable per AddInvoice call rather that having fixed config values in the config file.
1 parent e47160d commit ca91e17

File tree

2 files changed

+74
-52
lines changed

2 files changed

+74
-52
lines changed

lnrpc/invoicesrpc/addinvoice.go

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -96,28 +96,6 @@ type AddInvoiceConfig struct {
9696
// QueryBlindedRoutes can be used to generate a few routes to this node
9797
// that can then be used in the construction of a blinded payment path.
9898
QueryBlindedRoutes func(lnwire.MilliSatoshi) ([]*route.Route, error)
99-
100-
// BlindedRoutePolicyIncrMultiplier is the amount by which policy values
101-
// for hops in a blinded route will be bumped to avoid easy probing. For
102-
// example, a multiplier of 1.1 will bump all appropriate the values
103-
// (base fee, fee rate, CLTV delta and min HLTC) by 10%.
104-
BlindedRoutePolicyIncrMultiplier float64
105-
106-
// BlindedRoutePolicyDecrMultiplier is the amount by which appropriate
107-
// policy values for hops in a blinded route will be decreased to avoid
108-
// easy probing. For example, a multiplier of 0.9 will reduce
109-
// appropriate values (like maximum HTLC) by 10%.
110-
BlindedRoutePolicyDecrMultiplier float64
111-
112-
// MinNumBlindedPathHops is the minimum number of hops that a blinded
113-
// path should be. Dummy hops will be used to pad any route with a
114-
// length less than this.
115-
MinNumBlindedPathHops uint8
116-
117-
// DefaultDummyHopPolicy holds the default policy values to use for
118-
// dummy hops in a blinded path in the case where they cant be derived
119-
// through other means.
120-
DefaultDummyHopPolicy *blindedpath.BlindedHopPolicy
12199
}
122100

123101
// AddInvoiceData contains the required data to create a new invoice.
@@ -168,16 +146,44 @@ type AddInvoiceData struct {
168146
// NOTE: Preimage should always be set to nil when this value is true.
169147
Amp bool
170148

171-
// Blind signals that this invoice should disguise the location of the
172-
// recipient by adding blinded payment paths to the invoice instead of
173-
// revealing the destination node's real pub key.
174-
Blind bool
149+
// BlindedPathCfg holds the config values to use when constructing
150+
// blinded paths to add to the invoice. A non-nil BlindedPathCfg signals
151+
// that this invoice should disguise the location of the recipient by
152+
// adding blinded payment paths to the invoice instead of revealing the
153+
// destination node's real pub key.
154+
BlindedPathCfg *BlindedPathConfig
175155

176156
// RouteHints are optional route hints that can each be individually
177157
// used to assist in reaching the invoice's destination.
178158
RouteHints [][]zpay32.HopHint
179159
}
180160

161+
// BlindedPathConfig holds the configuration values required for blinded path
162+
// generation for invoices.
163+
type BlindedPathConfig struct {
164+
// RoutePolicyIncrMultiplier is the amount by which policy values for
165+
// hops in a blinded route will be bumped to avoid easy probing. For
166+
// example, a multiplier of 1.1 will bump all appropriate the values
167+
// (base fee, fee rate, CLTV delta and min HLTC) by 10%.
168+
RoutePolicyIncrMultiplier float64
169+
170+
// RoutePolicyDecrMultiplier is the amount by which appropriate policy
171+
// values for hops in a blinded route will be decreased to avoid easy
172+
// probing. For example, a multiplier of 0.9 will reduce appropriate
173+
// values (like maximum HTLC) by 10%.
174+
RoutePolicyDecrMultiplier float64
175+
176+
// MinNumPathHops is the minimum number of hops that a blinded path
177+
// should be. Dummy hops will be used to pad any route with a length
178+
// less than this.
179+
MinNumPathHops uint8
180+
181+
// DefaultDummyHopPolicy holds the default policy values to use for
182+
// dummy hops in a blinded path in the case where they cant be derived
183+
// through other means.
184+
DefaultDummyHopPolicy *blindedpath.BlindedHopPolicy
185+
}
186+
181187
// paymentHashAndPreimage returns the payment hash and preimage for this invoice
182188
// depending on the configuration.
183189
//
@@ -277,7 +283,9 @@ func (d *AddInvoiceData) mppPaymentHashAndPreimage() (*lntypes.Preimage,
277283
func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
278284
invoice *AddInvoiceData) (*lntypes.Hash, *invoices.Invoice, error) {
279285

280-
if invoice.Amp && invoice.Blind {
286+
blind := invoice.BlindedPathCfg != nil
287+
288+
if invoice.Amp && blind {
281289
return nil, nil, fmt.Errorf("AMP invoices with blinded paths " +
282290
"are not yet supported")
283291
}
@@ -420,7 +428,7 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
420428
// Only include a final CLTV expiry delta if this is not a blinded
421429
// invoice. In a blinded invoice, this value will be added to the total
422430
// blinded route CLTV delta value
423-
if !invoice.Blind {
431+
if !blind {
424432
options = append(options, zpay32.CLTVExpiry(cltvExpiryDelta))
425433
}
426434

@@ -433,7 +441,7 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
433441

434442
// Include route hints if needed.
435443
if len(invoice.RouteHints) > 0 || invoice.Private {
436-
if invoice.Blind {
444+
if blind {
437445
return nil, nil, fmt.Errorf("can't set both hop " +
438446
"hints and add blinded payment paths")
439447
}
@@ -492,7 +500,9 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
492500
return nil, nil, err
493501
}
494502

495-
if invoice.Blind {
503+
if blind {
504+
blindCfg := invoice.BlindedPathCfg
505+
496506
// Use the 10-min-per-block assumption to get a rough estimate
497507
// of the number of blocks until the invoice expires. We want
498508
// to make sure that the blinded path definitely does not expire
@@ -525,12 +535,12 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
525535

526536
//nolint:lll
527537
return blindedpath.AddPolicyBuffer(
528-
p, cfg.BlindedRoutePolicyIncrMultiplier,
529-
cfg.BlindedRoutePolicyDecrMultiplier,
538+
p, blindCfg.RoutePolicyIncrMultiplier,
539+
blindCfg.RoutePolicyDecrMultiplier,
530540
)
531541
},
532-
MinNumHops: cfg.MinNumBlindedPathHops,
533-
DefaultDummyHopPolicy: cfg.DefaultDummyHopPolicy,
542+
MinNumHops: blindCfg.MinNumPathHops,
543+
DefaultDummyHopPolicy: blindCfg.DefaultDummyHopPolicy,
534544
},
535545
)
536546
if err != nil {
@@ -560,7 +570,7 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
560570
// For an invoice without a blinded path, the main node
561571
// key is used to sign the invoice so that the sender
562572
// can derive the true pub key of the recipient.
563-
if !invoice.Blind {
573+
if !blind {
564574
return cfg.NodeSigner.SignMessageCompact(
565575
msg, false,
566576
)

rpcserver.go

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5820,10 +5820,6 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
58205820
},
58215821
GetAlias: r.server.aliasMgr.GetPeerAlias,
58225822
BestHeight: r.server.cc.BestBlockTracker.BestHeight,
5823-
BlindedRoutePolicyIncrMultiplier: r.server.cfg.Routing.
5824-
BlindedPaths.PolicyIncreaseMultiplier,
5825-
BlindedRoutePolicyDecrMultiplier: r.server.cfg.Routing.
5826-
BlindedPaths.PolicyDecreaseMultiplier,
58275823
QueryBlindedRoutes: func(amt lnwire.MilliSatoshi) (
58285824
[]*route.Route, error) {
58295825

@@ -5833,18 +5829,6 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
58335829
blindingRestrictions,
58345830
)
58355831
},
5836-
MinNumBlindedPathHops: r.server.cfg.Routing.BlindedPaths.
5837-
NumHops,
5838-
DefaultDummyHopPolicy: &blindedpath.BlindedHopPolicy{
5839-
CLTVExpiryDelta: uint16(defaultDelta),
5840-
FeeRate: uint32(r.server.cfg.Bitcoin.FeeRate),
5841-
BaseFee: r.server.cfg.Bitcoin.BaseFee,
5842-
MinHTLCMsat: r.server.cfg.Bitcoin.MinHTLCIn,
5843-
5844-
// MaxHTLCMsat will be calculated on the fly by using
5845-
// the introduction node's channel's capacities.
5846-
MaxHTLCMsat: 0,
5847-
},
58485832
}
58495833

58505834
value, err := lnrpc.UnmarshallAmt(invoice.Value, invoice.ValueMsat)
@@ -5857,6 +5841,34 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
58575841
if err != nil {
58585842
return nil, err
58595843
}
5844+
5845+
var blindedPathCfg *invoicesrpc.BlindedPathConfig
5846+
if invoice.Blind {
5847+
bpConfig := r.server.cfg.Routing.BlindedPaths
5848+
5849+
blindedPathCfg = &invoicesrpc.BlindedPathConfig{
5850+
RoutePolicyIncrMultiplier: bpConfig.
5851+
PolicyIncreaseMultiplier,
5852+
RoutePolicyDecrMultiplier: bpConfig.
5853+
PolicyDecreaseMultiplier,
5854+
DefaultDummyHopPolicy: &blindedpath.BlindedHopPolicy{
5855+
CLTVExpiryDelta: uint16(defaultDelta),
5856+
FeeRate: uint32(
5857+
r.server.cfg.Bitcoin.FeeRate,
5858+
),
5859+
BaseFee: r.server.cfg.Bitcoin.BaseFee,
5860+
MinHTLCMsat: r.server.cfg.Bitcoin.MinHTLCIn,
5861+
5862+
// MaxHTLCMsat will be calculated on the fly by
5863+
// using the introduction node's channel's
5864+
// capacities.
5865+
MaxHTLCMsat: 0,
5866+
},
5867+
MinNumPathHops: r.server.cfg.Routing.BlindedPaths.
5868+
NumHops,
5869+
}
5870+
}
5871+
58605872
addInvoiceData := &invoicesrpc.AddInvoiceData{
58615873
Memo: invoice.Memo,
58625874
Value: value,
@@ -5867,7 +5879,7 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
58675879
Private: invoice.Private,
58685880
RouteHints: routeHints,
58695881
Amp: invoice.IsAmp,
5870-
Blind: invoice.Blind,
5882+
BlindedPathCfg: blindedPathCfg,
58715883
}
58725884

58735885
if invoice.RPreimage != nil {

0 commit comments

Comments
 (0)