Skip to content

PLEX-2794 fix inconsistent head snapshots#438

Merged
dhaidashenko merged 23 commits into
developfrom
fix/PLEX-2794-N-09-inconsistent-head-snapshots
May 19, 2026
Merged

PLEX-2794 fix inconsistent head snapshots#438
dhaidashenko merged 23 commits into
developfrom
fix/PLEX-2794-N-09-inconsistent-head-snapshots

Conversation

@dhaidashenko
Copy link
Copy Markdown
Contributor

Problem

The pollAndSaveLogs function derives on-chain status from latestBlocks and latestSafeBlock, but those helpers only clamp zero values and never verify the basic ordering finalized <= safe <= latest before the numbers are used and persisted. The resulting latestFinalizedBlockNumber drives the finalized backfill bound lastSafeBackfillBlock := latestFinalizedBlockNumber - 1, and the finalized / safe values are written into block checkpoints during getUnfinalizedLogs. If the poller observes a self-inconsistent head tuple, it can make poor control-flow decisions such as attempting out-of-range backfills or persisting inflated confirmation metadata that later feeds confirmed-read cutoffs through withConfs.

Fix

Use blocks with higher confidence if their block number is higher to guarantee latest >= safe >= finalized.

@github-actions
Copy link
Copy Markdown
Contributor

✅ API Diff Results - No breaking changes


📄 View full apidiff report

@dhaidashenko dhaidashenko changed the title PLEX-2794 N-09 fix inconsistent head snapshots PLEX-2794 fix inconsistent head snapshots May 15, 2026
Base automatically changed from fix/PLEX-2793-N-08-ensure-heads-not-nil to develop May 19, 2026 14:09
@silaslenihan silaslenihan requested review from a team as code owners May 19, 2026 14:09
Copilot AI review requested due to automatic review settings May 19, 2026 15:10
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 19, 2026

📊 API Diff Results

No changes detected for module github.com/smartcontractkit/chainlink-evm

View full report

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR mitigates inconsistent head snapshots observed by logPoller by enforcing a consistent ordering across latest/safe/finalized block numbers before they’re used for backfill bounds and persisted into block checkpoints.

Changes:

  • Consolidates retrieval of latest/safe/finalized into latestBlocks(...) and introduces latestAndFinalizedBlocks(...) to separate concerns.
  • Adds ordering/mitigation logic so returned values satisfy latest >= safe >= finalized (preferring higher-confidence heads when they report higher numbers).
  • Updates internal tests to reflect the new helper APIs and adds coverage for “finalized ahead of latest” and “safe ahead of latest” scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/logpoller/log_poller.go Refactors head tuple retrieval and applies ordering mitigation to prevent inconsistent persisted checkpoint metadata/backfill bounds.
pkg/logpoller/log_poller_internal_test.go Updates mocks to new helper APIs and adds test cases for inconsistent head ordering scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/logpoller/log_poller.go Outdated
Comment thread pkg/logpoller/log_poller.go
@dhaidashenko dhaidashenko enabled auto-merge (squash) May 19, 2026 15:29
@dhaidashenko dhaidashenko merged commit e22912d into develop May 19, 2026
34 checks passed
@dhaidashenko dhaidashenko deleted the fix/PLEX-2794-N-09-inconsistent-head-snapshots branch May 19, 2026 15:36
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.

4 participants