@@ -892,15 +892,27 @@ func TestPruneChannelGraphDoubleDisabled(t *testing.T) {
892
892
}
893
893
894
894
func testPruneChannelGraphDoubleDisabled (t * testing.T , assumeValid bool ) {
895
+ timestamp := time .Now ()
896
+
897
+ // nextTimeStamp is a helper closure that will return a new
898
+ // timestamp each time it's called, this helps us create channel updates
899
+ // with new timestamps so that we don't run into our SQL DB constraint
900
+ // which only allows an update to a channel edge if the last update
901
+ // timestamp is greater than the previous one.
902
+ nextTimeStamp := func () time.Time {
903
+ timestamp = timestamp .Add (time .Second )
904
+
905
+ return timestamp
906
+ }
907
+
895
908
// We'll create the following test graph so that only the last channel
896
909
// is pruned. We'll use a fresh timestamp to ensure they're not pruned
897
910
// according to that heuristic.
898
- timestamp := time .Now ()
899
911
testChannels := []* testChannel {
900
912
// Channel from self shouldn't be pruned.
901
913
symmetricTestChannel (
902
914
"self" , "a" , 100000 , & testChannelPolicy {
903
- LastUpdate : timestamp ,
915
+ LastUpdate : nextTimeStamp () ,
904
916
Disabled : true ,
905
917
}, 99 ,
906
918
),
@@ -918,7 +930,7 @@ func testPruneChannelGraphDoubleDisabled(t *testing.T, assumeValid bool) {
918
930
Node1 : & testChannelEnd {
919
931
Alias : "a" ,
920
932
testChannelPolicy : & testChannelPolicy {
921
- LastUpdate : timestamp ,
933
+ LastUpdate : nextTimeStamp () ,
922
934
Disabled : true ,
923
935
},
924
936
},
@@ -932,7 +944,7 @@ func testPruneChannelGraphDoubleDisabled(t *testing.T, assumeValid bool) {
932
944
Node1 : & testChannelEnd {
933
945
Alias : "a" ,
934
946
testChannelPolicy : & testChannelPolicy {
935
- LastUpdate : timestamp ,
947
+ LastUpdate : nextTimeStamp () ,
936
948
Disabled : false ,
937
949
},
938
950
},
@@ -946,14 +958,14 @@ func testPruneChannelGraphDoubleDisabled(t *testing.T, assumeValid bool) {
946
958
Node1 : & testChannelEnd {
947
959
Alias : "a" ,
948
960
testChannelPolicy : & testChannelPolicy {
949
- LastUpdate : timestamp ,
961
+ LastUpdate : nextTimeStamp () ,
950
962
Disabled : true ,
951
963
},
952
964
},
953
965
Node2 : & testChannelEnd {
954
966
Alias : "b" ,
955
967
testChannelPolicy : & testChannelPolicy {
956
- LastUpdate : timestamp ,
968
+ LastUpdate : nextTimeStamp () ,
957
969
Disabled : false ,
958
970
},
959
971
},
@@ -963,13 +975,13 @@ func testPruneChannelGraphDoubleDisabled(t *testing.T, assumeValid bool) {
963
975
964
976
// Both edges enabled.
965
977
symmetricTestChannel ("c" , "d" , 100000 , & testChannelPolicy {
966
- LastUpdate : timestamp ,
978
+ LastUpdate : nextTimeStamp () ,
967
979
Disabled : false ,
968
980
}, 2 ),
969
981
970
982
// Both edges disabled, only one pruned.
971
983
symmetricTestChannel ("e" , "f" , 100000 , & testChannelPolicy {
972
- LastUpdate : timestamp ,
984
+ LastUpdate : nextTimeStamp () ,
973
985
Disabled : true ,
974
986
}, 3 ),
975
987
}
@@ -1363,7 +1375,9 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
1363
1375
testAddrs = append (testAddrs , testAddr )
1364
1376
1365
1377
// Next, create a temporary graph database for usage within the test.
1366
- graph := graphdb .MakeTestGraph (t , graphdb .WithUseGraphCache (useCache ))
1378
+ graph := graphdb .MakeTestGraphNew (
1379
+ t , graphdb .WithUseGraphCache (useCache ),
1380
+ )
1367
1381
1368
1382
aliasMap := make (map [string ]route.Vertex )
1369
1383
privKeyMap := make (map [string ]* btcec.PrivateKey )
@@ -1441,6 +1455,13 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
1441
1455
}
1442
1456
1443
1457
source = dbNode
1458
+
1459
+ // Set the selected source node.
1460
+ if err := graph .SetSourceNode (ctx , source ); err != nil {
1461
+ return nil , err
1462
+ }
1463
+
1464
+ continue
1444
1465
}
1445
1466
1446
1467
// With the node fully parsed, add it as a vertex within the
@@ -1450,13 +1471,6 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
1450
1471
}
1451
1472
}
1452
1473
1453
- if source != nil {
1454
- // Set the selected source node
1455
- if err := graph .SetSourceNode (ctx , source ); err != nil {
1456
- return nil , err
1457
- }
1458
- }
1459
-
1460
1474
// With all the vertexes inserted, we can now insert the edges into the
1461
1475
// test graph.
1462
1476
for _ , edge := range g .Edges {
@@ -1739,14 +1753,16 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
1739
1753
testAddrs = append (testAddrs , testAddr )
1740
1754
1741
1755
// Next, create a temporary graph database for usage within the test.
1742
- graph := graphdb .MakeTestGraph (t , graphdb .WithUseGraphCache (useCache ))
1756
+ graph := graphdb .MakeTestGraphNew (
1757
+ t , graphdb .WithUseGraphCache (useCache ),
1758
+ )
1743
1759
1744
1760
aliasMap := make (map [string ]route.Vertex )
1745
1761
privKeyMap := make (map [string ]* btcec.PrivateKey )
1746
1762
1747
1763
nodeIndex := byte (0 )
1748
- addNodeWithAlias := func (alias string , features * lnwire. FeatureVector ) (
1749
- * models. LightningNode , error ) {
1764
+ addNodeWithAlias := func (alias string ,
1765
+ features * lnwire. FeatureVector ) error {
1750
1766
1751
1767
keyBytes := []byte {
1752
1768
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
@@ -1776,26 +1792,26 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
1776
1792
1777
1793
// With the node fully parsed, add it as a vertex within the
1778
1794
// graph.
1779
- if err := graph .AddLightningNode (ctx , dbNode ); err != nil {
1780
- return nil , err
1795
+ if alias == source {
1796
+ err = graph .SetSourceNode (ctx , dbNode )
1797
+ require .NoError (t , err )
1798
+ } else {
1799
+ err := graph .AddLightningNode (ctx , dbNode )
1800
+ require .NoError (t , err )
1781
1801
}
1782
1802
1783
1803
aliasMap [alias ] = dbNode .PubKeyBytes
1784
1804
nodeIndex ++
1785
1805
1786
- return dbNode , nil
1806
+ return nil
1787
1807
}
1788
1808
1789
1809
// Add the source node.
1790
- dbNode , err : = addNodeWithAlias (source , lnwire .EmptyFeatureVector ())
1810
+ err = addNodeWithAlias (source , lnwire .EmptyFeatureVector ())
1791
1811
if err != nil {
1792
1812
return nil , err
1793
1813
}
1794
1814
1795
- if err = graph .SetSourceNode (ctx , dbNode ); err != nil {
1796
- return nil , err
1797
- }
1798
-
1799
1815
// Initialize variable that keeps track of the next channel id to assign
1800
1816
// if none is specified.
1801
1817
nextUnassignedChannelID := uint64 (100000 )
@@ -1813,7 +1829,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
1813
1829
features =
1814
1830
node .testChannelPolicy .Features
1815
1831
}
1816
- _ , err := addNodeWithAlias (
1832
+ err := addNodeWithAlias (
1817
1833
node .Alias , features ,
1818
1834
)
1819
1835
if err != nil {
0 commit comments