Skip to content

Replace offset-based active piece pagination with getActivePiecesByCursor #848

Description

@BravoNatalie

Description

synapse-core currently exposes and uses getActivePieces(setId, offset, limit) for active piece pagination, but this path becomes impractical on large data sets. In PDPVerifier, getActivePieces has O(offset) gas complexity because it always iterates from piece ID 0. For deep pages, read calls can fail with out-of-gas errors even though the data set is live and the call is otherwise valid.

The contract already includes getActivePiecesByCursor(setId, startPieceId, limit), which is designed for O(limit) pagination and works correctly for the same data sets where offset-based pagination fails. However, this function is not currently exported by synapse-core, which forces downstream consumers onto the more expensive path.

Proposed solution

Add a getActivePiecesByCursor export to @filoz/synapse-core/pdp-verifier and update internal or downstream pagination flows to prefer it over getActivePieces.

Done criteria

  • synapse-core exports getActivePiecesByCursor from @filoz/synapse-core/pdp-verifier
  • The helper includes a typed call builder and parsed return shape consistent with existing read helpers
  • Offset-based pagination usage is replaced with cursor-based pagination in the relevant active-piece listing
    flow(s)
  • Tests cover first-page and subsequent-page cursor pagination behavior
  • Docs or examples note that getActivePieces is O(offset) and getActivePiecesByCursor should be preferred for
    large data sets

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
🐱 Todo

Relationships

None yet

Development

No branches or pull requests

Issue actions