Skip to content

(Requires Audit) PLEX-2473 LP Sparce Block Store (Part 3)#374

Merged
dhaidashenko merged 14 commits intodevelopfrom
feature/PLEX-2473-lp-sparce-block-store
Apr 24, 2026
Merged

(Requires Audit) PLEX-2473 LP Sparce Block Store (Part 3)#374
dhaidashenko merged 14 commits intodevelopfrom
feature/PLEX-2473-lp-sparce-block-store

Conversation

@dhaidashenko
Copy link
Copy Markdown
Contributor

@dhaidashenko dhaidashenko commented Feb 25, 2026

Required to reduce LP's DB usage.
Depends on #356

@dhaidashenko dhaidashenko changed the title PLEX-2473 LP Sparce Block Store (Requires Audit) PLEX-2473 LP Sparce Block Store Feb 25, 2026
@dhaidashenko dhaidashenko changed the base branch from develop to feature/PLEX-2473-lp-batch-insert-blocks February 25, 2026 17:53
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 25, 2026

⚠️ API Diff Results - Breaking changes detected

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

🔴 Breaking Changes (2)

pkg/config.EVM (1)
  • LogPollerSkipEmptyBlocks — ➕ Added
pkg/logpoller.ORM (1)
  • SelectNewestBlock — ➕ Added

📄 View full apidiff report

@dhaidashenko dhaidashenko force-pushed the feature/PLEX-2473-lp-sparce-block-store branch from 498dfff to 4cad2fc Compare February 25, 2026 18:10
@dhaidashenko dhaidashenko marked this pull request as ready for review February 25, 2026 18:20
@dhaidashenko dhaidashenko requested a review from a team as a code owner February 25, 2026 18:20
Unheilbar
Unheilbar previously approved these changes Feb 26, 2026
silaslenihan
silaslenihan previously approved these changes Feb 26, 2026
@dhaidashenko dhaidashenko force-pushed the feature/PLEX-2473-lp-batch-insert-blocks branch from 0833d36 to 715d9ba Compare February 26, 2026 15:18
@dhaidashenko dhaidashenko force-pushed the feature/PLEX-2473-lp-sparce-block-store branch from 4cad2fc to 3fb2047 Compare February 26, 2026 15:21
@dhaidashenko dhaidashenko force-pushed the feature/PLEX-2473-lp-sparce-block-store branch from 3fb2047 to 0c4981b Compare February 26, 2026 16:14
@dhaidashenko dhaidashenko force-pushed the feature/PLEX-2473-lp-sparce-block-store branch from 0c4981b to 8d8ff31 Compare February 26, 2026 17:04
@dhaidashenko dhaidashenko changed the title (Requires Audit) PLEX-2473 LP Sparce Block Store (Requires Audit) PLEX-2473 LP Sparce Block Store (Part 3) Feb 26, 2026
@dhaidashenko dhaidashenko force-pushed the feature/PLEX-2473-lp-sparce-block-store branch from 8d8ff31 to c681f60 Compare February 26, 2026 17:23
@dhaidashenko dhaidashenko requested review from a team as code owners February 27, 2026 16:15
@github-actions
Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 30 days with no activity.
Remove the stale label or comment or this will be closed in 7 days.

@github-actions github-actions Bot added the Stale label Mar 30, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 6, 2026

This PR has been automatically closed because it has been stale for > 30 days.
If you wish to continue working on this PR, please reopen it and make any necessary changes.

@github-actions github-actions Bot closed this Apr 6, 2026
@github-actions github-actions Bot deleted the feature/PLEX-2473-lp-sparce-block-store branch April 6, 2026 01:02
@dhaidashenko dhaidashenko restored the feature/PLEX-2473-lp-sparce-block-store branch April 14, 2026 12:02
@dhaidashenko dhaidashenko reopened this Apr 14, 2026
@github-actions github-actions Bot removed the Stale label Apr 15, 2026
Base automatically changed from feature/PLEX-2473-lp-batch-insert-blocks to develop April 24, 2026 14:49
@dhaidashenko dhaidashenko dismissed stale reviews from silaslenihan and Unheilbar April 24, 2026 14:49

The base branch was changed.

Copilot AI review requested due to automatic review settings April 24, 2026 15:43
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

Adds support for a “sparse blocks” storage mode in the LogPoller to reduce DB writes by optionally skipping persistence of empty (no-log) blocks, and updates reorg/LCA logic plus configuration plumbing to support it.

Changes:

  • Add SelectNewestBlock to the LogPoller ORM and ObservedORM to support ancestor lookup in a sparse blocks table.
  • Introduce Opts.SkipEmptyBlocks / LogPollerSkipEmptyBlocks configuration and wire it through chain config -> LogPoller.
  • Update LogPoller reorg handling/LCA search and expand tests for sparse-block scenarios (including skip-empty-blocks).

Reviewed changes

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

Show a summary per file
File Description
pkg/logpoller/orm.go Adds SelectNewestBlock query for newest block at/below a given height.
pkg/logpoller/observability.go Adds observed wrapper for SelectNewestBlock.
pkg/logpoller/log_poller.go Adds SkipEmptyBlocks option and updates unfinalized log/block collection + LCA search for sparse DB blocks.
pkg/logpoller/log_poller_test.go Refactors/extends tests for skip-empty-blocks and adds DB-vs-geth consistency helpers.
pkg/logpoller/log_poller_internal_test.go Adds dedicated unit tests for findBlockAfterLCA under sparse DB conditions.
pkg/config/toml/docs.toml Documents LogPollerSkipEmptyBlocks.
pkg/config/toml/defaults/fallback.toml Provides default for LogPollerSkipEmptyBlocks.
pkg/config/toml/defaults.go Ensures defaults copy includes LogPollerSkipEmptyBlocks.
pkg/config/toml/testdata/config-full.toml Adds LogPollerSkipEmptyBlocks to full config fixture.
pkg/config/toml/config.go Adds LogPollerSkipEmptyBlocks to TOML Chain struct.
pkg/config/toml/config_test.go Updates config test expectations to include the new field.
pkg/config/config.go Extends EVM config interface with LogPollerSkipEmptyBlocks().
pkg/config/chain_scoped.go Implements LogPollerSkipEmptyBlocks() accessor.
pkg/config/mocks/evm.go Updates generated mock for new config method.
pkg/chains/legacyevm/chain.go Wires config flag into logpoller.Opts.SkipEmptyBlocks.
CONFIG.md Documents the new TOML setting.

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

Comment on lines 1250 to +1277
@@ -1262,8 +1270,11 @@ func (lp *logPoller) getUnfinalizedLogs(ctx context.Context, currentBlock *evmty
FinalizedBlockNumber: finalized,
SafeBlockNumber: safe,
}
logs = append(logs, convertLogs(rpcLogs, []Block{block}, lp.lggr, lp.ec.ConfiguredChainID())...)
blocks = append(blocks, block)
logs = append(logs, convertLogs(rpcLogs, []Block{*block}, lp.lggr, lp.ec.ConfiguredChainID())...)
// Skip empty blocks if configured to do so.
if len(rpcLogs) > 0 || !lp.skipEmptyBlocks {
blocks = append(blocks, *block)
}
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

getUnfinalizedLogs currently will not compile: it declares var block *Block and then shadows it with block := Block{...} inside the loop, but later dereferences *block and appends *block to slices. This also means the deferred checkpoint logic never sees the last block. Avoid shadowing and keep a single *Block (or use a differently named value like blk) and pass/append by value without dereferencing a non-pointer.

Copilot uses AI. Check for mistakes.
Comment on lines +2266 to +2289
func checkDBMatchesGeth(t *testing.T, orm logpoller.ORM, client logpoller.Client) bool {
// Check every block is identical
latest, err1 := client.HeadByNumber(testutils.Context(t), nil)
require.NoError(t, err1)
dbBlocks, err := orm.SelectLogsByBlockRange(t.Context(), 0, latest.Number)
require.NoError(t, err)
// ensure all blocks present in db are on geth canonical chain
for _, ourBlock := range dbBlocks {
gethBlock, err1 := client.HeadByNumber(testutils.Context(t), big.NewInt(ourBlock.BlockNumber))
require.NoError(t, err1)
if ourBlock.BlockHash != gethBlock.Hash {
t.Logf("Initial poll our block differs at height %d got %x want %x\n", ourBlock.BlockNumber, ourBlock.BlockHash, gethBlock.Hash)
return false
}
}

latestDB, err := orm.SelectLatestBlock(t.Context())
require.NoError(t, err)
require.Equal(t, latest.Number, latestDB.BlockNumber, "latest block number in db should match geth")

// ensure all logs present in db are on geth canonical chain
logs, err1 := orm.SelectLogsByBlockRange(t.Context(), 0, latest.Number)
require.NoError(t, err1)
for _, log := range logs {
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

checkDBMatchesGeth attempts to validate DB blocks against the canonical chain, but it calls orm.SelectLogsByBlockRange(...) and iterates those results as dbBlocks. This ends up checking log rows (and will miss blocks with no logs), and it duplicates the same logs query again later. Use a blocks query (e.g., orm.GetBlocksRange(...) or similar) for the blocks-table check, and keep the logs query only for validating log rows.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 24, 2026

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

⚠️ Breaking Changes (2)

pkg/config.EVM (1)
  • LogPollerSkipEmptyBlocks — ➕ Added
pkg/logpoller.ORM (1)
  • SelectNewestBlock — ➕ Added

✅ Compatible Changes (10)

pkg/config.(*EVMConfig) (1)
  • LogPollerSkipEmptyBlocks — ➕ Added
pkg/config.EVM (1)
  • LogPollerSkipEmptyBlocks — ➕ Added
pkg/config/mocks (1)
  • EVM_LogPollerSkipEmptyBlocks_Call — ➕ Added
pkg/config/mocks.(*EVM) (1)
  • LogPollerSkipEmptyBlocks — ➕ Added
pkg/config/mocks.(*EVM_Expecter) (1)
  • LogPollerSkipEmptyBlocks — ➕ Added
pkg/config/toml.Chain (1)
  • LogPollerSkipEmptyBlocks — ➕ Added
pkg/config/toml.EVMConfig (1)
  • LogPollerSkipEmptyBlocks — ➕ Added
pkg/logpoller.(*DSORM) (1)
  • SelectNewestBlock — ➕ Added
pkg/logpoller.(*ObservedORM) (1)
  • SelectNewestBlock — ➕ Added
pkg/logpoller.Opts (1)
  • SkipEmptyBlocks — ➕ Added

📄 View full apidiff report

@dhaidashenko dhaidashenko enabled auto-merge (squash) April 24, 2026 16:27
@dhaidashenko dhaidashenko merged commit 938a963 into develop Apr 24, 2026
34 checks passed
@dhaidashenko dhaidashenko deleted the feature/PLEX-2473-lp-sparce-block-store branch April 24, 2026 16:44
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.

6 participants