Skip to content

Commit 243f2a0

Browse files
committed
misc: more lint fix
1 parent 7772fe3 commit 243f2a0

File tree

4 files changed

+79
-21
lines changed

4 files changed

+79
-21
lines changed

channeldb/graph.go

+20-13
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func (c *ChannelGraph) populateGraphCache() {
295295
c.graphCacheReady.Store(true)
296296
}
297297

298-
func (c *ChannelGraph) getGraphCache() (*GraphCache, error) {
298+
func (c *ChannelGraph) GetGraphCache() (*GraphCache, error) {
299299
if c.graphCache == nil {
300300
return nil, nil
301301
}
@@ -526,7 +526,7 @@ func (c *ChannelGraph) ForEachChannel(cb func(*models.ChannelEdgeInfo,
526526
func (c *ChannelGraph) ForEachNodeDirectedChannel(tx kvdb.RTx,
527527
node route.Vertex, cb func(channel *DirectedChannel) error) error {
528528

529-
graphCache, err := c.getGraphCache()
529+
graphCache, err := c.GetGraphCache()
530530
if err == nil && graphCache != nil {
531531
return graphCache.ForEachChannel(node, cb)
532532
}
@@ -584,7 +584,7 @@ func (c *ChannelGraph) ForEachNodeDirectedChannel(tx kvdb.RTx,
584584
func (c *ChannelGraph) FetchNodeFeatures(
585585
node route.Vertex) (*lnwire.FeatureVector, error) {
586586

587-
graphCache, err := c.getGraphCache()
587+
graphCache, err := c.GetGraphCache()
588588
if err == nil && graphCache != nil {
589589
return graphCache.GetFeatures(node), nil
590590
}
@@ -615,7 +615,7 @@ func (c *ChannelGraph) FetchNodeFeatures(
615615
func (c *ChannelGraph) ForEachNodeCached(cb func(node route.Vertex,
616616
chans map[uint64]*DirectedChannel) error) error {
617617

618-
graphCache, err := c.getGraphCache()
618+
graphCache, err := c.GetGraphCache()
619619
if err == nil && graphCache != nil {
620620
return graphCache.ForEachNode(cb)
621621
}
@@ -895,7 +895,7 @@ func (c *ChannelGraph) AddLightningNode(node *LightningNode,
895895

896896
r := &batch.Request{
897897
Update: func(tx kvdb.RwTx) error {
898-
graphCache, err := c.getGraphCache()
898+
graphCache, err := c.GetGraphCache()
899899
if err != nil {
900900
if errors.Is(err, ErrGraphCacheNotReady) {
901901
// Queue this update function
@@ -1001,7 +1001,7 @@ func (c *ChannelGraph) DeleteLightningNode(nodePub route.Vertex) error {
10011001
return ErrGraphNodeNotFound
10021002
}
10031003

1004-
graphCache, err := c.getGraphCache()
1004+
graphCache, err := c.GetGraphCache()
10051005
if err != nil {
10061006
if errors.Is(err, ErrGraphCacheNotReady) {
10071007
// Queue this delete function
@@ -1146,7 +1146,7 @@ func (c *ChannelGraph) addChannelEdge(tx kvdb.RwTx,
11461146
return ErrEdgeAlreadyExist
11471147
}
11481148

1149-
graphCache, err := c.getGraphCache()
1149+
graphCache, err := c.GetGraphCache()
11501150
if err != nil {
11511151
if errors.Is(err, ErrGraphCacheNotReady) {
11521152
// Queue this function
@@ -1363,7 +1363,7 @@ func (c *ChannelGraph) UpdateChannelEdge(edge *models.ChannelEdgeInfo) error {
13631363
return ErrEdgeNotFound
13641364
}
13651365

1366-
graphCache, err := c.getGraphCache()
1366+
graphCache, err := c.GetGraphCache()
13671367
if err != nil {
13681368
if errors.Is(err, ErrGraphCacheNotReady) {
13691369
// Queue this update function
@@ -1612,7 +1612,7 @@ func (c *ChannelGraph) pruneGraphNodes(nodes kvdb.RwBucket,
16121612
return err
16131613
}
16141614

1615-
graphCache, err := c.getGraphCache()
1615+
graphCache, err := c.GetGraphCache()
16161616
if err != nil {
16171617
if errors.Is(err, ErrGraphCacheNotReady) {
16181618
// Queue this prune operation
@@ -2668,7 +2668,7 @@ func (c *ChannelGraph) delChannelEdgeUnsafe(edges, edgeIndex, chanIndex,
26682668
return err
26692669
}
26702670

2671-
graphCache, err := c.getGraphCache()
2671+
graphCache, err := c.GetGraphCache()
26722672
if err != nil {
26732673
if errors.Is(err, ErrGraphCacheNotReady) {
26742674
// Queue this delete function
@@ -2683,8 +2683,10 @@ func (c *ChannelGraph) delChannelEdgeUnsafe(edges, edgeIndex, chanIndex,
26832683
strictZombie,
26842684
)
26852685
})
2686+
26862687
return nil
26872688
}
2689+
26882690
return err
26892691
}
26902692

@@ -2945,16 +2947,18 @@ func updateEdgePolicy(tx kvdb.RwTx, edge *models.ChannelEdgePolicy,
29452947
copy(fromNodePubKey[:], fromNode)
29462948
copy(toNodePubKey[:], toNode)
29472949

2948-
graphCache, err := c.getGraphCache()
2950+
graphCache, err := c.GetGraphCache()
29492951
if err != nil {
29502952
if errors.Is(err, ErrGraphCacheNotReady) {
29512953
// Queue this update function
29522954
c.enqueueWriteOperation(func() error {
29532955
_, err := updateEdgePolicy(tx, edge, c)
29542956
return err
29552957
})
2958+
29562959
return false, nil
29572960
}
2961+
29582962
return false, err
29592963
}
29602964

@@ -3838,7 +3842,7 @@ func (c *ChannelGraph) MarkEdgeZombie(chanID uint64,
38383842
"bucket: %w", err)
38393843
}
38403844

3841-
graphCache, err := c.getGraphCache()
3845+
graphCache, err := c.GetGraphCache()
38423846
if err != nil {
38433847
if errors.Is(err, ErrGraphCacheNotReady) {
38443848
// Queue this function
@@ -3849,8 +3853,10 @@ func (c *ChannelGraph) MarkEdgeZombie(chanID uint64,
38493853
pubKey2,
38503854
)
38513855
})
3856+
38523857
return nil
38533858
}
3859+
38543860
return err
38553861
}
38563862

@@ -3938,13 +3944,14 @@ func (c *ChannelGraph) markEdgeLiveUnsafe(tx kvdb.RwTx, chanID uint64) error {
39383944

39393945
// We need to add the channel back into our graph cache, otherwise we
39403946
// won't use it for path finding.
3941-
graphCache, err := c.getGraphCache()
3947+
graphCache, err := c.GetGraphCache()
39423948
if err != nil {
39433949
if errors.Is(err, ErrGraphCacheNotReady) {
39443950
// Queue the operation to add the channel back.
39453951
c.enqueueWriteOperation(func() error {
39463952
return c.markEdgeLiveUnsafe(tx, chanID)
39473953
})
3954+
39483955
return nil
39493956
}
39503957
return err

channeldb/graph_test.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ func MakeTestGraph(t testing.TB, modifiers ...OptionModifier) (*ChannelGraph, er
8282
backendCleanup()
8383
})
8484

85+
// Wait for graph cache to be up and running.
86+
_ = waitForGraphCache(graph, 5*time.Second)
87+
8588
return graph, nil
8689
}
8790

@@ -3997,8 +4000,10 @@ func waitForGraphCache(graph *ChannelGraph, timeout time.Duration) error {
39974000
return fmt.Errorf("timed out waiting for graphCache " +
39984001
"to be ready")
39994002
case <-ticker.C:
4000-
if graphCache, err := graph.getGraphCache(); err != nil {
4001-
return fmt.Errorf("error getting graphCache: %v", err)
4003+
graphCache, err := graph.GetGraphCache()
4004+
if err != nil {
4005+
return fmt.Errorf("error getting graphCache: "+
4006+
"%v", err)
40024007
} else if graphCache != nil {
40034008
return nil
40044009
}
@@ -4027,10 +4032,6 @@ func TestGraphLoading(t *testing.T) {
40274032
)
40284033
require.NoError(t, err)
40294034

4030-
waitForGraphCache(graph, 5*time.Second)
4031-
_, err = graph.getGraphCache()
4032-
require.NoError(t, err)
4033-
40344035
// Populate the graph with test data.
40354036
const numNodes = 100
40364037
const numChannels = 4
@@ -4045,8 +4046,8 @@ func TestGraphLoading(t *testing.T) {
40454046
)
40464047
require.NoError(t, err)
40474048

4048-
waitForGraphCache(graphReloaded, 5*time.Second)
4049-
_, err = graphReloaded.getGraphCache()
4049+
_ = waitForGraphCache(graphReloaded, 5*time.Second)
4050+
_, err = graphReloaded.GetGraphCache()
40504051
require.NoError(t, err)
40514052

40524053
// Assert that the cache content is identical.

graph/notifications_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,28 @@ func (c *testCtx) RestartBuilder(t *testing.T) {
10861086
c.builder = builder
10871087
}
10881088

1089+
func waitForGraphCache(g *channeldb.ChannelGraph, timeout time.Duration) error {
1090+
ticker := time.NewTicker(100 * time.Millisecond)
1091+
defer ticker.Stop()
1092+
1093+
timeoutChan := time.After(timeout)
1094+
for {
1095+
select {
1096+
case <-timeoutChan:
1097+
return fmt.Errorf("timed out waiting for graphCache " +
1098+
"to be ready")
1099+
case <-ticker.C:
1100+
graphCache, err := g.GetGraphCache()
1101+
if err != nil {
1102+
return fmt.Errorf("error getting graphCache: "+
1103+
"%v", err)
1104+
} else if graphCache != nil {
1105+
return nil
1106+
}
1107+
}
1108+
}
1109+
}
1110+
10891111
// makeTestGraph creates a new instance of a channeldb.ChannelGraph for testing
10901112
// purposes.
10911113
func makeTestGraph(t *testing.T, useCache bool) (*channeldb.ChannelGraph,
@@ -1109,6 +1131,9 @@ func makeTestGraph(t *testing.T, useCache bool) (*channeldb.ChannelGraph,
11091131
return nil, nil, err
11101132
}
11111133

1134+
// Wait for graph cache to be up and running.
1135+
_ = waitForGraphCache(graph, 5*time.Second)
1136+
11121137
return graph, backend, nil
11131138
}
11141139

routing/pathfind_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,34 @@ func makeTestGraph(t *testing.T, useCache bool) (*channeldb.ChannelGraph,
175175
return nil, nil, err
176176
}
177177

178+
// Wait for graph cache to be up and running.
179+
_ = waitForGraphCache(graph, 5*time.Second)
180+
178181
return graph, backend, nil
179182
}
180183

184+
func waitForGraphCache(g *channeldb.ChannelGraph, timeout time.Duration) error {
185+
ticker := time.NewTicker(100 * time.Millisecond)
186+
defer ticker.Stop()
187+
188+
timeoutChan := time.After(timeout)
189+
for {
190+
select {
191+
case <-timeoutChan:
192+
return fmt.Errorf("timed out waiting for graphCache " +
193+
"to be ready")
194+
case <-ticker.C:
195+
graphCache, err := g.GetGraphCache()
196+
if err != nil {
197+
return fmt.Errorf("error getting graphCache: "+
198+
"%v", err)
199+
} else if graphCache != nil {
200+
return nil
201+
}
202+
}
203+
}
204+
}
205+
181206
// parseTestGraph returns a fully populated ChannelGraph given a path to a JSON
182207
// file which encodes a test graph.
183208
func parseTestGraph(t *testing.T, useCache bool, path string) (

0 commit comments

Comments
 (0)