Skip to content

Commit 87aed73

Browse files
authored
Merge pull request #10269 from ellemouton/microSampleConf
2 parents 1c2ff4a + eb67757 commit 87aed73

File tree

5 files changed

+38
-3
lines changed

5 files changed

+38
-3
lines changed

graph/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ func (b *Builder) IsStaleNode(ctx context.Context, node route.Vertex,
13131313
// then we know that this is actually a stale announcement.
13141314
err := b.assertNodeAnnFreshness(ctx, node, timestamp)
13151315
if err != nil {
1316-
log.Debugf("Checking stale node %x got %v", node, err)
1316+
log.Debugf("Checking stale node %s got %v", node, err)
13171317
return true
13181318
}
13191319

graph/db/graph_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
125125
require.NoError(t, graph.AddNode(ctx, node))
126126
assertNodeInCache(t, graph, node, testFeatures)
127127

128+
// Our AddNode implementation uses the batcher meaning that it is
129+
// possible that two updates for the same node announcement may be
130+
// processed in the same batch. So to avoid the conflict error (since we
131+
// require at the DB level that the new timestamp is strictly
132+
// greater than the previous one), we need to gracefully handle the
133+
// case where the exact same node announcement is added twice.
134+
require.NoError(t, graph.AddNode(ctx, node))
135+
128136
// Next, fetch the node from the database to ensure everything was
129137
// serialized properly.
130138
dbNode, err := graph.FetchNode(ctx, testPub)
@@ -936,6 +944,13 @@ func TestEdgePolicyCRUD(t *testing.T) {
936944
require.NoError(t, graph.UpdateEdgePolicy(ctx, edge1))
937945
require.NoError(t, graph.UpdateEdgePolicy(ctx, edge2))
938946

947+
// Even though we assert at the DB level that any newer edge
948+
// update has a newer timestamp, we need to still gracefully
949+
// handle the case where the same exact policy is re-added since
950+
// it could be possible that our batch executor has two of the
951+
// same policy updates in the same batch.
952+
require.NoError(t, graph.UpdateEdgePolicy(ctx, edge1))
953+
939954
// Use the ForEachChannel method to fetch the policies and
940955
// assert that the deserialized policies match the original
941956
// ones.

graph/db/sql_store.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ func (s *SQLStore) AddNode(ctx context.Context,
255255
Opts: batch.NewSchedulerOptions(opts...),
256256
Do: func(queries SQLQueries) error {
257257
_, err := upsertNode(ctx, queries, node)
258+
259+
// It is possible that two of the same node
260+
// announcements are both being processed in the same
261+
// batch. This may case the UpsertNode conflict to
262+
// be hit since we require at the db layer that the
263+
// new last_update is greater than the existing
264+
// last_update. We need to gracefully handle this here.
265+
if errors.Is(err, sql.ErrNoRows) {
266+
return nil
267+
}
268+
258269
return err
259270
},
260271
}
@@ -769,7 +780,15 @@ func (s *SQLStore) UpdateEdgePolicy(ctx context.Context,
769780
from, to, isUpdate1, err = updateChanEdgePolicy(
770781
ctx, tx, edge,
771782
)
772-
if err != nil {
783+
// It is possible that two of the same policy
784+
// announcements are both being processed in the same
785+
// batch. This may case the UpsertEdgePolicy conflict to
786+
// be hit since we require at the db layer that the
787+
// new last_update is greater than the existing
788+
// last_update. We need to gracefully handle this here.
789+
if errors.Is(err, sql.ErrNoRows) {
790+
return nil
791+
} else if err != nil {
773792
log.Errorf("UpdateEdgePolicy faild: %v", err)
774793
}
775794

lncfg/db.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ type DB struct {
8686

8787
Sqlite *sqldb.SqliteConfig `group:"sqlite" namespace:"sqlite" description:"Sqlite settings."`
8888

89-
UseNativeSQL bool `long:"use-native-sql" description:"If set to true, native SQL will be used instead of KV emulation for tables that support it. Subsystems which support native SQL tables: Invoices."`
89+
UseNativeSQL bool `long:"use-native-sql" description:"If set to true, native SQL will be used instead of KV emulation for tables that support it. Subsystems which support native SQL tables: Invoices, Graph."`
9090

9191
SkipNativeSQLMigration bool `long:"skip-native-sql-migration" description:"If set to true, the KV to native SQL migration will be skipped. Note that this option is intended for users who experience non-resolvable migration errors. Enabling after there is a non-resolvable migration error that resulted in an incomplete migration will cause that partial migration to be abandoned and ignored and an empty database will be used instead. Since invoices are currently the only native SQL database used, our channels will still work but the invoice history will be forgotten. This option has no effect if native SQL is not in use (db.use-native-sql=false)."`
9292

sample-lnd.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,7 @@
15061506
; that support it.
15071507
; Subsystems which support native SQL tables:
15081508
; - Invoices
1509+
; - Graph
15091510
; db.use-native-sql=false
15101511

15111512
; If set to true, the KV to native SQL migration will be skipped. Note that

0 commit comments

Comments
 (0)