Description
// registry.rs:9-35
pub fn register_contributor(env: &Env, address: &Address, name: &String) -> Result<(), ContractError> {
let mut index = Storage::get_contributor_index(env);
for entry in index.iter() {
if entry.address == *address {
return Err(ContractError::AlreadyRegistered);
}
}
...
index.push_back(entry);
Storage::set_contributor_index(env, &index);
}
Every call loads the entire global contributor index into memory, scans it linearly for a duplicate, then writes the whole (now one-longer) index back to persistent storage. Registration cost grows linearly with the number of prior registrations, making total registration cost across n users O(n²). This scan is also redundant: lib.rs's contributor_register entrypoint already performs an O(1) duplicate check via Storage::get_contributor before calling into register_contributor, so the linear scan here is pure dead weight on top of that.
As the contributor base grows into the thousands, each new contributor_register call becomes progressively more expensive in CPU/read-bytes, eventually risking Soroban's per-invocation resource limits — a scaling liveness issue for new registrations, not a one-off bug.
Technical Requirements
Files to update
contracts/contracts/stellar-grants/src/registry.rs (register_contributor, lines 9-35)
Fix direction
Since lib.rs already does the O(1) duplicate check via Storage::get_contributor before calling this function, remove the redundant linear scan here entirely and rely on the caller's check (or, if this function needs to remain independently safe against duplicate calls, replace the linear scan with the same O(1) Storage::get_contributor lookup instead of scanning the whole index).
Acceptance Criteria
register_contributor no longer performs an O(n) scan over the full contributor index.
- Duplicate registration is still rejected (via the O(1) lookup, whether performed here or relied upon from the caller — document which).
- A test with many pre-existing contributors confirms registering a new one no longer requires reading the entire index.
cargo test passes.
Estimated Effort
Beginner: 3 hours
Intermediate: 1.5 hours
Expert: 1 hour
How to work this issue
- Read
contracts/ContributionGuide.md for the contribution workflow.
- Comment on the issue to claim it before starting.
- Branch:
fix/issue-920-registry-register-contributor-scan.
- Run
cargo fmt, cargo clippy -- -D warnings, cargo test before opening your PR.
- Use a Conventional Commit message, e.g.
perf: remove redundant linear scan from contributor registration.
Before you start
If you find this project interesting, please consider starring the repository on GitHub. It helps the project gain visibility and supports the Drips Wave program that rewards contributors for merged fixes like this one.
Description
Every call loads the entire global contributor index into memory, scans it linearly for a duplicate, then writes the whole (now one-longer) index back to persistent storage. Registration cost grows linearly with the number of prior registrations, making total registration cost across
nusers O(n²). This scan is also redundant:lib.rs'scontributor_registerentrypoint already performs an O(1) duplicate check viaStorage::get_contributorbefore calling intoregister_contributor, so the linear scan here is pure dead weight on top of that.As the contributor base grows into the thousands, each new
contributor_registercall becomes progressively more expensive in CPU/read-bytes, eventually risking Soroban's per-invocation resource limits — a scaling liveness issue for new registrations, not a one-off bug.Technical Requirements
Files to update
contracts/contracts/stellar-grants/src/registry.rs(register_contributor, lines 9-35)Fix direction
Since
lib.rsalready does the O(1) duplicate check viaStorage::get_contributorbefore calling this function, remove the redundant linear scan here entirely and rely on the caller's check (or, if this function needs to remain independently safe against duplicate calls, replace the linear scan with the same O(1)Storage::get_contributorlookup instead of scanning the whole index).Acceptance Criteria
register_contributorno longer performs an O(n) scan over the full contributor index.cargo testpasses.Estimated Effort
Beginner: 3 hours
Intermediate: 1.5 hours
Expert: 1 hour
How to work this issue
contracts/ContributionGuide.mdfor the contribution workflow.fix/issue-920-registry-register-contributor-scan.cargo fmt,cargo clippy -- -D warnings,cargo testbefore opening your PR.perf: remove redundant linear scan from contributor registration.Before you start
If you find this project interesting, please consider starring the repository on GitHub. It helps the project gain visibility and supports the Drips Wave program that rewards contributors for merged fixes like this one.