Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/core/payments/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ export const BUFFER_DENOMINATOR = 10n
*/
export const STORAGE_SCALE_MAX = 10_000_000
export const STORAGE_SCALE_MAX_BI = BigInt(STORAGE_SCALE_MAX)

/** PDP Leaf Size - the payment rate is based on `rawSize` bytes rounded up to the next multiple of 32.
*
* @see - https://github.com/FilOzone/synapse-sdk/issues/339#issue-3539254596
*/
export const PDP_LEAF_SIZE = 32
4 changes: 3 additions & 1 deletion src/core/payments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
} from './constants.js'
import { applyFloorPricing } from './floor-pricing.js'
import type { PaymentStatus, ServiceApprovalStatus, StorageAllowances, StorageRunwaySummary } from './types.js'
import { padSizeToPDPLeaves } from './utils.js'

// Re-export all constants
export * from './constants.js'
Expand Down Expand Up @@ -826,7 +827,8 @@ export function calculateDepositCapacity(
* @returns Required allowances for the piece
*/
export function calculateRequiredAllowances(pieceSizeBytes: number, pricePerTiBPerEpoch: bigint): StorageAllowances {
const storageTiB = pieceSizeBytes / Number(SIZE_CONSTANTS.TiB)
const paddedSizeBytes = padSizeToPDPLeaves(pieceSizeBytes)
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are a lot of other places where we use pieceSizeBytes.

your util function is correct, but I'm worried we're missing a few places.. this might need to wait until we clean up src/core/payments

Copy link
Author

@kaf-lamed-beyt kaf-lamed-beyt Nov 20, 2025

Choose a reason for hiding this comment

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

sounds, good.

let me find some of them while you're doing the cleanup. what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

sounds good @kaf-lamed-beyt. ill be pushing some cleanup PRs today

const storageTiB = paddedSizeBytes / Number(SIZE_CONSTANTS.TiB)
return calculateStorageAllowances(storageTiB, pricePerTiBPerEpoch)
}

Expand Down
11 changes: 11 additions & 0 deletions src/core/payments/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { PDP_LEAF_SIZE } from './constants.js'

/**
* Pad raw size to the next multiple of 32 bytes
*
* @param rawSizeBytes - The actual size in bytes
* @returns Padded size (next multiple of 32)
*/
export function padSizeToPDPLeaves(rawSizeBytes: number): number {
return Math.ceil(rawSizeBytes / PDP_LEAF_SIZE) * PDP_LEAF_SIZE
}