Commit 2a468a4
authored
core: Fix duplicate VID when multiple offchain triggers fire in the same 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 tests1 parent 629f2f7 commit 2a468a4
2 files changed
Lines changed: 128 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
810 | 810 | | |
811 | 811 | | |
812 | 812 | | |
| 813 | + | |
813 | 814 | | |
814 | | - | |
| 815 | + | |
815 | 816 | | |
816 | 817 | | |
817 | 818 | | |
| |||
1161 | 1162 | | |
1162 | 1163 | | |
1163 | 1164 | | |
| 1165 | + | |
1164 | 1166 | | |
1165 | 1167 | | |
1166 | 1168 | | |
| |||
1179 | 1181 | | |
1180 | 1182 | | |
1181 | 1183 | | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
1182 | 1189 | | |
1183 | 1190 | | |
1184 | 1191 | | |
| |||
1244 | 1251 | | |
1245 | 1252 | | |
1246 | 1253 | | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
1247 | 1258 | | |
1248 | 1259 | | |
1249 | 1260 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
366 | 366 | | |
367 | 367 | | |
368 | 368 | | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
369 | 485 | | |
370 | 486 | | |
371 | 487 | | |
| |||
0 commit comments