Skip to content

feat(kms-connector): event listening via eth_getLogs#2166

Merged
mergify[bot] merged 12 commits intomainfrom
eudelins/feat/1189/event-listening-via-get-logs
Mar 26, 2026
Merged

feat(kms-connector): event listening via eth_getLogs#2166
mergify[bot] merged 12 commits intomainfrom
eudelins/feat/1189/event-listening-via-get-logs

Conversation

@eudelins-zama
Copy link
Copy Markdown
Contributor

@eudelins-zama eudelins-zama commented Mar 24, 2026

Description of changes

Replaces the per-event-type subscription model (eth_newFilter + eth_getFilterChanges) with a simpler, batched eth_getLogs polling approach. This improves reliability (no more stale server-side filters).

Closes https://github.com/zama-ai/fhevm-internal/issues/1189

Core architecture change

  • Before: One async task per EventType (7 total), each creating a server-side filter via eth_newFilter and polling events via eth_getFilterChanges. A separate catchup phase was using eth_getFilterLogs to recover missed events on startup.
  • After: Two polling tasks (Decryption and KmsGeneration), each running a run_poll_loop that calls eth_getLogs with explicit fromBlock/toBlock ranges. The catchup phase is "merged" with the core listening phase.

Key changes

  • Batched DB insertion: Events from a single eth_getLogs response are published in one DB transaction (publish_batch), replacing individual publish_event calls.
    • The batch size is configurable.
    • When more blocks remain, ticker.reset_immediately() triggers the next poll without waiting.
  • Error handling: New max_consecutive_polling_errors config (default 20) stops the listener after repeated failures instead of failing on the first error.
    • Errors reset on any successful poll.
    • Replaces the previous mechanism which was crashing the listener when the filter was dropped by the RPC node.
    • This change is open to debate ofc.
  • Metric rename: event_received_errorsevent_listening_errors, now labeled by contract instead of event_type.
  • Default decryption polling: Changed from 1s to 500ms.

@eudelins-zama eudelins-zama self-assigned this Mar 24, 2026
@cla-bot cla-bot bot added the cla-signed label Mar 24, 2026
@eudelins-zama

This comment was marked as outdated.

@eudelins-zama eudelins-zama marked this pull request as ready for review March 24, 2026 16:43
@eudelins-zama eudelins-zama requested review from a team and dartdart26 as code owners March 24, 2026 16:43
@eudelins-zama

This comment was marked as outdated.

@claude

This comment was marked as outdated.

claude[bot]

This comment was marked as outdated.

@claude

This comment was marked as outdated.

@eudelins-zama eudelins-zama force-pushed the eudelins/feat/1189/event-listening-via-get-logs branch from 7290ed6 to 28d6226 Compare March 25, 2026 08:13
@eudelins-zama

This comment was marked as outdated.

@claude

This comment was marked as outdated.

@eudelins-zama

This comment was marked as outdated.

@claude

This comment was marked as outdated.

This comment was marked as outdated.

@eudelins-zama eudelins-zama marked this pull request as draft March 25, 2026 09:08

This comment was marked as outdated.

@eudelins-zama eudelins-zama force-pushed the eudelins/feat/1189/event-listening-via-get-logs branch from ecfe9e7 to 92ab2b9 Compare March 26, 2026 13:13
Copy link
Copy Markdown
Contributor

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Contributor

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (this time for reals!)

@eudelins-zama
Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify
Copy link
Copy Markdown

mergify bot commented Mar 26, 2026

Merge Queue Status

  • 🟠 Waiting for queue conditions
  • ⏳ Enter queue
  • ⏳ Run checks
  • ⏳ Merge
Required conditions to enter a queue
  • -closed [📌 queue requirement]
  • -conflict [📌 queue requirement]
  • -draft [📌 queue requirement]
  • any of [📌 queue -> configuration change requirements]:
    • -mergify-configuration-changed
    • check-success = Configuration changed
  • any of [🔀 queue conditions]:
    • all of [📌 queue conditions of queue rule main]:
      • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
      • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
      • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
      • base = main
      • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
      • label!=do-not-merge
      • any of [🛡 GitHub branch protection]:
        • check-success = common-pull-request/lint (bpr)
        • check-neutral = common-pull-request/lint (bpr)
        • check-skipped = common-pull-request/lint (bpr)
      • any of [🛡 GitHub branch protection]:
        • check-skipped = coprocessor-cargo-test/cargo-tests (bpr)
        • check-neutral = coprocessor-cargo-test/cargo-tests (bpr)
        • check-success = coprocessor-cargo-test/cargo-tests (bpr)
      • any of [🛡 GitHub branch protection]:
        • check-skipped = coprocessor-dependency-analysis/dependencies-check (bpr)
        • check-neutral = coprocessor-dependency-analysis/dependencies-check (bpr)
        • check-success = coprocessor-dependency-analysis/dependencies-check (bpr)
      • any of [🛡 GitHub branch protection]:
        • check-skipped = gateway-contracts-deployment-tests/sc-deploy (bpr)
        • check-neutral = gateway-contracts-deployment-tests/sc-deploy (bpr)
        • check-success = gateway-contracts-deployment-tests/sc-deploy (bpr)
      • any of [🛡 GitHub branch protection]:
        • check-success = kms-connector-tests/test-connector (bpr)
        • check-neutral = kms-connector-tests/test-connector (bpr)
        • check-skipped = kms-connector-tests/test-connector (bpr)

@eudelins-zama
Copy link
Copy Markdown
Contributor Author

@Mergifyio refresh

@mergify
Copy link
Copy Markdown

mergify bot commented Mar 26, 2026

refresh

✅ Pull request refreshed

@eudelins-zama
Copy link
Copy Markdown
Contributor Author

@Mergifyio refresh

@mergify
Copy link
Copy Markdown

mergify bot commented Mar 26, 2026

Merge Queue Status

This pull request spent 1 hour 19 minutes 4 seconds in the queue, including 51 minutes 58 seconds running CI.

Required conditions to merge

@mergify
Copy link
Copy Markdown

mergify bot commented Mar 26, 2026

refresh

✅ Pull request refreshed

mergify bot added a commit that referenced this pull request Mar 26, 2026
@mergify mergify bot merged commit 7b38b46 into main Mar 26, 2026
66 of 67 checks passed
@mergify mergify bot removed the merge-queued label Mar 26, 2026
@mergify mergify bot deleted the eudelins/feat/1189/event-listening-via-get-logs branch March 26, 2026 17:21
@mergify mergify bot removed the queued label Mar 26, 2026
eudelins-zama added a commit that referenced this pull request Mar 27, 2026
* feat(kms-connector): eth_getLogs event listening

* chore(kms-connector): event listener error handling

* chore(kms-connector): code cleaning

* fix(kms-connector): error metric handling

* fix(kms-connector): fix flaky tests

* chore(kms-connector): batch db insertion

* chore(kms-connector): rename metric

* chore(kms-connector): code cleaning

* fix(kms-connector): fix ob1 error

* chore(kms-connector): docs

* chore(kms-connector): docs

Co-authored-by: David <[email protected]>

* chore(kms-connector): u8 to usize

---------

Co-authored-by: David <[email protected]>
eudelins-zama added a commit that referenced this pull request Mar 27, 2026
feat(kms-connector): event listening via eth_getLogs (#2166)

* feat(kms-connector): eth_getLogs event listening

* chore(kms-connector): event listener error handling

* chore(kms-connector): code cleaning

* fix(kms-connector): error metric handling

* fix(kms-connector): fix flaky tests

* chore(kms-connector): batch db insertion

* chore(kms-connector): rename metric

* chore(kms-connector): code cleaning

* fix(kms-connector): fix ob1 error

* chore(kms-connector): docs

* chore(kms-connector): docs



* chore(kms-connector): u8 to usize

---------

Co-authored-by: David <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants