From eb67757a0732bd346e7d7dde5da83256bdb58f55 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Mon, 6 Oct 2025 11:34:53 +0200 Subject: [PATCH] graph/db: gracefully handle duplicate channel policy announcements --- graph/db/graph_test.go | 7 +++++++ graph/db/sql_store.go | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go index 08fa36f4e..ee5cf8dbf 100644 --- a/graph/db/graph_test.go +++ b/graph/db/graph_test.go @@ -944,6 +944,13 @@ func TestEdgePolicyCRUD(t *testing.T) { require.NoError(t, graph.UpdateEdgePolicy(ctx, edge1)) require.NoError(t, graph.UpdateEdgePolicy(ctx, edge2)) + // Even though we assert at the DB level that any newer edge + // update has a newer timestamp, we need to still gracefully + // handle the case where the same exact policy is re-added since + // it could be possible that our batch executor has two of the + // same policy updates in the same batch. + require.NoError(t, graph.UpdateEdgePolicy(ctx, edge1)) + // Use the ForEachChannel method to fetch the policies and // assert that the deserialized policies match the original // ones. diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go index a942405eb..f67894e4c 100644 --- a/graph/db/sql_store.go +++ b/graph/db/sql_store.go @@ -780,7 +780,15 @@ func (s *SQLStore) UpdateEdgePolicy(ctx context.Context, from, to, isUpdate1, err = updateChanEdgePolicy( ctx, tx, edge, ) - if err != nil { + // It is possible that two of the same policy + // announcements are both being processed in the same + // batch. This may case the UpsertEdgePolicy conflict to + // be hit since we require at the db layer that the + // new last_update is greater than the existing + // last_update. We need to gracefully handle this here. + if errors.Is(err, sql.ErrNoRows) { + return nil + } else if err != nil { log.Errorf("UpdateEdgePolicy faild: %v", err) }