Skip to content

fix: replace CampaignApplicants Vec with O(1) ApplicantCount storage - #50

Merged
JamesVictor-O merged 1 commit into
Ads-Bazaar:mainfrom
Suzan-max:fix/applicant-count-storage
Jul 25, 2026
Merged

fix: replace CampaignApplicants Vec with O(1) ApplicantCount storage#50
JamesVictor-O merged 1 commit into
Ads-Bazaar:mainfrom
Suzan-max:fix/applicant-count-storage

Conversation

@Suzan-max

Copy link
Copy Markdown
Contributor

storage::add_campaign_applicant rewrote an ever-growing Vec

on every apply_to_campaign call just to answer a yes/no question in has_campaign_applicants. Replace it with a u32 counter under DataKey::ApplicantCount, matching the existing approved_count pattern on Campaign, so applying costs O(1) storage-writes regardless of how many creators already applied.

Adds a regression test that applies 200+ creators and asserts the storage write cost of a later apply matches an early one, plus that update_campaign_metadata's lock-after-first-application behavior from #38 is unaffected.

Closes #43

storage::add_campaign_applicant rewrote an ever-growing Vec<Address> on
every apply_to_campaign call just to answer a yes/no question in
has_campaign_applicants. Replace it with a u32 counter under
DataKey::ApplicantCount, matching the existing approved_count pattern
on Campaign, so applying costs O(1) storage-writes regardless of how
many creators already applied.

Adds a regression test that applies 200+ creators and asserts the
storage write cost of a later apply matches an early one, plus that
update_campaign_metadata's lock-after-first-application behavior from
Ads-Bazaar#38 is unaffected.
@JamesVictor-O

Copy link
Copy Markdown
Contributor

Merged, nice fix — clean root cause and a genuinely good regression test. Measuring env.cost_estimate().resources().write_bytes before/after 200 applicants to prove O(1) cost, rather than just asserting behavioral equivalence, is exactly the right way to guard against this class of regression sneaking back in.

Verified before merging: fmt, full workspace build, all 64 tests, clippy -D warnings, and the wasm32v1-none release build. Also confirmed via git merge-tree that this combines cleanly with #34 and #49 (both landed after your branch was cut) — no conflicts, no follow-up fix needed. CI is green on main: https://github.com/Ads-Bazaar/ads-bazaar-contract/actions/runs/30163010137

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.

perf: CampaignApplicants storage grows unboundedly for a boolean check

2 participants