Skip to content

Commit e0a9705

Browse files
authored
Merge pull request #9935 from ellemouton/graphSQL11-forEachMethods
[11] graph/db: Implement various "ForEach" methods on the graph SQLStore
2 parents 168d63c + ece157b commit e0a9705

File tree

8 files changed

+595
-34
lines changed

8 files changed

+595
-34
lines changed

docs/release-notes/release-notes-0.20.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ circuit. The indices are only available for forwarding events saved after v0.20.
7777
* [2](https://github.com/lightningnetwork/lnd/pull/9869)
7878
* [3](https://github.com/lightningnetwork/lnd/pull/9887)
7979
* [4](https://github.com/lightningnetwork/lnd/pull/9931)
80+
* [5](https://github.com/lightningnetwork/lnd/pull/9935)
8081

8182
## RPC Updates
8283

graph/db/graph_test.go

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/btcsuite/btcd/chaincfg"
2424
"github.com/btcsuite/btcd/chaincfg/chainhash"
2525
"github.com/btcsuite/btcd/wire"
26+
"github.com/lightningnetwork/lnd/fn/v2"
2627
"github.com/lightningnetwork/lnd/graph/db/models"
2728
"github.com/lightningnetwork/lnd/kvdb"
2829
"github.com/lightningnetwork/lnd/lnwire"
@@ -1366,7 +1367,7 @@ func TestGraphTraversal(t *testing.T) {
13661367
func TestGraphTraversalCacheable(t *testing.T) {
13671368
t.Parallel()
13681369

1369-
graph := MakeTestGraph(t)
1370+
graph := MakeTestGraphNew(t)
13701371

13711372
// We'd like to test some of the graph traversal capabilities within
13721373
// the DB, so we'll create a series of fake nodes to insert into the
@@ -1436,7 +1437,7 @@ func TestGraphTraversalCacheable(t *testing.T) {
14361437
func TestGraphCacheTraversal(t *testing.T) {
14371438
t.Parallel()
14381439

1439-
graph := MakeTestGraph(t)
1440+
graph := MakeTestGraphNew(t)
14401441

14411442
// We'd like to test some of the graph traversal capabilities within
14421443
// the DB, so we'll create a series of fake nodes to insert into the
@@ -2069,16 +2070,15 @@ func TestChanUpdatesInHorizon(t *testing.T) {
20692070

20702071
assertEdgeInfoEqual(t, chanExp.Info, chanRet.Info)
20712072

2072-
err := compareEdgePolicies(
2073+
err = compareEdgePolicies(
20732074
chanExp.Policy1, chanRet.Policy1,
20742075
)
2075-
if err != nil {
2076-
t.Fatal(err)
2077-
}
2078-
compareEdgePolicies(chanExp.Policy2, chanRet.Policy2)
2079-
if err != nil {
2080-
t.Fatal(err)
2081-
}
2076+
require.NoError(t, err)
2077+
2078+
err = compareEdgePolicies(
2079+
chanExp.Policy2, chanRet.Policy2,
2080+
)
2081+
require.NoError(t, err)
20822082
}
20832083
}
20842084
}
@@ -3041,7 +3041,7 @@ func TestIncompleteChannelPolicies(t *testing.T) {
30413041
t.Parallel()
30423042
ctx := context.Background()
30433043

3044-
graph := MakeTestGraph(t)
3044+
graph := MakeTestGraphNew(t)
30453045

30463046
// Create two nodes.
30473047
node1 := createTestVertex(t)
@@ -4110,7 +4110,7 @@ func TestBatchedUpdateEdgePolicy(t *testing.T) {
41104110
// BenchmarkForEachChannel is a benchmark test that measures the number of
41114111
// allocations and the total memory consumed by the full graph traversal.
41124112
func BenchmarkForEachChannel(b *testing.B) {
4113-
graph := MakeTestGraph(b)
4113+
graph := MakeTestGraphNew(b)
41144114

41154115
const numNodes = 100
41164116
const numChannels = 4
@@ -4163,7 +4163,7 @@ func TestGraphCacheForEachNodeChannel(t *testing.T) {
41634163
t.Parallel()
41644164
ctx := context.Background()
41654165

4166-
graph := MakeTestGraph(t)
4166+
graph := MakeTestGraphNew(t)
41674167

41684168
// Unset the channel graph cache to simulate the user running with the
41694169
// option turned off.
@@ -4213,21 +4213,25 @@ func TestGraphCacheForEachNodeChannel(t *testing.T) {
42134213
edge1.ExtraOpaqueData = []byte{
42144214
253, 217, 3, 8, 0, 0, 0, 10, 0, 0, 0, 20,
42154215
}
4216+
inboundFee := lnwire.Fee{
4217+
BaseFee: 10,
4218+
FeeRate: 20,
4219+
}
4220+
edge1.InboundFee = fn.Some(inboundFee)
42164221
require.NoError(t, graph.UpdateEdgePolicy(edge1))
42174222
edge1 = copyEdgePolicy(edge1) // Avoid read/write race conditions.
42184223

42194224
directedChan := getSingleChannel()
42204225
require.NotNil(t, directedChan)
4221-
expectedInbound := lnwire.Fee{
4222-
BaseFee: 10,
4223-
FeeRate: 20,
4224-
}
4225-
require.Equal(t, expectedInbound, directedChan.InboundFee)
4226+
require.Equal(t, inboundFee, directedChan.InboundFee)
42264227

42274228
// Set an invalid inbound fee and check that persistence fails.
42284229
edge1.ExtraOpaqueData = []byte{
42294230
253, 217, 3, 8, 0,
42304231
}
4232+
// We need to update the timestamp so that we don't hit the DB conflict
4233+
// error when we try to update the edge policy.
4234+
edge1.LastUpdate = edge1.LastUpdate.Add(time.Second)
42314235
require.ErrorIs(
42324236
t, graph.UpdateEdgePolicy(edge1), ErrParsingExtraTLVBytes,
42334237
)
@@ -4236,7 +4240,7 @@ func TestGraphCacheForEachNodeChannel(t *testing.T) {
42364240
// the previous result when we query the channel again.
42374241
directedChan = getSingleChannel()
42384242
require.NotNil(t, directedChan)
4239-
require.Equal(t, expectedInbound, directedChan.InboundFee)
4243+
require.Equal(t, inboundFee, directedChan.InboundFee)
42404244
}
42414245

42424246
// TestGraphLoading asserts that the cache is properly reconstructed after a

graph/db/notifications.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,11 @@ func EncodeHexColor(color color.RGBA) string {
473473
// DecodeHexColor takes a hex color string like "#rrggbb" and returns a
474474
// color.RGBA.
475475
func DecodeHexColor(hex string) (color.RGBA, error) {
476+
if len(hex) != 7 || hex[0] != '#' {
477+
return color.RGBA{}, fmt.Errorf("invalid hex color string: %s",
478+
hex)
479+
}
480+
476481
r, err := strconv.ParseUint(hex[1:3], 16, 8)
477482
if err != nil {
478483
return color.RGBA{}, fmt.Errorf("invalid red component: %w",

0 commit comments

Comments
 (0)