Skip to content

(Requires Audit) PLEX-2473 LogPoller switch to batch inserts (Part 2)#356

Merged
dhaidashenko merged 11 commits intodevelopfrom
feature/PLEX-2473-lp-batch-insert-blocks
Apr 24, 2026
Merged

(Requires Audit) PLEX-2473 LogPoller switch to batch inserts (Part 2)#356
dhaidashenko merged 11 commits intodevelopfrom
feature/PLEX-2473-lp-batch-insert-blocks

Conversation

@dhaidashenko
Copy link
Copy Markdown
Contributor

@dhaidashenko dhaidashenko commented Feb 13, 2026

Insert blocks and logs in batches to reduce DB IO usage.

Depends on: #355

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 13, 2026

⚠️ API Diff Results - Breaking changes detected

📦 Module: github-com-smartcontractkit-chainlink-evm

🔴 Breaking Changes (4)

pkg/logpoller.(*DSORM) (1)
  • InsertLogsWithBlock — 🗑️ Removed
pkg/logpoller.(*ObservedORM) (1)
  • InsertLogsWithBlock — 🗑️ Removed
pkg/logpoller.ORM (2)
  • InsertLogsWithBlock — 🗑️ Removed

  • InsertLogsWithBlocks — ➕ Added


📄 View full apidiff report

@dhaidashenko dhaidashenko changed the title PLEX-2473 LogPoller switch to batch inserts PLEX-2473 LogPoller switch to batch inserts (Part 2) Feb 13, 2026
@dhaidashenko dhaidashenko changed the title PLEX-2473 LogPoller switch to batch inserts (Part 2) (Pending Audit) PLEX-2473 LogPoller switch to batch inserts (Part 2) Feb 13, 2026
@dhaidashenko dhaidashenko changed the title (Pending Audit) PLEX-2473 LogPoller switch to batch inserts (Part 2) (Requires Audit) PLEX-2473 LogPoller switch to batch inserts (Part 2) Feb 13, 2026
@dhaidashenko dhaidashenko marked this pull request as ready for review February 13, 2026 16:33
@dhaidashenko dhaidashenko requested a review from a team as a code owner February 13, 2026 16:33
Krish-vemula
Krish-vemula previously approved these changes Feb 17, 2026
Comment thread pkg/logpoller/orm.go Outdated
Comment thread pkg/logpoller/log_poller.go
@dhaidashenko dhaidashenko force-pushed the feature/PLEX-2473-fix-reorg-handing-on-replay branch from 29ffcf3 to ccc00f8 Compare February 26, 2026 15:14
@dhaidashenko dhaidashenko force-pushed the feature/PLEX-2473-lp-batch-insert-blocks branch from 0833d36 to 715d9ba Compare February 26, 2026 15:18
Comment thread pkg/logpoller/log_poller.go
jmank88
jmank88 previously approved these changes Feb 26, 2026
@github-actions github-actions Bot deleted the branch develop April 5, 2026 01:02
@github-actions github-actions Bot closed this Apr 5, 2026
@dhaidashenko dhaidashenko reopened this Apr 14, 2026
Base automatically changed from feature/PLEX-2473-fix-reorg-handing-on-replay to develop April 24, 2026 13:01
@dhaidashenko dhaidashenko dismissed stale reviews from jmank88 and Krish-vemula April 24, 2026 13:01

The base branch was changed.

# Conflicts:
#	pkg/logpoller/log_poller.go
#	pkg/logpoller/log_poller_test.go
Copilot AI review requested due to automatic review settings April 24, 2026 13:11
@dhaidashenko dhaidashenko enabled auto-merge (squash) April 24, 2026 13:11
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 24, 2026

⚠️ API Diff Results - github.com/smartcontractkit/chainlink-evm

⚠️ Breaking Changes (4)

pkg/logpoller.(*DSORM) (1)
  • InsertLogsWithBlock — 🗑️ Removed
pkg/logpoller.(*ObservedORM) (1)
  • InsertLogsWithBlock — 🗑️ Removed
pkg/logpoller.ORM (2)
  • InsertLogsWithBlock — 🗑️ Removed

  • InsertLogsWithBlocks — ➕ Added

✅ Compatible Changes (3)

pkg/logpoller.(*DSORM) (2)
  • InsertBlocks — ➕ Added

  • InsertLogsWithBlocks — ➕ Added

pkg/logpoller.(*ObservedORM) (1)
  • InsertLogsWithBlocks — ➕ Added

📄 View full apidiff 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 extends the LogPoller batching work by enabling batch insertion of blocks (and logs+blocks together) to reduce DB I/O, and refactors unfinalized log processing to accumulate blocks/logs before persisting.

Changes:

  • Replaced InsertLogsWithBlock with InsertLogsWithBlocks, added InsertBlocks, and introduced a shared batchInsert helper for batched SQL inserts.
  • Refactored unfinalized polling to gather blocks/logs across a range and persist them in one call, with explicit reorg detection via a typed error.
  • Updated and added tests to cover block batching and adjusted polling/reorg property tests.

Reviewed changes

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

Show a summary per file
File Description
pkg/logpoller/orm.go Adds batched block insert + generic batch insert helper; updates ORM API to accept multiple blocks.
pkg/logpoller/log_poller.go Refactors unfinalized polling flow to collect blocks/logs and batch-persist; adds reorgError plumbing.
pkg/logpoller/observability.go Updates observed ORM wrapper for the new insert API and block-count tracking.
pkg/logpoller/orm_test.go Adds a block batching test and updates call sites for the new insert API.
pkg/logpoller/observability_test.go Updates tests to call the new insert API.
pkg/logpoller/log_poller_test.go Adjusts property test randomness and poll start block handling.
pkg/logpoller/helper_test.go Updates canonical-hash assertions to compare via string formatting.
Comments suppressed due to low confidence (1)

pkg/logpoller/orm.go:576

  • InsertLogsWithBlocks currently allows inserting logs when blocks is empty (InsertBlocks becomes a no-op). This changes the old InsertLogsWithBlock contract (which always persisted the accompanying block) and can lead to logs existing without corresponding entries in log_poller_blocks, breaking confirmation-based queries and reorg detection. Consider returning an error when len(logs) > 0 && len(blocks) == 0, or documenting/enforcing the intended behavior.
func (o *DSORM) InsertLogsWithBlocks(ctx context.Context, logs []Log, blocks []Block) error {
	// Optimization, don't open TX when there is only a block to be persisted
	if len(logs) == 0 {
		return o.InsertBlocks(ctx, blocks)
	}

	if err := o.validateLogs(logs); err != nil {
		return err
	}

	// Block and logs goes with the same TX to ensure atomicity
	return o.Transact(ctx, func(orm *DSORM) error {
		err := orm.InsertBlocks(ctx, blocks)
		if err != nil {
			return err
		}
		return orm.insertLogsWithinTx(ctx, logs, orm.ds)
	})

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

Comment thread pkg/logpoller/orm_test.go
Comment thread pkg/logpoller/observability.go
Comment thread pkg/logpoller/log_poller.go
Comment thread pkg/logpoller/log_poller.go
Comment thread pkg/logpoller/log_poller_test.go
@dhaidashenko dhaidashenko merged commit ffb14c0 into develop Apr 24, 2026
34 checks passed
@dhaidashenko dhaidashenko deleted the feature/PLEX-2473-lp-batch-insert-blocks branch April 24, 2026 14:49
dhaidashenko added a commit that referenced this pull request Apr 28, 2026
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.

7 participants