-
Notifications
You must be signed in to change notification settings - Fork 6
fix: pad rawSize for payment calculations #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix: pad rawSize for payment calculations #251
Conversation
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.
|
how does this look, @SgtPooki? |
src/core/payments/constants.ts
Outdated
| /** | ||
| * 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 | ||
| } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
calculateRequiredAllowances(), supposedly, is the entry point for all the calculate* functions in /core/payments.calling
padSizeToPDPLeavesonce in it, shares that converted value with the rest.closes #213