Skip to content

(registry) implement schema versioning to support soroban contract upgrades and wasm updates#140

Merged
Osuochasam merged 5 commits into
Open-audit-foundation:mainfrom
ChukwuemekaP1:(registry)--Implement-schema-versioning-to-support-Soroban-contract-upgrades-and-WASM-updates
Jun 25, 2026
Merged

(registry) implement schema versioning to support soroban contract upgrades and wasm updates#140
Osuochasam merged 5 commits into
Open-audit-foundation:mainfrom
ChukwuemekaP1:(registry)--Implement-schema-versioning-to-support-Soroban-contract-upgrades-and-WASM-updates

Conversation

@ChukwuemekaP1

Copy link
Copy Markdown
Contributor

Translation Registry Evolution: Historical Event Translation System

Closes #103

Summary

This PR redesigns the Translation Registry into a Historical Event Translation System that supports contract upgrades while preserving complete historical accuracy.

Previously, the registry stored only a single schema per contract_id. This caused historical events to fail decoding after contract upgrades and made accurate blockchain replay impossible.

The new architecture introduces versioned schemas indexed by ledger ranges, ensuring that every event is decoded using the exact schema that was active when it was emitted.


Problem Statement

Soroban contracts can upgrade their logic using update_current_contract_wasm. The previous registry design could not handle schema evolution correctly because:

  • Historical blocks failed decoding after upgrades.
  • New events could fail validation against older schemas.
  • Blockchain replay and audit trails became unreliable.
  • Schema migrations required manual intervention.

Solution

Implemented a Versioned Resolution Engine with ledger-aware schema selection and runtime upgrade support.

Core Enhancements

Versioned Schema Resolution

  • Resolve schemas based on ledger sequence.
  • Historical events always use the correct schema version.
  • Supports unlimited contract upgrades while maintaining backward compatibility.

Resolution Cache

  • Added RESOLUTION_CACHE for O(1) lookup performance.
  • Optimized for hot contracts and frequent event decoding.

Runtime Upgrades

  • Added registerUpgrade() for zero-downtime contract evolution.
  • Cache invalidation occurs automatically for upgraded contracts.

Declarative Event Mapping

  • Added support for converting JSON/YAML event definitions into executable decoders.

Files Updated

Core Engine

  • lib/translator/registry.ts

    • Versioned resolution engine
    • Resolution cache
    • Runtime upgrades
    • Declarative mapping engine

Types

  • lib/translator/types.ts

    • Added ContractSchema
    • Added ContractRegistryEntry
    • Introduced hierarchical versioning support

Registry Schema

  • lib/translator/registry.schema.json

    • Added schemas[]
    • Semantic versioning support
    • valid_from_ledger
    • valid_to_ledger

Registry Data

  • lib/translator/registry.json

    • Migrated contracts to versioned schemas
    • Added multi-version examples

Documentation

  • ARCHITECTURE.md

    • Updated translation engine architecture
    • Added caching strategy
    • Added upgrade workflow

Tests

  • lib/translator/registry.versioning.test.ts

    • Historical replay tests
    • Boundary ledger matching
    • Cache invalidation tests
    • Upgrade flow verification

Key Features

Ledger-Based Schema Resolution

ledger >= validFromLedger &&
(validToLedger === null || ledger <= validToLedger)

This guarantees that historical events are always decoded with the schema that was active at that point in time.

Zero-Downtime Upgrades

Contracts can upgrade at runtime without restarting the indexer:

  • New schema registered immediately.
  • Future ledgers use the new schema.
  • Historical ledgers continue using previous versions.
  • Cache updates automatically.

Impact

Before

  • Contract upgrades broke historical decoding.
  • Re-indexing old blocks caused validation failures.
  • Schema evolution required manual handling.

After

  • Complete historical accuracy across all contract versions.
  • Reliable blockchain replay and auditing.
  • Zero-downtime schema evolution.
  • Scalable registry with O(1) schema resolution.

Performance & Reliability

  • O(1) schema resolution through compound-key caching.

  • 100% backward compatibility for historical events.

  • Full SAC family migrated to versioned schemas.

  • Integration tests cover edge cases including:

    • Boundary ledgers
    • Overlapping ranges
    • Historical replay
    • Upgrade scenarios

Testing

  • ✅ Historical replay verified
  • ✅ v1 → v2 upgrade simulation passed
  • ✅ Cache invalidation verified
  • ✅ Registry validation passed
  • ✅ Historical and new events decode correctly within the same session

Ready for review 🚀

@Osuochasam

Copy link
Copy Markdown
Collaborator

@ChukwuemekaP1 resolve conflicts

…upport-Soroban-contract-upgrades-and-WASM-updates
@ChukwuemekaP1

Copy link
Copy Markdown
Contributor Author

GM @Osuochasam I just fixed this issue , pls review

@Osuochasam

Copy link
Copy Markdown
Collaborator

@ChukwuemekaP1 GN, you still have conflicts

…upport-Soroban-contract-upgrades-and-WASM-updates
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.

(registry): Implement schema versioning to support Soroban contract upgrades and WASM updates

2 participants