Description
// analytics.rs:50-59
pub fn category_stats(env: &Env, category_id: u32) -> CategoryStats {
...
// Iterate through tag index to find grants in this category
let grant_ids = Storage::get_tag_index(env, category_id);
...
}
Storage::get_tag_index (storage/helpers.rs, line 927) reads DataKey::Grant(GrantKey::TagIndex(u32)), which is populated only by grant_tags::hash_tag's hash of a freeform tag string — a 32-bit hash value, not a small sequential category id. The correct per-category index is Storage::get_category_index (storage/helpers.rs, line 953), keyed by GrantKey::CategoryIndex(u32), which is exactly what grant_tags::find_by_category correctly uses elsewhere in the codebase.
Since a small integer category_id (0, 1, 2, …) will essentially never collide with a 32-bit tag hash, get_tag_index(category_id) returns an empty list for every real category. Any number of grants can be correctly tagged into a category via grant_tags::tag_grant, but analytics_category_stats(category_id) will always report total_grants = 0, completed_grants = 0, total_funded = 0, success_rate_bps = 0. This also silently breaks build_snapshot's "top category by funding" logic (which calls category_stats internally and picks the category with the highest total_funded, initialized to 0) — top_category_id can never be selected, with no error surfaced to callers.
Technical Requirements
Files to update
contracts/contracts/stellar-grants/src/analytics.rs (category_stats, lines 50-93)
Fix direction
let grant_ids = Storage::get_category_index(env, category_id);
Acceptance Criteria
analytics_category_stats(category_id) correctly reflects grants tagged into that category via grant_tags::tag_grant.
- A test tags several grants into a category, calls
category_stats, and asserts total_grants/total_funded match expectations (nonzero).
build_snapshot's top-category selection works correctly once fed real per-category data.
cargo test passes.
Estimated Effort
Beginner: 2 hours
Intermediate: 1 hour
Expert: 0.5 hours
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-931-analytics-category-index.
- Run
cargo fmt, cargo clippy -- -D warnings, cargo test before opening your PR.
- Use a Conventional Commit message, e.g.
fix: read category index instead of tag index in category_stats.
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
Storage::get_tag_index(storage/helpers.rs, line 927) readsDataKey::Grant(GrantKey::TagIndex(u32)), which is populated only bygrant_tags::hash_tag's hash of a freeform tag string — a 32-bit hash value, not a small sequential category id. The correct per-category index isStorage::get_category_index(storage/helpers.rs, line 953), keyed byGrantKey::CategoryIndex(u32), which is exactly whatgrant_tags::find_by_categorycorrectly uses elsewhere in the codebase.Since a small integer
category_id(0, 1, 2, …) will essentially never collide with a 32-bit tag hash,get_tag_index(category_id)returns an empty list for every real category. Any number of grants can be correctly tagged into a category viagrant_tags::tag_grant, butanalytics_category_stats(category_id)will always reporttotal_grants = 0,completed_grants = 0,total_funded = 0,success_rate_bps = 0. This also silently breaksbuild_snapshot's "top category by funding" logic (which callscategory_statsinternally and picks the category with the highesttotal_funded, initialized to0) —top_category_idcan never be selected, with no error surfaced to callers.Technical Requirements
Files to update
contracts/contracts/stellar-grants/src/analytics.rs(category_stats, lines 50-93)Fix direction
Acceptance Criteria
analytics_category_stats(category_id)correctly reflects grants tagged into that category viagrant_tags::tag_grant.category_stats, and assertstotal_grants/total_fundedmatch expectations (nonzero).build_snapshot's top-category selection works correctly once fed real per-category data.cargo testpasses.Estimated Effort
Beginner: 2 hours
Intermediate: 1 hour
Expert: 0.5 hours
How to work this issue
contracts/ContributionGuide.mdfor the contribution workflow.fix/issue-931-analytics-category-index.cargo fmt,cargo clippy -- -D warnings,cargo testbefore opening your PR.fix: read category index instead of tag index in category_stats.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.