graph/db: gracefully handle duplicate channel policy announcements
This commit is contained in:
2 files changed
+16
-1
No files matched your search
@@ -944,6 +944,13 @@ func TestEdgePolicyCRUD(t *testing.T) {
|
|||||||
require.NoError(t, graph.UpdateEdgePolicy(ctx, edge1))
|
require.NoError(t, graph.UpdateEdgePolicy(ctx, edge1))
|
||||||
require.NoError(t, graph.UpdateEdgePolicy(ctx, edge2))
|
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
|
// Use the ForEachChannel method to fetch the policies and
|
||||||
// assert that the deserialized policies match the original
|
// assert that the deserialized policies match the original
|
||||||
// ones.
|
// ones.
|
||||||
|
|||||||
@@ -780,7 +780,15 @@ func (s *SQLStore) UpdateEdgePolicy(ctx context.Context,
|
|||||||
from, to, isUpdate1, err = updateChanEdgePolicy(
|
from, to, isUpdate1, err = updateChanEdgePolicy(
|
||||||
ctx, tx, edge,
|
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)
|
log.Errorf("UpdateEdgePolicy faild: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user