Skip to content

feat: share CDN bandwidth rail across a payer's data sets - #527

Draft
juliangruber wants to merge 2 commits into
mainfrom
cdn-shared-bandwidth-rail
Draft

feat: share CDN bandwidth rail across a payer's data sets#527
juliangruber wants to merge 2 commits into
mainfrom
cdn-shared-bandwidth-rail

Conversation

@juliangruber

Copy link
Copy Markdown
Member

What

Lets a client buy the CDN bandwidth service once and share it across multiple data sets, instead of paying for it per data set. This is the core, on-chain part of a cross-repo proposal.

Full proposal, with rationale and the companion changes in the other repos: https://gist.github.com/juliangruber/a34b225f9588ec68d069054d731e20c9

The gist also links to the companion draft PRs in FilOzone/synapse-sdk, filbeam/contracts, and filbeam/worker.

Why

The SDK now does multi-copy upload, a piece is stored in 2 data sets on 2 providers. When withCDN is enabled on both, each data set creates its own CDN bandwidth rail to the same FilBeam beneficiary, so the bandwidth service is bought twice: the 0.7 USDFC lockup is reserved twice and there are two rails for FilBeam to meter against. The bytes are delivered to the end user once, so this duplication is pure cost to the client.

The cache-miss rail is different, its payee is the data set's SP, which differs across the two copies, so it genuinely stays per provider.

How

A CDN subscription is keyed by (payer, groupId), where groupId is an optional value carried in the withCDN metadata entry (its presence was the only thing read before, the value was unused). FWSS maps that key to a single shared bandwidth rail.

  • New storage cdnGroupRail (subscription key to shared cdnRailId) and cdnRailRefCount (members per shared rail), appended at slots 23 and 24.
  • createRails reuses an active shared bandwidth rail when the group key matches, skipping the second rail and its lockup. The first member creates and seeds it. The cache-miss rail is always created per data set.
  • validatePayerOperatorApprovalAndFunds only requires the bandwidth lockup for the first member of a subscription.
  • New settleCDNBandwidthRail(cdnRailId, cdnAmount) settles the shared rail once for the whole subscription. settleFilBeamPaymentRails remains for cache-miss and legacy ungrouped data sets.
  • Teardown (terminateCDNService, dataSetDeleted, abandonment) decrements the ref count and terminates the bandwidth rail only when the last member leaves.

The shared cdnRailId is the subscription identity, so downstream systems aggregate bandwidth by rail id and need no knowledge of group ids.

Compatibility

Purely additive. An empty withCDN value keeps the legacy one-rail-per-data-set behavior, ref counting only engages for grouped data sets. No change to the immutable FilBeam beneficiary and no new signed-message format, the group id is already covered by the EIP-712 creation signature.

Follow-ups

These are intentionally out of scope for this draft.

  • Regenerate the storage-layout JSON and ABIs via the Makefile (the .sol layout binding is updated here, the generated .json artifact is not).
  • Tests for ref-count correctness across the normal-deletion and abandonment teardown paths, and for two data sets in one group sharing a single bandwidth rail.
  • A view getter for cdnRailRefCount / cdnGroupRail if FilBeam wants to read subscription membership on-chain.

Multi-copy upload stores a piece in 2 data sets on 2 providers. With
withCDN on both, the CDN bandwidth service was bought twice. This lets a
client buy it once: the withCDN metadata value carries an optional group
id, FWSS keys a shared bandwidth rail by keccak256(payer, groupId), and
data sets in the same group join one rail instead of creating a second.

The shared cdnRailId is the subscription identity, settled once via the
new settleCDNBandwidthRail(cdnRailId, cdnAmount). The cache-miss rail
stays per data set (its payee is the data set's SP). cdnRailRefCount
tracks members so the bandwidth rail is torn down only at zero across the
termination, deletion, and abandonment paths.

Empty group id keeps the legacy one-rail-per-data-set behavior.
@FilOzzy FilOzzy added this to FOC Jun 15, 2026
@github-project-automation github-project-automation Bot moved this to 📌 Triage in FOC Jun 15, 2026
Run make gen and make update-abi so the checked-in artifacts match the
shared bandwidth rail changes: settleCDNBandwidthRail and the
UnknownCDNBandwidthRail error in the ABIs, and the cdnGroupRail (slot 23)
and cdnRailRefCount (slot 24) mappings in the layout JSON.
@BigLep BigLep moved this from 📌 Triage to ⌨️ In Progress in FOC Jun 15, 2026
@BigLep BigLep moved this from ⌨️ In Progress to 🐱 Todo in FOC Jun 29, 2026
@BigLep BigLep mentioned this pull request Jul 11, 2026
@BigLep

BigLep commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Marked as potential for #534

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🐱 Todo

Development

Successfully merging this pull request may close these issues.

3 participants