Skip to content

refactor: migrate reputation score to per-user persistent storage #51

Description

@EmeditWeb

Problem

All reputation scores are stored in a single instance storage Map<Address, u32> (storage.rs lines 27-46). Every score read/write loads/saves the entire Map. For large user bases this will exceed Soroban instance storage size limits.

Contract impact: At scale, the reputation contract will hit instance storage caps and fail to read/write scores for new users.

Before Starting

Read: context/architecture-context.md

Root Cause

Instance storage was used for simplicity during initial implementation.

What To Build

  1. Migrate to per-user persistent storage:
    • Key: DataKey::Score(address)
    • Value: u32 score
    • TTL extension on every write
  2. Keep get_score() interface unchanged
  3. Write a migration test verifying data integrity
  4. Document the storage layout change

Files To Touch

  • contracts/reputation-contract/src/storage.rs — rewrite read_score/write_score
  • contracts/reputation-contract/src/types.rs — add DataKey variant
  • contracts/reputation-contract/src/tests.rs — add migration tests

Acceptance Criteria

  • Scores stored per-user in persistent storage
  • TTL extended on every score write
  • get_score returns same values as before
  • All existing tests pass
  • Scaling test with 1000+ users passes

Mandatory Checks

  • context/ files read
  • cargo build passes
  • cargo test passes
  • PR references this issue

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions