Skip to content

Conversation

@pyropy
Copy link
Member

@pyropy pyropy commented Sep 25, 2025

Motivation

To support FilBeam's usage-based payment model, this PR adds methods to the FWSS contract for settling CDN payment rails without payment validators

Description

Introduces two new methods:

  • settleCDNPaymentRails - for settling CDN payment rails
  • topUpCDNPaymentRails - for topping up balance in CDN payment rails (increasing fixed lockup)

Adding these two methods would enable usage-based payments for CDN-related payment rails as FilBeam contract would be able to calculate settlement amounts based on the reported egress usage and settle payment rails via settleCDNPaymentRails.

Validator has been removed from CDN-related payment rails as settling is done by FilBeam contract.

Users are be able to increase fixed lockup for their CDN-related payment rails by calling topUpCDNPaymentRails in return increasing their data set egress limit. Initial fixed lockup for CDN payment rails is set to 0 as we're unable to pass lockup amounts via metadata without increasing contract byte size due to addition of helper new functions.

Changelog

  • Remove validator from CDN payment rails
  • Add methods for FilBeam operator contract to settle cdn payment rails
  • Add method for increasing fixed lockup on cdn payment rails topUpCDNPaymentRails
  • Cleanup variables, errors and events related to cdn service termination
  • Remove handling of cdn payment rail termination from railTerminated method

Related to:

- Remove validator from cdn payment rails
- Add fixed lockup during cdn payment rail creation
- Add methods for FilBeam operator contract to settle cdn
  payment rails
- Add method for increasing fixed lockup on cdn payment rails
- Cleanup variables, errors and events related to cdn service
  termination
- Remove handling of cdn payment rail termination from `railTerminated`
  method
@FilOzzy FilOzzy added this to FS Sep 25, 2025
@github-project-automation github-project-automation bot moved this to 📌 Triage in FS Sep 25, 2025
@pyropy pyropy changed the title Modify payment rails and add methods for usage-based payments WIP: Modify payment rails and add methods for usage-based payments Sep 25, 2025
- Replace percentage-based lockup ratios with absolute lockup values
- Remove cdnEndEpoch field from DataSetInfo as CDN rails don't track termination
- Update metadata keys from ratio to value naming convention
- Modify lockup calculation to use provided values directly instead of percentage calculations
- Update test cases to use absolute values instead of percentages
- Add validation for empty lockup value strings
- Support asymmetric and zero lockup values for flexible CDN configuration
… settleCDNPaymentRails method

- Combine two separate settlement methods into one with signature: settleCDNPaymentRails(uint256 dataSetId, uint256 cdnAmount, uint256 cacheMissAmount)
- Consolidates validation logic and reduces code duplication
- Maintains all access control and validation requirements
- Add comprehensive test coverage with 13 test cases covering success scenarios, access control, validation errors, event emission, and payment processing
- Remove specialized _getCDNMetadataKV helper function
- Replace all calls with the more general _getSingleMetadataKV("withCDN", value)
- Simplifies codebase by using existing generic metadata helper
- Remove redundant tests
- Add CDNPaymentRailsToppedUp event and modify top-up tests
@pyropy pyropy changed the title WIP: Modify payment rails and add methods for usage-based payments Modify payment rails and add methods for usage-based payments Oct 1, 2025
@pyropy pyropy marked this pull request as ready for review October 1, 2025 10:30
@pyropy pyropy requested review from ZenGround0, bajtos and juliangruber and removed request for juliangruber October 1, 2025 10:30
@pyropy pyropy self-assigned this Oct 1, 2025
@pyropy pyropy requested review from jennijuju and rvagg October 1, 2025 10:31
@pyropy pyropy requested a review from juliangruber October 6, 2025 13:55
* @param cdnAmount Amount to settle for CDN rail
* @param cacheMissAmount Amount to settle for cache miss rail
*/
function settleCDNPaymentRails(uint256 dataSetId, uint256 cdnAmount, uint256 cacheMissAmount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are discussing this API in the PR adding code that calls this method, let's resolve that thread first:

filbeam/contracts#1 (comment)

Copy link
Contributor

@bajtos bajtos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the discussion around settleCDNPaymentRails API, I think the pull request looks great now!

@github-project-automation github-project-automation bot moved this from ⌨️ In Progress to ✔️ Approved by reviewer in FS Oct 6, 2025
@pyropy pyropy merged commit 8cece67 into main Oct 6, 2025
5 checks passed
@pyropy pyropy deleted the feat/usage-based-payments branch October 6, 2025 15:19
@github-project-automation github-project-automation bot moved this from ✔️ Approved by reviewer to 🎉 Done in FS Oct 6, 2025

event ViewContractSet(address indexed viewContract);

event CDNPaymentRailsToppedUp(uint256 indexed dataSetId, uint256 totalCdnLockup, uint256 totalCacheMissLockup);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need an event for this?

createData.payer, // from (payer)
filBeamBeneficiaryAddress, // to FilBeam beneficiary
address(this), // this contract acts as the arbiter
address(0), // no validator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure? We use this validator to adjust payments according to service uptime. For example for PDP if you aren't proving possession you aren't getting paid. Maybe CDN should have its own validator?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is IValidator(filBeamController) not possible because the controller doesn't have the information yet?

DarkLord017 pushed a commit to DarkLord017/filecoin-services that referenced this pull request Oct 8, 2025
usdfcTokenAddress, // token address
createData.payer, // from (payer)
payee, // payee address from registry
address(this), // this contract acts as the arbiter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this contract is not the rail validator any more, don't need to set railToDataSet for the rail

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wjmelements added a commit that referenced this pull request Oct 10, 2025
Reviewer @rvagg
CC @Chaitu-Tatipamula
Closes #277
Resolves
#269 (review)
We are able to remove this mapping because it is only used by IValidator
functions, and, since
#237, FWSS is not the
IValidator for these rails.

This reduces codesize 23,991 -> 23,898 (-93)
#### Changes
* remove railToDataSet mapping for both cdn rails
pyropy added a commit that referenced this pull request Oct 14, 2025
## Description

This pull request modifies the existing `CDNPaymentRailsToppedUp `event
by adding two new fields: `cdnAmountAdded `and `cacheMissAmountAdded`.
These additions are designed to simplify the tracking of remaining user
egress in the off-chain component.

## Motivation

Following discussions with @bajtos, we identified the need to modify the
`CDNPaymentRailsToppedUp` event signature to streamline our egress
accounting process. Our initial approach involved extending the
`FilBeamOperator` contract with a `topUpCDNPaymentRails` method and
adding authorization to the existing
`FilecoinWarmStorageService.topUpCDNPaymentRails` method. However, I
opted against this approach since these modifications can be implemented
through a contract upgrade instead.

## Changelog

- Add `cdnAmountAdded` and `cacheMissAmountAdded` fields to
`CDNPaymentRailsToppedUp` event
- Refactor tests to match updated event signature

## Related

- filbeam/worker#333
- #237
}

if (cacheMissAmount > 0) {
payments.modifyRailPayment(info.cacheMissRailId, 0, cacheMissAmount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting these rates to zero here is negated by updatePaymentRates. Should we also set the payment rate to zero in there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pyropy PTAL

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was already a fix PR before I noticed this.

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

Labels

None yet

Projects

Status: 🎉 Done

Development

Successfully merging this pull request may close these issues.

6 participants