Skip to content

fix(txcommon): dedupe blockchain events within a batch - #1783

Open
EnriqueL8 wants to merge 3 commits into
mainfrom
fix/blockchain-event-batch-dedup
Open

EnriqueL8 wants to merge 3 commits into
mainfrom
fix/blockchain-event-batch-dedup

Conversation

@EnriqueL8

Copy link
Copy Markdown
Contributor

Proposed changes

When the blockchain connector delivers the same on-chain log twice within one batch, FireFly emits two blockchain_event_received events with the same reference, pointing at the same blockchain_events row.

InsertNewBlockchainEvents' insert-or-get fallback queries the events table to decide whether a duplicate blockchain_events row still needs a notification, but that query only sees events committed in previous batches — the FF events for earlier entries of the current batch are inserted later, in maybePersistBlockchainEvents. So the second entry falls through the "partial success" branch and both end up in inserted.

Symptom observed:

DEBUG connector: Detected event 000012345/000000/000000/B=0xbeef…/L=00000000-1111-2222-3333-444444444444
DEBUG connector: Detected event 000012345/000000/000000/B=0xbeef…/L=00000000-1111-2222-3333-444444444444
WARN  txcommon: Blockchain event insert-many optimization failed: FF00195: PK violation
DEBUG events:   Emitting blockchain_event_received reference=99999999-eeee-4fff-aaaa-deadbeef0000
DEBUG events:   Emitting blockchain_event_received reference=99999999-eeee-4fff-aaaa-deadbeef0000

Originally thought about adding a new set with IDs to be O(1) but batches are small so we can iterate over the array

Types of changes

  • Bug fix
  • New feature added
  • Documentation Update

Please make sure to follow these points

  • I have read the contributing guidelines.
  • I have performed a self-review of my own code or work.
  • I have commented my code, particularly in hard-to-understand areas.
  • My changes generates no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • My changes have sufficient code coverage (unit, integration, e2e tests).

Signed-off-by: Enrique Lacal <enrique.lacal@kaleido.io>
@EnriqueL8
EnriqueL8 requested a review from a team as a code owner September 15, 2026 16:52
@codecov

codecov Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
internal/txcommon/txcommon.go 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
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.

1 participant