Validate duplicate addresses in config at parse time#1311
Merged
Conversation
The same address under two contract definitions (or listed twice under one) on a single chain violated the (chainId, address) primary key of envio_addresses at storage init, surfacing only on deploy as an opaque 'duplicate key value violates unique constraint "envio_addresses_pkey"' with no hint of the offending address or contracts. Validate at config parse time in the CLI (codegen fails fast) and again in Config.fromPublic as a runtime safety net for non-EVM ecosystems and stale codegen output, naming the chain, address, and contract pair. https://claude.ai/code/session_01Ga6MwYHPWo6GbqPdkPYrMy
registerDynamicContracts already warned and skipped a dynamic contract whose address was owned by another contract on fetchState.indexingAddresses, but the same-batch guard was dead code: it looked the address up in the per-contract dict keyed by the DC's own contract name, where a different contract name can never appear. Two contracts registering the same fresh address within one batch were both accepted — the address landed in both contracts' partitions while only one row survived in envio_addresses. Conflicts between events and no-events contracts in one batch slipped through the same way. Track a batch-level address dict across all contracts (including no-events ones) and consult it from both registration paths, so in-batch conflicts get the same warn-and-skip treatment as conflicts against indexingAddresses. https://claude.ai/code/session_01Ga6MwYHPWo6GbqPdkPYrMy
Contributor
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR enforces address uniqueness constraints per chain across config parsing and dynamic contract registration layers. Rust EVM validation, ReScript config loading, and runtime batch registration now consistently reject duplicate or conflicting addresses on the same chain while permitting reuse across different chains. ChangesAddress Uniqueness Validation Per Chain
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
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
Add validation to detect and reject duplicate addresses in config files at parse time, preventing opaque database constraint violations at runtime. The same address cannot be configured for multiple contracts on the same chain, nor can it be listed twice for a single contract. However, the same address is allowed across different chains.
Key Changes
Rust validation (
packages/cli/src/config_parsing/validation.rs): Added address deduplication check per chain that rejects:ReScript config parsing (
packages/envio/src/Config.res): Added parallel validation duringfromPublicto catch address conflicts before they reach the database, with clear error messages indicating the offending address, chain, and contract(s)Dynamic contract registration (
packages/envio/src/FetchState.res): Enhanced batch-level conflict detection to track all addresses being registered in a single batch (across contracts), ensuring two contracts cannot register the same address within one batch. Includes handling for conflicts between events and no-events registrations.Test coverage (
scenarios/test_codegen/test/Config_test.res,scenarios/test_codegen/test/lib_tests/FetchState_test.res): Added tests validating:Implementation Details
(chainId, address)https://claude.ai/code/session_01Ga6MwYHPWo6GbqPdkPYrMy
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests