Skip to content

Portal metrics: inserted.logs reports raw-streamed log count, not store-inserted (assembled.logs) count #143

Description

@dzhelezov

Summary

The per-chain metrics file's inserted.logs field reports the raw streamed Portal log count, not the number of logs actually inserted into the sync-store. In a window whose raw logs are all dropped by client-side re-match, the file can therefore report logs > 0 while blocks = 0 and zero logs were inserted.

Mechanism

  • stats.logs is incremented from the raw streamed logs during range streaming: stats.logs += b.logs.length (portal/portal.ts ~L409). The code separately tracks matchedLogsAdded, confirming stats.logs is the raw (pre-match) count.
  • Actual log insertion uses the assembled (post-re-match) set: syncStore.insertLogs({ logs: assembled.logs }) in syncBlockRangeData (~L1000). Raw over-returned logs that assembly drops (e.g. bounded out-of-range logs — see the existing portal.test.ts coverage) are never inserted.
  • The metrics file maps inserted: { logs: stats.logs, ... } (portal/portal-metrics.ts ~L115), i.e. inserted.logs = the raw count.

Result: on a window where raw logs were streamed but all re-match-dropped, assembled.blocks is empty → syncBlockData takes the blockArr.length === 0 path and emits a metrics file with inserted.logs > 0, inserted.blocks = 0. The logs count contradicts the fact that nothing was inserted.

Scope / relationship to #140

This is pre-existing and independent of #140/#142 — the normal (non-empty) path already reports inserted.logs from the raw count. #142 (emit metrics on 0-block windows) merely surfaces it on one additional code path. The real #140 case (empty child-address set → 0 raw logs → stats.logs = 0) is unaffected and reports honest zeros.

Suggested fix

Make inserted.logs reflect logs actually inserted — count assembled.logs.length at insertion time rather than raw b.logs.length at stream time — so inserted.* is uniformly a store-insertion count. Note this metric feeds the completion-line provenance, so update that path together and add a regression test for a re-match-dropped-only empty window (logs reported = 0 when nothing is inserted).

Severity: low (observability/metric accuracy; indexing correctness unaffected). Surfaced during review of #142.

Metadata

Metadata

Assignees

No one assigned

    Labels

    severity:lowDefense-in-depth / narrow residual

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions