Skip to content

Conversation

@kaf-lamed-beyt
Copy link

calculateRequiredAllowances(), supposedly, is the entry point for all the calculate* functions in /core/payments.

calling padSizeToPDPLeaves once in it, shares that converted value with the rest.

closes #213

calculateRequiredAllowances(), supposedly, is the entry point for all the calculate* functions in /core/payments.

calling padSizeToPDPLeaves once in it, shares that converted with the rest.
@kaf-lamed-beyt
Copy link
Author

how does this look, @SgtPooki?

Comment on lines 61 to 69
/**
* 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
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this shouldn't go in constants.ts it should probably go in a new file: /core/payments/utils.ts

Copy link
Author

Choose a reason for hiding this comment

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

alright. let me update that.

*/
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?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: use padded rawSize for payment calculations

2 participants