Skip to content

feat(storage): namespace storage keys across contract modules (#1055) - #1094

Open
Killerjunior wants to merge 1 commit into
CalloraOrg:mainfrom
Killerjunior:feat/1055-namespace-storage-keys
Open

feat(storage): namespace storage keys across contract modules (#1055)#1094
Killerjunior wants to merge 1 commit into
CalloraOrg:mainfrom
Killerjunior:feat/1055-namespace-storage-keys

Conversation

@Killerjunior

Copy link
Copy Markdown
Contributor

feat(storage): namespace storage keys across contract modules

Closes #1055


Summary

This PR implements a type-safe, production-ready storage key namespacing framework across the entire Callora workspace, resolving [Quality-2][High] Namespace storage keys across contract modules.

Prior to this change, storage keys used by individual contracts had no structural namespace, no explicit ownership semantics, inconsistent TTL/archival policies, and no protection against cross-module state collision. This PR addresses all of that systematically.


Changes

contracts/helpers — Core Framework

  • ContractNamespace#[contracttype] enum covering all workspace contract modules. Each variant uniquely scopes every key written by that module.
  • KeyCategory — Structural classification (Config, State, Accounting, Ephemeral, Idempotency, Migration) with explicit durability mapping (Instance/Persistent/Temporary) and TTL parameters per category.
  • NamespacedKey<K> — Composite tuple key (ContractNamespace, KeyCategory, K) with manual Soroban IntoVal/TryFromVal serialization that is compatible with #[contracttype] restrictions on generic types.
  • KeyOwnershipMarker — Audit trail record capturing namespace, category, optional owner address, creation ledger sequence, and lifecycle timestamps (migration, archival).
  • NamespacedStorage<'a> — Safe storage engine providing instance_*, persistent_*, and temporary_* operations with:
    • Automatic TTL extension on hot reads
    • Explicit idempotency pruning and migration cleanup
    • Multi-tenant isolation guardrails via debug assertions on cross-namespace key access
    • bulk_instance_bump for contract liveness management

All 28 Workspace Contract Crates

  • Added callora-helpers as a dependency in each contract's Cargo.toml
  • Exposed a standardized pub mod ns in each contract's src/lib.rs binding:
    • CONTRACT_NS: ContractNamespace — the module-level namespace discriminant
    • storage(env: &Env) -> NamespacedStorage<'_> — zero-overhead namespace-bound accessor
    • Re-exports of all key construction helpers (config_key, state_key, accounting_key, ephemeral_key, idempotency_key, migration_key)

contracts/tests — Integration Test Suite

Added namespaced_storage.rs to callora-cross-contract-tests with four test cases:

Test Coverage
test_namespaced_storage_lifecycle_and_isolation Fresh writes, hot reads, expiry/cleanup, recovery — all 6 key categories
test_ownership_marker_audit_trail Marker field correctness, describe() output
integrated_contracts_expose_own_namespace All 28 contracts bind the correct CONTRACT_NS
integrated_storage_accessors_bind_matching_namespace All 28 storage(&env) return the correct namespace

Test Results

cargo test --package callora-helpers --package callora-cross-contract-tests

callora-cross-contract-tests: 11 passed; 0 failed
callora-helpers:              22 passed; 0 failed

CI Checklist

  • cargo fmt --all -- --check — clean
  • cargo clippy --package callora-helpers --package callora-cross-contract-tests -- -D warnings — clean
  • All 33 tests pass locally (22 unit + 11 integration)
  • No breaking changes to existing public contract APIs
  • All pub mod ns bindings are additive — no existing code paths touched

…aOrg#1055)

- Add ContractNamespace, KeyCategory, KeyOwnershipMarker, and NamespacedKey to callora-helpers
- Implement NamespacedStorage with TTL management, instance/persistent/temporary durability, and cross-contract isolation
- Expose pub mod ns with module-specific CONTRACT_NS and storage() helper across all 28 workspace contract crates
- Add integration test suite in callora-cross-contract-tests verifying namespace isolation, lifecycle paths, and contract bindings
- Ensure full unit test coverage and local CI verification passes
@drips-wave

drips-wave Bot commented Aug 30, 2026

Copy link
Copy Markdown

@Killerjunior Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Killerjunior

Copy link
Copy Markdown
Contributor Author

Kindly review and merge @greatest0fallt1me

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.

[Quality-2][High] Namespace storage keys across contract modules

1 participant