Skip to content

Commit 398623b

Browse files
committed
blindedpath: move blinded path logic to own pkg
1 parent c62a9c2 commit 398623b

File tree

11 files changed

+1959
-1874
lines changed

11 files changed

+1959
-1874
lines changed

config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,8 @@ func DefaultConfig() Config {
680680
},
681681
Invoices: &lncfg.Invoices{
682682
HoldExpiryDelta: lncfg.DefaultHoldInvoiceExpiryDelta,
683+
},
684+
Routing: &lncfg.Routing{
683685
BlindedPaths: lncfg.BlindedPaths{
684686
MinNumRealHops: lncfg.DefaultMinNumRealBlindedPathHops,
685687
NumHops: lncfg.DefaultNumBlindedPathHops,
@@ -1686,6 +1688,7 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
16861688
cfg.Sweeper,
16871689
cfg.Htlcswitch,
16881690
cfg.Invoices,
1691+
cfg.Routing,
16891692
)
16901693
if err != nil {
16911694
return nil, err

itest/lnd_route_blinding_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ func (b *blindedForwardTest) setupNetwork(ctx context.Context,
367367
// Bob to himself.
368368
b.dave = b.ht.NewNode("Dave", []string{
369369
"--bitcoin.timelockdelta=18",
370-
"--invoices.blinding.min-num-real-hops=2",
371-
"--invoices.blinding.num-hops=2",
370+
"--routing.blinding.min-num-real-hops=2",
371+
"--routing.blinding.num-hops=2",
372372
})
373373

374374
b.channels = setupFourHopNetwork(b.ht, b.carol, b.dave)
@@ -625,8 +625,8 @@ func testBlindedRouteInvoices(ht *lntest.HarnessTest) {
625625
// Restart Dave with blinded path restrictions that will result in him
626626
// creating a blinded path that uses himself as the introduction node.
627627
ht.RestartNodeWithExtraArgs(testCase.dave, []string{
628-
"--invoices.blinding.min-num-real-hops=0",
629-
"--invoices.blinding.num-hops=0",
628+
"--routing.blinding.min-num-real-hops=0",
629+
"--routing.blinding.num-hops=0",
630630
})
631631
ht.EnsureConnected(testCase.dave, testCase.carol)
632632

@@ -901,8 +901,8 @@ func testMPPToSingleBlindedPath(ht *lntest.HarnessTest) {
901901
// Restrict Dave so that he only ever chooses the Carol->Dave path for
902902
// a blinded route.
903903
dave := ht.NewNode("dave", []string{
904-
"--invoices.blinding.min-num-real-hops=1",
905-
"--invoices.blinding.num-hops=1",
904+
"--routing.blinding.min-num-real-hops=1",
905+
"--routing.blinding.num-hops=1",
906906
})
907907
carol := ht.NewNode("carol", nil)
908908
eve := ht.NewNode("eve", nil)
@@ -1098,8 +1098,8 @@ func testBlindedRouteDummyHops(ht *lntest.HarnessTest) {
10981098
// Configure Dave so that all blinded paths always contain 2 hops and
10991099
// so that there is no minimum number of real hops.
11001100
dave := ht.NewNode("dave", []string{
1101-
"--invoices.blinding.min-num-real-hops=0",
1102-
"--invoices.blinding.num-hops=2",
1101+
"--routing.blinding.min-num-real-hops=0",
1102+
"--routing.blinding.num-hops=2",
11031103
})
11041104

11051105
ht.EnsureConnected(alice, bob)
@@ -1183,8 +1183,8 @@ func testBlindedRouteDummyHops(ht *lntest.HarnessTest) {
11831183
// of hops to 2 meaning that one dummy hop should be added.
11841184
ht.RestartNodeWithExtraArgs(carol, nil)
11851185
ht.RestartNodeWithExtraArgs(dave, []string{
1186-
"--invoices.blinding.min-num-real-hops=1",
1187-
"--invoices.blinding.num-hops=2",
1186+
"--routing.blinding.min-num-real-hops=1",
1187+
"--routing.blinding.num-hops=2",
11881188
})
11891189
ht.EnsureConnected(bob, carol)
11901190
ht.EnsureConnected(carol, dave)

lncfg/invoices.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package lncfg
22

3-
import "fmt"
4-
53
const (
64
// DefaultHoldInvoiceExpiryDelta defines the number of blocks before the
75
// expiry height of a hold invoice's htlc that lnd will automatically
@@ -41,20 +39,6 @@ const (
4139
//nolint:lll
4240
type Invoices struct {
4341
HoldExpiryDelta uint32 `long:"holdexpirydelta" description:"The number of blocks before a hold invoice's htlc expires that the invoice should be canceled to prevent a force close. Force closes will not be prevented if this value is not greater than DefaultIncomingBroadcastDelta."`
44-
45-
BlindedPaths BlindedPaths `group:"blinding" namespace:"blinding"`
46-
}
47-
48-
// BlindedPaths holds the configuration options for blinded paths added to
49-
// invoices.
50-
//
51-
//nolint:lll
52-
type BlindedPaths struct {
53-
MinNumRealHops uint8 `long:"min-num-real-hops" description:"The minimum number of real hops to include in a blinded path. This doesn't include our node, so if the minimum is 1, then the path will contain at minimum our node along with an introduction node hop. If it is zero then the shortest path will use our node as an introduction node."`
54-
NumHops uint8 `long:"num-hops" description:"The number of hops to include in a blinded path. This doesn't include our node, so if it is 1, then the path will contain our node along with an introduction node or dummy node hop. If paths shorter than NumHops is found, then they will be padded using dummy hops."`
55-
MaxNumPaths uint8 `long:"max-num-paths" description:"The maximum number of blinded paths to select and add to an invoice."`
56-
PolicyIncreaseMultiplier float64 `long:"policy-increase-multiplier" description:"The amount by which to increase certain policy values of hops on a blinded path in order to add a probing buffer."`
57-
PolicyDecreaseMultiplier float64 `long:"policy-decrease-multiplier" description:"The amount by which to decrease certain policy values of hops on a blinded path in order to add a probing buffer."`
5842
}
5943

6044
// Validate checks that the various invoice config options are sane.
@@ -72,23 +56,5 @@ func (i *Invoices) Validate() error {
7256
i.HoldExpiryDelta, DefaultIncomingBroadcastDelta)
7357
}
7458

75-
if i.BlindedPaths.MinNumRealHops > i.BlindedPaths.NumHops {
76-
return fmt.Errorf("the minimum number of real hops in a " +
77-
"blinded path must be smaller than or equal to the " +
78-
"number of hops expected to be included in each path")
79-
}
80-
81-
if i.BlindedPaths.PolicyIncreaseMultiplier < 1 {
82-
return fmt.Errorf("the blinded route policy increase " +
83-
"multiplier must be greater than or equal to 1")
84-
}
85-
86-
if i.BlindedPaths.PolicyDecreaseMultiplier > 1 ||
87-
i.BlindedPaths.PolicyDecreaseMultiplier < 0 {
88-
89-
return fmt.Errorf("the blinded route policy decrease " +
90-
"multiplier must be in the range (0,1]")
91-
}
92-
9359
return nil
9460
}

lncfg/routing.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,50 @@
11
package lncfg
22

3+
import "fmt"
4+
35
// Routing holds the configuration options for routing.
46
//
57
//nolint:lll
68
type Routing struct {
79
AssumeChannelValid bool `long:"assumechanvalid" description:"DEPRECATED: Skip checking channel spentness during graph validation. This speedup comes at the risk of using an unvalidated view of the network for routing. (default: false)" hidden:"true"`
810

911
StrictZombiePruning bool `long:"strictgraphpruning" description:"If true, then the graph will be pruned more aggressively for zombies. In practice this means that edges with a single stale edge will be considered a zombie."`
12+
13+
BlindedPaths BlindedPaths `group:"blinding" namespace:"blinding"`
14+
}
15+
16+
// BlindedPaths holds the configuration options for blinded path construction.
17+
//
18+
//nolint:lll
19+
type BlindedPaths struct {
20+
MinNumRealHops uint8 `long:"min-num-real-hops" description:"The minimum number of real hops to include in a blinded path. This doesn't include our node, so if the minimum is 1, then the path will contain at minimum our node along with an introduction node hop. If it is zero then the shortest path will use our node as an introduction node."`
21+
NumHops uint8 `long:"num-hops" description:"The number of hops to include in a blinded path. This doesn't include our node, so if it is 1, then the path will contain our node along with an introduction node or dummy node hop. If paths shorter than NumHops is found, then they will be padded using dummy hops."`
22+
MaxNumPaths uint8 `long:"max-num-paths" description:"The maximum number of blinded paths to select and add to an invoice."`
23+
PolicyIncreaseMultiplier float64 `long:"policy-increase-multiplier" description:"The amount by which to increase certain policy values of hops on a blinded path in order to add a probing buffer."`
24+
PolicyDecreaseMultiplier float64 `long:"policy-decrease-multiplier" description:"The amount by which to decrease certain policy values of hops on a blinded path in order to add a probing buffer."`
25+
}
26+
27+
// Validate checks that the various routing config options are sane.
28+
//
29+
// NOTE: this is part of the Validator interface.
30+
func (r *Routing) Validate() error {
31+
if r.BlindedPaths.MinNumRealHops > r.BlindedPaths.NumHops {
32+
return fmt.Errorf("the minimum number of real hops in a " +
33+
"blinded path must be smaller than or equal to the " +
34+
"number of hops expected to be included in each path")
35+
}
36+
37+
if r.BlindedPaths.PolicyIncreaseMultiplier < 1 {
38+
return fmt.Errorf("the blinded route policy increase " +
39+
"multiplier must be greater than or equal to 1")
40+
}
41+
42+
if r.BlindedPaths.PolicyDecreaseMultiplier > 1 ||
43+
r.BlindedPaths.PolicyDecreaseMultiplier < 0 {
44+
45+
return fmt.Errorf("the blinded route policy decrease " +
46+
"multiplier must be in the range (0,1]")
47+
}
48+
49+
return nil
1050
}

0 commit comments

Comments
 (0)