Skip to content

Commit eb67757

Browse files
committed
graph/db: gracefully handle duplicate channel policy announcements
1 parent abb9654 commit eb67757

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

graph/db/graph_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,13 @@ func TestEdgePolicyCRUD(t *testing.T) {
944944
require.NoError(t, graph.UpdateEdgePolicy(ctx, edge1))
945945
require.NoError(t, graph.UpdateEdgePolicy(ctx, edge2))
946946

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+
947954
// Use the ForEachChannel method to fetch the policies and
948955
// assert that the deserialized policies match the original
949956
// ones.

graph/db/sql_store.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,15 @@ func (s *SQLStore) UpdateEdgePolicy(ctx context.Context,
780780
from, to, isUpdate1, err = updateChanEdgePolicy(
781781
ctx, tx, edge,
782782
)
783-
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 {
784792
log.Errorf("UpdateEdgePolicy faild: %v", err)
785793
}
786794

0 commit comments

Comments
 (0)