Skip to content

Fix duplicate off-chain vote metadata child rows (#1966)#2137

Open
ArturWieczorek wants to merge 3 commits into
masterfrom
1966-offchain-vote-duplicate-rows
Open

Fix duplicate off-chain vote metadata child rows (#1966)#2137
ArturWieczorek wants to merge 3 commits into
masterfrom
1966-offchain-vote-duplicate-rows

Conversation

@ArturWieczorek

Copy link
Copy Markdown
Contributor

Re-processing the off-chain metadata of an already-stored voting anchor duplicated its child rows (off_chain_vote_drep_data, off_chain_vote_author, off_chain_vote_reference, off_chain_vote_external_update, off_chain_vote_gov_action_data). The parent insert used ON CONFLICT DO UPDATE ... RETURNING id, so a re-fetch returned the existing id, and the children - which have no uniqueness and were plain-inserted - were written again.

Make insertion idempotent: insertBulkOffChainVoteDataReturningNew uses ON CONFLICT DO NOTHING RETURNING (voting_anchor_id, hash, id) so only newly inserted parents come back, and the orchestration inserts child rows only for those, matched by natural key. Adds a WithResultBulkColumns result mode for a custom RETURNING column list. Prevents new duplicates; existing rows on synced DBs are unaffected.

Adds a regression test (cardano-db test-db) asserting a re-fetch creates no duplicate child rows.

Description

Add your description here, if it fixes a particular issue please provide a link to the issue.

Checklist

  • Commit sequence broadly makes sense
  • Commits have useful messages
  • New tests are added if needed and existing tests are updated
  • Any changes are noted in the changelog
  • Code is formatted with fourmolu on version 0.17.0.0 (which can be run with scripts/fourmolize.sh)
  • Self-reviewed the diff

Migrations

  • The pr causes a breaking change of type a,b or c
  • If there is a breaking change, the pr includes a database migration and/or a fix process for old values, so that upgrade is possible
  • Resyncing and running the migrations provided will result in the same database semantically

If there is a breaking change, especially a big one, please add a justification here. Please elaborate
more what the migration achieves, what it cannot achieve or why a migration is not possible.

Re-processing the off-chain metadata of an already-stored voting anchor
duplicated its child rows (off_chain_vote_drep_data, off_chain_vote_author,
off_chain_vote_reference, off_chain_vote_external_update,
off_chain_vote_gov_action_data). The parent insert used ON CONFLICT DO
UPDATE ... RETURNING id, so a re-fetch returned the existing id, and the
children - which have no uniqueness and were plain-inserted - were written
again.

Make insertion idempotent: insertBulkOffChainVoteDataReturningNew uses ON
CONFLICT DO NOTHING RETURNING (voting_anchor_id, hash, id) so only newly
inserted parents come back, and the orchestration inserts child rows only
for those, matched by natural key. Adds a WithResultBulkColumns result mode
for a custom RETURNING column list. Prevents new duplicates; existing rows
on synced DBs are unaffected.

Adds a regression test (cardano-db test-db) asserting a re-fetch creates no
duplicate child rows.
@ArturWieczorek ArturWieczorek force-pushed the 1966-offchain-vote-duplicate-rows branch from b5ab32b to 256e4fd Compare June 8, 2026 22:25
@kderme kderme added this to DBSync Jun 10, 2026
@ArturWieczorek

Copy link
Copy Markdown
Contributor Author

@ArturWieczorek ArturWieczorek marked this pull request as ready for review June 15, 2026 20:29
@ArturWieczorek ArturWieczorek requested a review from a team as a code owner June 15, 2026 20:29
Comment thread cardano-db-sync/src/Cardano/DbSync/OffChain.hs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants