Skip to content

Backport some issues with offchain vids#6417

Open
lutter wants to merge 2 commits intokrishna/cherry-pick-anynetworkbarefrom
lutter/vid-collision
Open

Backport some issues with offchain vids#6417
lutter wants to merge 2 commits intokrishna/cherry-pick-anynetworkbarefrom
lutter/vid-collision

Conversation

@lutter
Copy link
Collaborator

@lutter lutter commented Mar 4, 2026

No description provided.

hudsonhrh and others added 2 commits March 3, 2026 15:46
…ame block (#6336)

* fix: thread vid_seq across offchain triggers to prevent duplicate VIDs

When specVersion >= 1.3.0, VIDs are computed deterministically as
(block_number << 32) + vid_seq. Each offchain trigger in
handle_offchain_triggers creates a fresh EntityCache with vid_seq
reset to RESERVED_VIDS (100). When multiple file data source triggers
fire in the same block and write to the same entity table, they
produce identical VIDs, causing PostgreSQL primary key violations:

  "duplicate key value violates unique constraint task_metadata_pkey"

Fix: Pass the onchain EntityCache's final vid_seq into
handle_offchain_triggers and accumulate it across loop iterations,
so each offchain trigger continues the sequence from where the
previous one left off.

* test: add unit tests proving VID collision bug in offchain triggers

Two tests demonstrate the bug where multiple offchain triggers (e.g. file
data sources) in the same block each create a fresh EntityCache with
vid_seq reset to RESERVED_VIDS (100), producing duplicate VIDs that
violate the primary key constraint.

- offchain_trigger_vid_collision_without_fix: proves VIDs collide
- offchain_trigger_vid_no_collision_with_fix: proves threading vid_seq
  across triggers prevents collisions

* refactor: improve comment clarity in vid_seq threading

* test-store: Fix rustfmt style in entity_cache tests
Each ipfs.map() callback created a fresh BlockState with vid_seq reset
to RESERVED_VIDS. When multiple callbacks write to the same entity
table, they all generate vids starting at (block<<32)+100, producing
duplicates.

Fix by threading vid_seq through the callback loop and updating it in
EntityCache::extend() so the parent handler also continues from the
right sequence after merging callback results.
@lutter lutter requested a review from incrypto32 March 4, 2026 01:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants