graph/db: gracefully handle duplicate channel policy announcements

This commit is contained in:
Elle Mouton committed 2025-10-06 11:37:39 +02:00
1 parent abb9654856
commit eb67757a07
2 files changed
+16 -1

No files matched your search

+7
View File
@@ -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.
+9 -1
View File
@@ -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)
}