Skip to content

Contracts: Migrate participant storage from instance to persistent storage #280

@joelpeace48-cell

Description

@joelpeace48-cell

Summary

The campaign contract stores participant registrations in instance storage using (PARTICIPANT, participant.clone()) as the key. Instance storage in Soroban has a hard size limit of 64KB. A high-traffic campaign with thousands of participants will hit this ceiling and permanently brick the contract, silently failing new registrations.

Problem

In contracts/campaign/src/lib.rs:

let key = (PARTICIPANT, participant.clone());
env.storage().instance().set(&key, &true);

Per Soroban storage docs:

  • Instance storage: shared with contract code, max ~64KB, cheaper TTL management but shared fate
  • Persistent storage: per-key, appropriate for user-keyed data like participant records

Using instance storage for per-user data breaks at scale and makes the entire contract instance fragile.

Acceptance Criteria

  • Migrate all participant record reads/writes to env.storage().persistent() in register() and is_participant()
  • Add extend_ttl for persistent storage keys on each participant registration (with appropriate mainnet values)
  • Keep PARTICIPANT_COUNT in instance storage (it's a single aggregate value, not per-user)
  • Update all tests that verify participant registration to account for the new storage tier
  • Add a test that registers > 100 participants to validate no size limit regression
  • Add CHANGELOG entry and migration note in docs/upgradeability.md

Storage size risk

Each Address in XDR is ~35 bytes. At 64KB instance limit, a campaign caps out at ~1,800 participants — far below what a viral campaign might receive.

References

  • contracts/campaign/src/lib.rs:292-300 (register function storage writes)
  • contracts/campaign/src/lib.rs:332-336 (is_participant storage read)
  • Soroban storage types

Metadata

Metadata

Assignees

Labels

Type

No type
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