Problem Statement
crates/contracts/core/src/lib.rs::get_dashboard_metrics walks id from 1..=total_campaigns reading each one:
let mut active_campaigns: u64 = 0;
let mut id: u64 = 1;
while id <= total_campaigns {
if let Some(c) = env.storage().persistent().get::<_, Campaign>(&campaign_key(id))
{ if c.active { active_campaigns += 1; } }
id += 1;
}
This is O(N) reads. For platforms with 10,000 campaigns, this is 10,000 reads per view call. Soroban resource limits will exceed under non-trivial calls.
Why it matters
This is in the legacy core contract, but the same logic may propagate to campaign over time. Currently, campaign is single-campaign-per-instance, so the problem is structural in core.
Expected Outcome
Either:
(a) Maintain a separate ActiveCampaignCount storage key, incremented/decremented on status transitions, returning active_campaigns in O(1). Recommended.
(b) Add an explicit pagination cap (e.g., max 256 campaigns per view) so the view call stays within budget.
Acceptance Criteria
- New storage key
ActiveCampaignCount (in core contracts).
create_campaign increments it (campaigns start active).
withdraw / approve may not change the active flag in core; revisit.
get_dashboard_metrics reads the counter in O(1).
- New test asserts increment/decrement behavior.
Implementation Notes
- If
core is being deprecated, this fix may be unnecessary — Issue 17.
Affected Files / Modules
crates/contracts/core/src/lib.rs
Dependencies — Issue 17 (deprecating core simplifies this).
Problem Statement
crates/contracts/core/src/lib.rs::get_dashboard_metricswalksidfrom1..=total_campaignsreading each one:This is O(N) reads. For platforms with 10,000 campaigns, this is 10,000 reads per view call. Soroban resource limits will exceed under non-trivial calls.
Why it matters
This is in the legacy core contract, but the same logic may propagate to
campaignover time. Currently,campaignis single-campaign-per-instance, so the problem is structural incore.Expected Outcome
Either:
(a) Maintain a separate
ActiveCampaignCountstorage key, incremented/decremented on status transitions, returningactive_campaignsin O(1). Recommended.(b) Add an explicit pagination cap (e.g., max 256 campaigns per view) so the view call stays within budget.
Acceptance Criteria
ActiveCampaignCount(incorecontracts).create_campaignincrements it (campaigns start active).withdraw/ approve may not change the active flag in core; revisit.get_dashboard_metricsreads the counter in O(1).Implementation Notes
coreis being deprecated, this fix may be unnecessary — Issue 17.Affected Files / Modules
crates/contracts/core/src/lib.rsDependencies — Issue 17 (deprecating core simplifies this).