feat(evm): explicit factory pre-indexing phase before the main loop - #106
Open
mo4islona wants to merge 1 commit into
Open
feat(evm): explicit factory pre-indexing phase before the main loop#106mo4islona wants to merge 1 commit into
mo4islona wants to merge 1 commit into
Conversation
mo4islona
force-pushed
the
feat/factory-preindex
branch
3 times, most recently
from
July 7, 2026 13:58
80e3724 to
224fefa
Compare
Replaces the removed _experimental_preindex with a declarative preindex: true option on contractFactory. On startup the pipe scans factory-creation events up to the finalized head, persists children and scan progress in SQLite, then backfills child events with a server-side address filter and falls back to a wildcard query above the finalized head. Restarts and interrupted scans resume from the persisted progress. Co-Authored-By: Claude Fable 5 <[email protected]>
mo4islona
force-pushed
the
feat/factory-preindex
branch
from
July 7, 2026 14:04
224fefa to
8f87a15
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the removed
_experimental_preindexwith an explicit, automatically-managed factory pre-indexing phase, enabled declaratively:The old option was removed for being vague (a user-picked range silently changing query behavior). This version manages the range itself and runs as a visible, logged phase.
How it works
factory preindex: already up to date at block N).[from … finalized]are requested with a server-side address filter (fast backfill, less traffic). Above the finalized head the query falls back to the usual wildcard (topic-only) request with client-side filtering, where inline discovery keeps running as before.Fork safety is structural: the pre-indexed range never exceeds the finalized head, so it never rolls back; children discovered inline in the wildcard tail are handled by the existing
Factory.fork()cleanup.Notable details:
range.fromor changing addresses/event/params between runs safely triggers a re-scan instead of silently missing children.maxAddressFilterSizechildren (default 5 000 — the list is embedded into every stream request body, ~50 bytes per address) the pipe warns and falls back to the wildcard query. The cap is enforced before wasting work: a start with more persisted children than the cap skips the gap scan entirely, and a first-run scan stops mid-way as soon as the discovered set crosses the cap. The per-batch progress stays honest, so raising the cap later resumes the scan from where it stopped./finalized-head) log a warning and keep today's single-pass behavior.FactoryPersistentAdaptergains optionalgetPreindexedRange/setPreindexedRange— third-party adapters keep working and degrade to a full re-scan per start (idempotent).portal(SetupQueryCtx), andevmDecoderregisters its log requests insidesetupQueryinstead of at construction time, since the split depends on the pre-pass result. Registration is memoized as a promise: a pre-pass that failed during setup stays failed on a retried stream start instead of silently merging a query without child-event requests.factory preindex: scanning blocks X…Y for factory 0x…, progress ticks in the main loop's format under the same prefix (factory preindex: 15,000,000 / 23,000,000 (65%), ETA: 1m 30s+ blocks/s, bytes/s), thenfactory preindex: finished, blocks X…Y covered. The nested scan no longer emits a secondStart indexing…line — the only one you see belongs to the main loop.Coverage diff (base vs head)
src/core/portal-source.tssrc/core/query-builder.tssrc/core/transformer.tssrc/evm/evm-decoder.tssrc/evm/factory-adapters/sqlite.tssrc/evm/factory.tssrc/internal/hash.tssrc/testing/test-portal.tsBase 378 tests → head 400 tests. The
factory.tsbranch dip comes from new defensive guards (non-404 error rethrow, missing-adapter-method warnings);hash.tsuncovered lines are environment-guard throws (noTextEncoder/crypto.subtle) unreachable under Node. New tests use the internal testing framework (createMockPortal+mockBlock/encodeEvent);createMockPortallearned aheadoption to serve/finalized-headdeterministically, andcreateTestLoggerlearned acaptureoption to assert log output. The table predates the review follow-ups (5 extra tests slightly raisefactory.ts/evm-decoder.tsfurther;src/core/progress-tracker.tswas touched by a pure extract-and-reuse refactor of the progress-message formatting).Testing
factory-preindex.test.ts: query split shape, empty-children skip, gap-only re-scan on restart, params-change re-scan under a new progress key, per-batch progress persistence + interrupted-scan resume, fork in the wildcard tail, no-finality fallback,maxAddressFilterSizefallback, unit tests for the range helpers — plus review follow-ups: serialized shared-factory pre-passes (same range → single scan; a range extending below the covered one → re-scan), loud failure on a retried setup after a failed pre-pass,factory preindex:-prefixed pre-pass logging without a duplicate start line, mid-scan abort once the child set crosses the cap (with resume after raising it), and skipping the gap scan when the persisted children already exceed the cap.pnpm buildand Biome clean.factory preindex: already up to date at block 12400000and went straight to the main loop.🤖 Generated with Claude Code