Correct storage cost and fee calculations - #946
Open
hugomrdias wants to merge 1 commit into
Open
Conversation
hugomrdias
requested review from
a team,
BigLep,
jennijuju,
rjan90 and
rvagg
as code owners
August 27, 2026 14:21
commit: |
hugomrdias
force-pushed
the
hugomrdias/audit-costs-and-fee-calculations
branch
from
August 27, 2026 14:24
1bf1238 to
0c729da
Compare
hugomrdias
requested review from
BravoNatalie,
Kubuxu and
SgtPooki
and removed request for
a team,
BigLep,
jennijuju and
rjan90
August 27, 2026 14:25
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
synapse-dev | 0c729da | Commit Preview URL Branch Preview URL |
Aug 27 2026, 02:37 PM |
39 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors warm-storage pricing and funding calculations to match on-chain behavior more closely by switching from raw byte totals to PDP leaf-count based sizing and by modeling one-time fees as lifecycle-reserve-funded rather than directly deposit-funded.
Changes:
- Replace
dataSizewithpieceSizesacross SDK/core APIs to correctly model per-piece PDP rounding and per-operation fees. - Add PDP sizing helpers (raw size ↔ leaf count, leaf count → FWSS-priced bytes) plus a shared
calculateUploadCostspure utility used by both single- and multi-context flows. - Update mocks, unit tests, and docs to reflect the new proving fee, lifecycle reserve behavior, and existing-data-set state requirements.
Reviewed changes
Copilot reviewed 42 out of 42 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| utils/example-storage-e2e.js | Update prepare-cost input to pieceSizes for multi-file batching flow |
| packages/synapse-sdk/src/types.ts | Update public SDK types: PrepareOptions.pieceSizes, enrich DataSetInfo with reserve state |
| packages/synapse-sdk/src/test/warm-storage-service.test.ts | Align non-existent data set behavior expectations (null) |
| packages/synapse-sdk/src/test/calculate-multi-context-costs.test.ts | Expand multi-context cost tests for leaf-count sizing + reserve replenishment |
| packages/synapse-sdk/src/storage/manager.ts | Rework multi-context cost aggregation to use leaf counts + lifecycle reserve state and delegate arithmetic to core utility |
| packages/synapse-core/test/pdp-size.test.ts | Add tests for new PDP size utilities |
| packages/synapse-core/test/get-upload-costs.test.ts | Update upload-cost tests for pieceSizes, leaf-based pricing, and reserve-aware deposits |
| packages/synapse-core/test/get-pieces.test.ts | Update dataset mocks to include new reserve-related fields |
| packages/synapse-core/test/get-data-sets-by-id.test.ts | Add test coverage for new getDataSetsById helper |
| packages/synapse-core/test/get-data-set.test.ts | Update “missing dataset” expectation to null |
| packages/synapse-core/test/get-data-set-leaf-counts.test.ts | Replace dataset-size helper tests with leaf-count map helper tests |
| packages/synapse-core/test/get-account-total-storage-size.test.ts | Update total storage size to use FWSS-priced bytes derived from leaf counts |
| packages/synapse-core/test/calculate-upload-fees.test.ts | Update upload-fee tests to depend on pieceSizes validation and pricing |
| packages/synapse-core/test/calculate-upload-costs.test.ts | Add direct tests for the new calculateUploadCosts pure utility |
| packages/synapse-core/test/calculate-lifecycle-reserve-funding.test.ts | Add tests for lifecycle reserve creation/replenishment math |
| packages/synapse-core/test/calculate-effective-rate.test.ts | Update proving fee constant in rate tests |
| packages/synapse-core/test/calculate-deposit-needed.test.ts | Update deposit-needed tests for reserve-funded fees and leaf-count sizing |
| packages/synapse-core/test/calculate-additional-lockup-required.test.ts | Update lockup tests to use leaf-count conversions and pieceSizes |
| packages/synapse-core/src/warm-storage/types.ts | Extend DataSetInfo to include reserve balance and pending one-time payments |
| packages/synapse-core/src/warm-storage/index.ts | Export new warm-storage helpers (calculateLifecycleReserveFunding, getDataSetsById) |
| packages/synapse-core/src/warm-storage/get-upload-costs.ts | Delegate cost arithmetic to calculateUploadCosts; require existing-data-set state |
| packages/synapse-core/src/warm-storage/get-data-sets-by-id.ts | Add multicall helper to fetch datasets indexed by ID (missing -> null) |
| packages/synapse-core/src/warm-storage/get-data-set.ts | Refactor parsing and standardize missing dataset sentinel to null via parseGetDataSet |
| packages/synapse-core/src/warm-storage/get-account-total-storage-size.ts | Sum FWSS-priced approximate sizes using leaf-count conversion |
| packages/synapse-core/src/warm-storage/calculate-upload-fees.ts | Change fee calculation inputs to pieceSizes; simplify fee model to per-call base + per-piece |
| packages/synapse-core/src/warm-storage/calculate-lifecycle-reserve-funding.ts | New helper to model reserve funding/replenishment and final reserve balance |
| packages/synapse-core/src/warm-storage/calculate-effective-rate.ts | Clarify that rate inputs are FWSS-priced aggregate sizes derived from leaf counts |
| packages/synapse-core/src/warm-storage/calculate-deposit-needed.ts | Adapt legacy deposit helper to the shared calculateUploadCosts utility |
| packages/synapse-core/src/warm-storage/calculate-additional-lockup-required.ts | Switch delta computation to leaf-count aggregation + FWSS pricing conversion |
| packages/synapse-core/src/utils/pdp-size.ts | New PDP sizing utilities + pieceSizes validation |
| packages/synapse-core/src/utils/index.ts | Export new upload-cost utility and PDP sizing utilities |
| packages/synapse-core/src/utils/constants.ts | Update leaf-size comment to direct callers to leafCountToRawSize() conversion |
| packages/synapse-core/src/utils/calculate-upload-costs.ts | New shared pure upload cost + funding calculator (single + multi-context) |
| packages/synapse-core/src/pdp-verifier/index.ts | Export new getDataSetLeafCounts helper and stop exporting deprecated size helper |
| packages/synapse-core/src/pdp-verifier/get-dataset-size.ts | Remove deprecated dataset-size helper (bytes) in favor of leaf-count based APIs |
| packages/synapse-core/src/pdp-verifier/get-data-set-leaf-counts.ts | New multicall leaf-count map helper with dedupe + “not live -> 0n” handling |
| packages/synapse-core/src/mocks/jsonrpc/index.ts | Update pricing/fee/lockup mock values (proving fee + lifecycle reserve, etc.) |
| docs/src/content/docs/introduction/about.mdx | Refresh proving fee and lifecycle reserve narrative |
| docs/src/content/docs/getting-started/index.mdx | Update code samples to use pieceSizes |
| docs/src/content/docs/developer-guides/storage/upload-pipeline.mdx | Update prepare example to pieceSizes |
| docs/src/content/docs/developer-guides/storage/storage-costs.mdx | Update pricing/fees tables and add leaf-count sizing explanation |
| docs/src/content/docs/cookbooks/payments-and-storage.mdx | Update cookbook pricing and lifecycle reserve mechanics |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+41
to
+50
| export function validatePieceSizes(pieceSizes: readonly bigint[]): void { | ||
| if (pieceSizes.length === 0) { | ||
| throw new ValidationError('pieceSizes must contain at least one piece') | ||
| } | ||
| for (const size of pieceSizes) { | ||
| if (size <= 0n) { | ||
| throw new ValidationError('pieceSizes must contain only positive byte sizes') | ||
| } | ||
| } | ||
| } |
Comment on lines
+26
to
+28
| * The length of `pieceSizes` determines the per-piece fee and the calculation | ||
| * includes one add-pieces base fee. Execution batch limits are intentionally | ||
| * not enforced here because they are independent of fee calculation. |
Comment on lines
78
to
+81
| console.log('\n--- Preparing Account ---') | ||
| const { costs, transaction } = await synapse.storage.prepare({ dataSize: BigInt(totalSize) }) | ||
| const { costs, transaction } = await synapse.storage.prepare({ | ||
| pieceSizes: files.map((file) => BigInt(file.length)), | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Testing