FilOzone / FilOzone/pdp-explorer
perf(subgraph): remove dead SumTree maintenance from piece handlers
- Dominant language
- TypeScript
- Stars
- 3
- Forks
- 7
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 4
Description
## Problem
`sumTreeAdd` / `sumTreeRemove` run for **every piece** in `handlePiecesAdded` (`subgraph/src/pdp-verifier.ts:1139-1140`) and `handlePiecesRemoved` (`subgraph/src/pdp-verifier.ts:1295-1302`). Each call performs O(log n) `SumTreeCount` entity loads plus at least one write (`subgraph/src/sumTree.ts`).
Nothing consumes this data today:
- The only reader is `findChallengedRoots` in `subgraph/src/pdp-service.ts`, whose `handleFaultRecord` is **not wired into the manifest** — there is no PDPService data source in `subgraph.yaml` or `templates/subgraph.template.yaml`.
- The client never queries `sumTreeCounts`.
So on the hottest backfill path (piece ingest) we pay O(log n) store reads + writes per piece for state that is never read.
## Proposal
1. Decide: is FaultRecord / PDPService support coming back?
- **No / not soon:** delete the `SumTree` calls from both handlers, the `SumTreeCount` entity from `schema.graphql`, and `src/sumTree.ts` (git history preserves it).
- **Yes:** remove the calls now anyway and reintroduce them in the same PR that adds the PDPService data source, so we don't pay the cost while nothing consumes it.
2. Update Matchstick tests accordingly.
## Acceptance criteria
- [ ] No `SumTreeCount` loads/writes during `PiecesAdded` / `PiecesRemoved` handling
- [ ] `graph build` for both networks + tests pass
- [ ] Decision on FaultRecord reintroduction recorded in this issue
- [ ] Remove stale heatmap from subgraph-client
## Notes
Current Heatmap shows no faults at all and this is because FaultRecord/PDPService isn't wired in manifest.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with handlePiecesAdded and handlePiecesRemoved in subgraph/src/pdp-verifier.ts, then inspect subgraph/src/sumTree.ts, schema.graphql, the two manifest files, and the Matchstick tests. Confirm the FaultRecord/PDPService wiring decision and identify the stale heatmap in subgraph-client. Done means no SumTreeCount work on piece handlers, both network builds and tests pass, and the heatmap is removed or updated as specified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- backend, data, testing
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100