Skip to content

Replace ecosystem tag constants with typed enum - #1361

Merged
DZakh merged 3 commits into
mainfrom
claude/transaction-store-quality-1c7wbo
Jun 30, 2026
Merged

Replace ecosystem tag constants with typed enum#1361
DZakh merged 3 commits into
mainfrom
claude/transaction-store-quality-1c7wbo

Conversation

@DZakh

@DZakh DZakh commented Jun 29, 2026

Copy link
Copy Markdown
Member

Replace magic number constants (ECO_UNKNOWN, ECO_EVM, ECO_SVM) with a proper Ecosystem enum in the transaction store, improving type safety and code clarity.

Key changes:

  • Introduce Ecosystem enum with Evm and Svm variants, eliminating the need for an Unknown variant by using Option<Ecosystem> to represent the unset state
  • Add Ecosystem::to_tag() and Ecosystem::from_tag() methods to convert between the enum and the u8 tags stored in the atomic
  • Add ecosystem() and set_ecosystem() helper methods on TransactionStore to encapsulate tag conversion logic
  • Update all ecosystem checks and assignments to use the typed enum instead of raw constants
  • Simplify ReScript field lists by deriving them from typed Internal definitions instead of maintaining separate hardcoded arrays, eliminating drift risk between Rust and ReScript orderings
  • Update tests to verify the derived field lists match Rust orderings

Implementation details:

The persistent store starts with ecosystem unset (0), learned from the first merged page. Using Option<Ecosystem> makes this unset state explicit in the type system rather than relying on a magic constant. The atomic still stores u8 tags for serialization, but all code paths now work with the typed enum.

https://claude.ai/code/session_019sLva7B7C64twV9DVcJb6X

Derive Evm/Svm `transactionFields` from the typed `Internal` field lists
instead of restating them as string literals, so the array order (the
bitmask field codes shared with the Rust store) can't drift from the
variant lists. The two redundant contract tests are dropped; the
`Internal.all*TransactionFields` pins to the Rust ordinals remain.

Replace the `ECO_UNKNOWN/EVM/SVM` u8 constants and bare-integer match
with an `Ecosystem { Evm, Svm }` enum. The not-yet-learned state is now
`Option::None` rather than a magic variant; the atomic keeps a `u8` tag
(`0` = unset) behind `to_tag`/`from_tag`, and `materialize` dispatches on
an exhaustive `Some(Evm)/Some(Svm)/None` match.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019sLva7B7C64twV9DVcJb6X
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You鈥檝e reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 17 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
鈿欙笍 Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3e058070-2e48-43de-8115-935e4ac2d8f2

馃摜 Commits

Reviewing files that changed from the base of the PR and between 0b5a669 and 461c528.

馃搾 Files selected for processing (9)
  • packages/cli/src/evm_hypersync_source/mod.rs
  • packages/cli/src/transaction_store.rs
  • packages/envio/src/ChainState.res
  • packages/envio/src/ChainState.resi
  • packages/envio/src/sources/Evm.res
  • packages/envio/src/sources/Svm.res
  • packages/envio/src/sources/TransactionStore.res
  • scenarios/test_codegen/test/SvmHyperSyncSource_test.res
  • scenarios/test_codegen/test/TransactionStore_test.res

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

The store's ecosystem is fixed per chain by config, so model it that way
instead of learning it lazily from the first merged page:

- `Ecosystem` becomes a data-carrying enum `Evm { should_checksum } | Svm
  | Fuel`. `should_checksum` (a per-chain EVM constant) moves out of its
  own field into the `Evm` variant, so it can't be set without EVM or
  forgotten for it.
- The unset state is gone. The enum has no `Unknown`/`None`; `ecosystem`
  is a plain immutable field set at construction, dropping both atomics,
  the `u8` tag round-trip, and the lazy learn-on-merge branch.
- Fuel is a first-class variant rather than an untracked case; its store
  is inert (Fuel keeps transactions inline) but honestly typed.
- Expose `newEvm`/`newSvm`/`newFuel` factories; ReScript `make` takes the
  ecosystem (+ EVM checksum) and dispatches. ChainState derives both from
  config (`config.ecosystem.name`, `!lowercaseAddresses`), so even
  `CustomSources` chains construct the right store.

`merge` no longer transfers ecosystem/checksum (both fixed at
construction); a debug assert pins the page-vs-store ecosystem match.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019sLva7B7C64twV9DVcJb6X
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

@DZakh
DZakh enabled auto-merge (squash) June 30, 2026 09:09
@DZakh
DZakh merged commit 734a728 into main Jun 30, 2026
8 checks passed
@DZakh
DZakh deleted the claude/transaction-store-quality-1c7wbo branch June 30, 2026 09:14
DZakh pushed a commit that referenced this pull request Jun 30, 2026
Bring in main (incl. #1361 typed transaction-store ecosystem). Apply the same
to BlockStore: replace the ECO_* u8 constants + atomics with a construction-time
Ecosystem { Evm { should_checksum }, Svm, Fuel } enum and new_evm/new_svm/new_fuel
factories; merge no longer learns the ecosystem (debug-asserts page==store).
ReScript BlockStore.make takes ~ecosystem/~shouldChecksum and ChainState derives
both from config, mirroring TransactionStore.
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.

2 participants