Skip to content

feat(subgraph): track payment-active state for cheaper anon-retrieval queries#582

Draft
dennis-tra wants to merge 1 commit into
FilOzone:mainfrom
probe-lab:feat/subgraph/payment-termination-tracking
Draft

feat(subgraph): track payment-active state for cheaper anon-retrieval queries#582
dennis-tra wants to merge 1 commit into
FilOzone:mainfrom
probe-lab:feat/subgraph/payment-termination-tracking

Conversation

@dennis-tra
Copy link
Copy Markdown
Contributor

@dennis-tra dennis-tra commented May 29, 2026

The subgraph part of #579
The backend part is here probe-lab#12 and depends on #487 to land first.

Why

In the pending retrieval anon implementation why draw candidate pieces by running multiple attempts and then hoping that we draw a pieces whose payment hasn't terminated yet. The reason for this is that we'd need to pass the current epoch to the query to filter the result set server side which isn't available. Secondly, we'll get served the current epoch together with the query result but cannot make use of that field during the querying process so we can only apply the filter condition after we got served the data.

What

In this PR we add a callback to the subgraph code that fires on every block (handleBlock) which "cleans up" all datasets that have expired at that epoch by setting a new isPaymentActive flag to false. The rest of the code is just bookkeeping of that flag as a response to various events.

How it is maintained:

  • PDPPaymentTerminated with future endEpoch schedules the dataset into a PendingPaymentTermination bucket keyed by epoch; if endEpoch is already past, the flag flips immediately.
  • A new handleBlock attached to the FWSS data source loads the bucket for the current block (O(1) load returning null in the steady state) and flips matching datasets to isPaymentActive: false.
  • ServiceTerminated also flips the flag and unschedules from the bucket.
  • Re-extension (a new PDPPaymentTerminated after a prior epoch elapsed) sets the flag back to true and reschedules.

Backwards compatible: pdpPaymentEndEpoch stays on the schema unchanged and is still populated. Existing clients comparing it to the current epoch keep working; new clients can use the cheaper isPaymentActive filter instead.

Deployment

Deployed new version of this subgraph to:

I've also reset the version to 0.1.0 because I've deployed them into a new Goldsky account which I'll plan to hand over to FilOZ.

… queries

Add `DataSet.isPaymentActive: Boolean!` and maintain it from FWSS events plus
a per-block handler, so anon-retrieval can filter expired PDP payments at the
subgraph layer instead of pulling candidates and re-checking client-side.

How it is maintained:
- `PDPPaymentTerminated` with future endEpoch schedules the dataset into a
  `PendingPaymentTermination` bucket keyed by epoch; if endEpoch is already
  past, the flag flips immediately.
- A new `handleBlock` attached to the FWSS data source loads the bucket for
  the current block (O(1) load returning null in the steady state) and flips
  matching datasets to `isPaymentActive: false`.
- `ServiceTerminated` also flips the flag and unschedules from the bucket.
- Re-extension (a new PDPPaymentTerminated after a prior epoch elapsed) sets
  the flag back to true and reschedules.

Backwards compatible: `pdpPaymentEndEpoch` stays on the schema unchanged and
is still populated. Existing clients comparing it to the current epoch keep
working; new clients can use the cheaper `isPaymentActive` filter instead.
@FilOzzy FilOzzy added this to FOC May 29, 2026
@github-project-automation github-project-automation Bot moved this to 📌 Triage in FOC May 29, 2026
@BigLep BigLep moved this from 📌 Triage to ⌨️ In Progress in FOC May 30, 2026
@BigLep BigLep added this to the M4.5: GA Fast Follows milestone Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ⌨️ In Progress

Development

Successfully merging this pull request may close these issues.

3 participants