#341 registerUpgrade() references createTranslateFromMapping which is… - #351
Conversation
…eFromMapping which is not defined anywhere in the codebase FIXED
Collaborator
|
@felladaniel36-hash fix conflicts |
…references-createTranslateFromMapping-which-is-not-defined-anywhere-in-the-codebase-FIX
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.
📋 Issue Summary
Problem:
registerUpgradeinlib/translator/registry.tsattempted to build runtime translation blueprints usingcreateTranslateFromMapping, but the translation path was incomplete and unsafe:eventMappingsusedany[], bypassing TypeScript validation.{from.short}and{amount.formatted}were not interpolated correctly.Solution: Implemented a fully typed event-mapping translation pipeline, connected it to
registerUpgrade, preserved schema version metadata, added ledger-boundary tests, and ensured cache invalidation works after registering an upgrade.✅ Changes Made
Modified Files
lib/translator/registry.tscreateTranslateFromMappingtranslation path.eventMappings: any[]with:decodeAddressdecodeAmountdecodeEventNameinterpolateTemplate{field}{field.short}{field.formatted}versionandvalidFromLedgeron generated upgrade blueprints.anycast previously used to read blueprint versions.lib/translator/types.tsEventMappingFieldTypeEventMappingFieldEventMappingStructureEventMappingDefinitionany.lib/translator/registry.versioning.test.tsresolveSchemaassertions.lib/translator/core.tsNew Files Created
None.
🧩 Typed Runtime Mapping API
The public API now accepts strongly typed mapping definitions:
Example:
No
any[]parameter is used.🔄 Runtime Upgrade Flow
flowchart TD RegisterUpgrade[registerUpgrade called] TypedMappings[Validate typed event mappings] Compile[Compile mapping translators once] Schema[Create versioned translation blueprint] Sort[Sort schemas by validFromLedger] Boundaries[Recalculate validToLedger boundaries] Cache[Invalidate contract resolution cache] Resolve[resolveSchema receives event ledger] Translate[Use matching schema translator] RegisterUpgrade --> TypedMappings TypedMappings --> Compile Compile --> Schema Schema --> Sort Sort --> Boundaries Boundaries --> Cache Cache --> Resolve Resolve --> Translate📐 Schema Boundary Behavior
Given these registrations:
The registry resolves schemas as follows:
991001.1.04991.1.05002.0.010,0002.0.0The resulting ranges are:
Historical events therefore continue using the schema that was active when they were emitted.
🌍 Template Support
The translator supports both the legacy English template property and language-specific templates.
Legacy format
Language-specific format
Template selection order:
⚡ Performance Improvement
Before
A mapping translator was constructed inside the translation loop:
This recreated closures every time an event was translated.
After
Mapping translators are compiled once when the upgrade is registered:
The event path only executes the precompiled translators:
🧪 Testing
Version-selection tests
Executed:
Result:
The tests prove:
registerUpgradeexecutes without the reported missing-function error.Registry-focused test suite
Executed:
Result:
Registry validation
Executed:
Result:
Diff validation
Executed:
Result: Passed.
The issue-specific implementation and registry tests pass. However, the current upstream
mainbranch contains unrelated pre-existing build, type-check, and test failures.Full test suite
npm testResult:
The remaining failures involve unrelated areas such as:
TypeScript
The repository-wide check remains blocked by unrelated existing errors, including missing modules, invalid exports, API route typing, dashboard typing, indexer conflicts, and test typing errors.
Production build
The build starts but is blocked by unrelated missing upstream modules and exports:
These failures are outside the files and behavior addressed by this PR.
🎯 Acceptance Criteria
registerUpgradecan be called without the reportedReferenceErroreventMappingsno longer usesany[]tsc --noEmitpasses📊 Fix Metrics
anyparameters inregisterUpgrade: 0🔍 Key Review Areas
Reviewers should focus on:
lib/translator/types.ts.registerUpgrade.registry.versioning.test.ts.📌 Closes Issue
This fix resolves the issue where runtime contract upgrades could reference a missing or incomplete
createTranslateFromMappingimplementation and bypass TypeScript throughany[].Before: Runtime upgrade registration was unsafe and could fail during translation.
After: Runtime upgrades use typed mapping definitions, precompiled translators, language-aware templates, cache invalidation, and ledger-correct schema resolution.
Branch Information
mainReady for review, with unrelated upstream repository failures documented above.
CLOSE #341