Skip to content

Conversation

@DZakh
Copy link
Member

@DZakh DZakh commented Sep 11, 2025

Summary by CodeRabbit

  • New Features
    • Added onBlock handlers with per-chain options and lifecycle-guarded registration.
    • Process block-level items alongside events for block-driven workflows.
  • Refactor
    • Config updates: replace unordered flag with multichain mode; add preloadHandlers and registrations across generated configs.
    • Progress tracking improved (startBlock, firstEventBlockNumber).
    • HyperSync source accepts API token, retry, and timeout options.
  • Chores
    • Added ECS Pino format dependency for structured logging.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 11, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Adds a new item model (Internal.item) and onBlock registration lifecycle. Refactors batching, fetch state, processing, logging, and chain management to use items (Event|Block). Introduces registration start/finish, per-chain onBlock configs, and updated source sync/options. Updates templates, tests, and dependencies accordingly.

Changes

Cohort / File(s) Summary
API Type Exports
codegenerator/cli/npm/envio/index.d.ts, .../src/Envio.gen.ts, .../src/Envio.res, .../src/Internal.gen.ts, .../src/InternalConfig.res
Exported new public types: blockEvent, onBlockArgs, onBlockOptions; Internal.blockEvent TS alias; added ecosystem/multichain/history/sourceSync types.
Item Model Refactor & Utils
.../src/Internal.res, .../src/EventUtils.res, .../src/Batch.res, .../src/FetchState.res, .../src/sources/Source.res
Introduced Internal.item (Event
Registration Lifecycle & onBlock
.../src/EventRegister.res, .../src/EventRegister.resi, codegenerator/cli/templates/dynamic/codegen/src/Handlers.res.hbs, .../index.d.ts.hbs, .../RegisterHandlers.res.hbs, .../TestHelpers_MockDb.res.hbs
Added lifecycle: startRegistration/finishRegistration, withRegistration queue; onBlock registration with validation and per-chain uniqueness; generator exposes onBlock binding; config build now preloads/collects registrations.
Sources
.../src/sources/HyperSyncSource.res, .../src/sources/HyperSync.res, .../src/sources/HyperSync.resi, .../src/sources/RpcSource.res, .../src/sources/HyperFuelSource.res, .../templates/static/codegen/src/eventFetching/NetworkSources.res
HyperSyncSource options now include apiToken/client retries/timeout; moved env to args; sources construct Internal.Event items; HyperSync block field types updated; NetworkSources uses InternalConfig.sourceSyncOptions and passes new HyperSync options.
Logging & Dependencies
.../src/Logging.res, .../src/bindings/Pino.res, codegenerator/cli/npm/envio/package.json, .../package.json.tmpl, codegenerator/cli/templates/dynamic/codegen/package.json.hbs
Logging now per-item (getItemLogger) with Event
Static Template Refactors
.../templates/static/codegen/src/Config.res, .../EventProcessing.res, .../IO.res, .../Index.res, .../LoadLayer.res, .../LoadLayer.resi, .../UserContext.res, .../GlobalState.res, .../db/Migrations.res, .../eventFetching/ChainFetcher.res, .../eventFetching/ChainManager.res
Switched to Internal.item across processing, load layer, user context, global state; added registrations/preloadHandlers fields; multichain now enum; moved endBlock/first event handling; updated function signatures and flows accordingly.
Codegen Types Injection
codegenerator/cli/src/hbs_templating/codegen_templates.rs, codegenerator/cli/templates/dynamic/codegen/src/Types.res.hbs
Generator now computes and injects {{types_code}} (e.g., chainId/chain union) into Types.res.hbs; ProjectTemplate gains types_code field.
Tests and Docs
scenarios/** (multiple tests and mocks), internal_docs/EventFetchers.md, scenarios/helpers/src/*, scenarios/test_codegen/src/EventHandlers.ts
Tests/mocks updated to item model, multichain enum, registration flow, and new shapes; added onBlock usage tests and late-registration errors; docs adjusted to item terminology.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Gen as Codegen Handlers
  participant ER as EventRegister
  participant Cfg as Config Builder
  participant CM as ChainManager
  participant CF as ChainFetcher
  participant FS as FetchState
  participant EP as EventProcessing

  rect rgb(245,248,255)
    note over Cfg,ER: Registration lifecycle (new)
    Cfg->>ER: startRegistration(~ecosystem, ~multichain, ~preloadHandlers)
    Gen->>ER: onBlock(options, handler)
    ER-->>ER: validate & store per-chain onBlock
    Cfg->>ER: finishRegistration()
    ER-->>Cfg: registrations
    Cfg-->>CM: config { registrations, multichain, ... }
  end

  rect rgb(245,255,245)
    note over CM,EP: Processing with items (Event|Block)
    CM->>CF: fetch next ranges
    CF->>FS: handleQueryResult(...)
    FS-->>CF: queue items [Event|Block]
    CF-->>CM: batch of items
    CM->>EP: processEventBatch(items, ...)
    alt item is Block
      EP-->>EP: build onBlock args {block, context}
      EP-->>Gen: invoke registered onBlock handler
    else item is Event
      EP-->>Gen: invoke event handler (if any)
    end
  end
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120–180 minutes

Possibly related PRs

Suggested reviewers

  • JonoPrest
  • moose-code

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "On block interval" is concise and directly references the new onBlock interval functionality introduced in the changeset (new onBlock/onBlockOptions types, onBlock registration, and block-item queuing). It accurately relates to a clear, significant part of the PR while not capturing the broader refactor (item/event unification and registration lifecycle). The title is not vague or misleading.

Poem

I hopped through blocks, both Event and Block,
With paws that sort and ears that clock.
I registered first—then off I go,
On every chain, in ordered flow.
Logs now sparkle, ECS-bright—
Carrots compiled, everything’s right! 🥕✨

✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dz/on-block-interval

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@DZakh DZakh changed the base branch from main to dz/on-block September 11, 2025 10:31
@DZakh DZakh requested a review from JonoPrest September 11, 2025 10:31
Comment on lines +654 to +657
let rangeEnd = switch onBlockConfig.endBlock {
| Some(endBlock) => Pervasives.min(endBlock, nextLatestFullyFetchedBlockNumber)
| None => nextLatestFullyFetchedBlockNumber
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Clamp this to the max queue size

Copy link
Collaborator

@JonoPrest JonoPrest left a comment

Choose a reason for hiding this comment

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

💪🏼

@DZakh DZakh changed the base branch from dz/on-block to main September 11, 2025 12:49
@DZakh DZakh merged commit 4ac325a into main Sep 11, 2025
2 checks passed
@DZakh DZakh deleted the dz/on-block-interval branch September 11, 2025 12:49
@DZakh DZakh mentioned this pull request Sep 11, 2025
14 tasks
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.

3 participants