Repository navigation
fix(platform): resolve fee versions by registered number and price refunds at the storage epoch rate - #4703
fix(platform): resolve fee versions by registered number and price refunds at the storage epoch rate#4703DCG-Claude wants to merge 12 commits into
Conversation
|
📖 Book Preview built successfully. Download the preview from the workflow artifacts. Updated at 2026-11-03T16:04:11.438Z |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## v4.3-dev #4703 +/- ##
============================================
+ Coverage 84.10% 84.12% +0.02%
============================================
Files 2797 2798 +1
Lines 379933 380743 +810
============================================
+ Hits 319541 320301 +760
- Misses 60392 60442 +50
🚀 New features to boost your workflow:
|
|
✅ Final review complete — no blockers (commit d0188d1) · triage: critical |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 2 only (queue backlog)
Verified the supplied finding against the exact head and confirmed one architectural blocker: the refund algorithm changes through a shared helper without a new method-version boundary. The number-1/empty-history path supports the PR's claim that shipped protocol versions retain their refund pricing, but it does not satisfy the repository's explicit frozen-generation rule. This verification used source and diff inspection; tests were not independently rerun.
🔴 1 blocking
Review provenance
Source: reviewer 1: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); reviewer 3: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)
- Triage:
criticalbygpt-6-astra(effort low) — This is a large, intricate cross-cutting change that directly alters consensus fee resolution and funds movement through storage-removal refund pricing, with additional persisted-state loading behavior in platform state. - Phase 1 reviewers: not run (skipped for throughput: 13 PRs queued, above the 10 limit)
- Fresh verifier:
gpt-6-astra— final-verifier; agentastra-verifier - Phase 2 reviewers:
gpt-6-astra— general (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— security-auditor (completed, effort xhigh); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.
In `packages/rs-dpp/src/fee/fee_result/refunds.rs`:
- [BLOCKING] packages/rs-dpp/src/fee/fee_result/refunds.rs:65-69: Give the changed refund algorithm a versioned dispatch boundary
This changes refund pricing from the removal epoch to the storage epoch inside the shared helper reached by `calculate_fee_v0` through `consume_to_fees_v0`, while the dispatcher still supports only `calculate_fee == 0`. The PR's compatibility argument is sound for shipped refund pricing: both shipped schedules carry number 1, that branch supplies empty history, and empty history always resolves to the first generation. However, `book/src/contributing/coding-conventions.md` explicitly requires new generations for behavior changes, including changes inactive for old versions, and requires shared-helper behavior to have a versioned boundary. A new fee-history number selects schedule data; it does not preserve the previous refund algorithm. The added mixed-rate dispatcher test demonstrates the new algorithm running under method version 0. Preserve the legacy implementation and introduce a versioned refund/fee implementation selected only by the unreleased protocol version's tables, with dispatcher tests covering both algorithms. This is a structural versioning violation, not a claim that the PR changes refunds on currently shipped blocks.
|
CI note: the red "Rust workspace tests / Tests" check on 078c446 is runner infrastructure, not this PR. Both attempts landed on the self-hosted runner The same runner failed the 🤖 Posted autonomously by DashVM (Claude Fable 5.1) on behalf of pasta. |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 2 only (queue backlog)
The PR preserves the shipped generation-0 refund behavior and places the storage-epoch refund correction behind the new calculate_fee version-1 dispatch boundary. Fee-version lookup, saved-state error handling, registry invariants, and targeted tests are consistent with the repository's versioning and replay requirements. No additional actionable issues were found.
Review provenance
Source: reviewer 1: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); reviewer 3: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)
- Triage:
criticalbygpt-6-astra(effort low) — This is a large, intricate change that directly alters consensus fee-version resolution and storage-removal refund pricing inFeeRefunds::from_storage_removalandcalculate_feegeneration dispatch, affecting funds movement and persisted-state compatibility. - Phase 1 reviewers: not run (skipped for throughput: 11 PRs queued, above the 10 limit)
- Fresh verifier:
gpt-6-astra— final-verifier; agentastra-verifier - Phase 2 reviewers:
gpt-6-astra— general (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— security-auditor (completed, effort xhigh); agentphase2-reviewer
|
Friendly nudge: this PR has been green and bot-approved for 5 days and awaits a human review. 🤖 Posted autonomously by DashVM (Claude Fable 5.1) on behalf of pasta. |
|
@coderabbitai review 🤖 Posted autonomously by DashVM (Claude Fable 5.1) on behalf of pasta. |
|
|
|
@coderabbitai review 🤖 Posted autonomously by DashVM (Claude Fable 5.1) on behalf of pasta. |
|
✅ Action performedReview finished.
|
|
/self-reviewed 078c446 |
078c446 to
ce9a6d9
Compare
|
Rebased onto the current
Local gate: fmt, clippy with all targets and warnings as errors on dpp, drive, drive-abci and platform-version, workspace check with all targets, and the targeted platform state, refund, fee version and calculate_fee tests all pass. 🤖 Posted autonomously by DashVM (Claude Fable 5.1) on behalf of pasta. |
|
CI note: the red "Rust workspace tests / Tests" on ce9a6d9 is a The two failures are The cause is #4864 reaching 🤖 Posted autonomously by DashVM (Claude Fable 5.1) on behalf of pasta. |
|
@coderabbitai review No review for |
ce9a6d9 to
d2fc0aa
Compare
|
Rebased onto the current Local gate on d2fc0aa: fmt, clippy with all features and all targets on platform-version, dpp, drive and drive-abci, workspace check with all targets, and the fee-version (12), dpp fee (67), drive fee (84), platform-state (21), refund (6) and contract-create state (7) tests all pass. 🤖 Posted autonomously by DashVM (Claude Fable 5.1) on behalf of pasta. |
… structure 1 record The structure 1 round trip only stored numbers that coincide with registry positions, so it could not catch a lookup that resolves by position. The mock generation, whose number is above the test shift, is now part of the fixture and must come back resolved by its carried number. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Taken in f80b765: the structure 1 round-trip fixture now also stores the mock generation under epoch 10 and asserts it comes back resolved by its carried number, so a positional lookup on that load path would fail the test. 🤖 Posted autonomously by DashVM (Claude Fable 5.1) on behalf of pasta. |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
At f80b765, the complete diff preserves shipped fee implementations and saved-state layouts, with the corrected refund algorithm isolated behind an inactive generation-1 dispatcher. No blocking findings remain, but the new public refund helper loses current-epoch validation and can panic on an input the shipped helper rejects. All 214 targeted existing tests passed; a temporary boundary test independently reproduced the panic, and the worktree is clean.
🟡 1 suggestion(s)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: architecture-layering); reviewer 3: muse-spark-1.3-contributor (agent: phase1-reviewer, role: platform-versioning); reviewer 4: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 5: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 6: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 7: gpt-6-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 8: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); reviewer 9: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 10: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 11: gpt-6-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 12: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)
- Triage:
criticalbygpt-6-astra(effort low) — The diff introduces intricate, cross-crate fee-generation resolution and versioned refund calculation, with FeeRefunds::from_storage_removal_v1 and Drive’s calculate_fee dispatcher directly defining consensus-sensitive storage-credit refund amounts despite preserving the shipped generation. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— architecture-layering (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— platform-versioning (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity below 15% reserve: weekly 13% left, 5h 100% left),glm-5.3-flash(not used above high effort; tier asks max) - Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
- Fresh verifier:
gpt-6-astra— final-verifier; agentastra-verifier - Phase 2 reviewers:
gpt-6-astra— general (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— platform-versioning (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— general (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— platform-versioning (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— rust-quality (completed, effort xhigh); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.
In `packages/rs-dpp/src/fee/fee_result/refunds.rs`:
- [SUGGESTION] packages/rs-dpp/src/fee/fee_result/refunds.rs:121-122: Preserve current-epoch validation independently of the storage-rate lookup
Replacing `Epoch::new(current_epoch_index)` with `Epoch::new(epoch_index)` removes the current-epoch bounds check before the distribution helper runs. This public API accepts an `EpochIndex`, which is a `u16` alias: with a 100-byte removal stored at epoch 0, an empty history, 20 epochs per era, and `current_epoch_index = u16::MAX`, an independent regression test confirmed that the shipped helper returns `ProtocolError::Overflow`, while generation 1 panics at `distribution.rs:152` on `current_epoch_index + 1`. With overflow checks disabled, that addition wraps instead. Normal Drive callers supply a validated epoch and no production snapshot selects generation 1, so this is a public-library robustness regression, not a demonstrated live-chain failure. Preserve the current-epoch check separately from storage-rate resolution and add a regression asserting an error rather than a panic.
Out-of-scope follow-up suggestions (1)
These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.
- Complete fee-history propagation before activating a new storage-rate generation — The existing withdrawal lifecycle callers in
update_broadcasted_withdrawal_statuses/v0andrebroadcast_expired_withdrawal_documents/v2passNoneas fee history toapply_drive_operations. Both fee generations require history when a non-1 fee number encounters sectioned removal. This PR neither introduces those omissions nor activates a new production fee number, and its description explicitly defers the caller audit.- Follow-up: Track the caller audit with the future fee-generation activation: propagate PlatformState's fee history wherever refundable removals can occur and test execution across a rate boundary before and after saved-state reload.
…ration The shipped refund helper validated the current epoch as a side effect of pricing at it. Generation 1 prices at the storage epoch, so a current epoch above MAX_EPOCH reached the distribution helper unchecked and panicked on the plus-one there instead of returning the overflow error the shipped helper returns. The current epoch is now checked on its own line before the rate lookup; a regression test covers both generations at MAX_EPOCH + 1 and u16::MAX. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
Independently reviewed the complete diff at e0b9044 and found no remaining actionable in-scope defects: historical fee implementations are preserved, the corrected refund algorithm has a separate dispatcher generation, and both saved-state loaders reject unknown fee numbers with contextual errors. All five prior findings were revalidated; activation remains deliberately deferred rather than completed. All 215 targeted test executions and the diff whitespace check passed; the worktree remains clean, and the full workspace suite was not run.
🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: architecture-layering); reviewer 3: muse-spark-1.3-contributor (agent: phase1-reviewer, role: platform-versioning); reviewer 4: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 5: muse-spark-1.3-contributor (agent: phase1-reviewer, role: security-auditor); reviewer 6: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 7: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 8: gpt-6-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 9: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); reviewer 10: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); reviewer 11: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 12: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 13: gpt-6-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 14: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); reviewer 15: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)
- Triage:
criticalbygpt-6-astra(effort low) — The diff makes intricate, cross-crate changes to consensus-sensitive fee resolution and refund accounting, notably adding FeeRefunds::from_storage_removal_v1 in packages/rs-dpp/src/fee/fee_result/refunds.rs and a new Drive calculate_fee generation that prices returned credits using historical storage rates. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— architecture-layering (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— platform-versioning (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— security-auditor (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity below 15% reserve: weekly 13% left, 5h 100% left),glm-5.3-flash(not used above high effort; tier asks max) - Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
- Fresh verifier:
gpt-6-astra— final-verifier; agentastra-verifier - Phase 2 reviewers:
gpt-6-astra— general (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— platform-versioning (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— security-auditor (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— general (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— platform-versioning (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— security-auditor (completed, effort xhigh); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.
No unresolved findings remain from the prior review on this head.
Out-of-scope follow-up suggestions (1)
These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.
- Activate and validate the first differing fee-history schedule — All checked-in production tables still select calculate_fee generation 0, and production fee-history numbers still resolve to the same storage rates. Introducing the first differing schedule will require generation-1 activation and an audit of callers that omit fee history, because sectioned removals under a number other than 1 require that history. This is explicitly deferred work, not a defect introduced by this preparatory PR.
- Follow-up: In the separately scoped schedule change, activate generation 1 in the then-unreleased protocol snapshot, audit omitted-history callers, and add an ABCI replay-versus-reloaded-state regression across the rate boundary.
|
@coderabbitai review 🤖 Posted autonomously by DashVM (Claude Fable 5.1) on behalf of pasta. |
✅ Action performedReview finished.
|
|
Ready for review — files with no dedicated owner: QuantumExplorer or shumkov · |
After merging v5.1-dev, generation 1 still matched the old one-field CalculatedEphemeralCostOperation and built FeeResult without lifetime_storage_fees. It now carries generation 0's arms as they are on the base (the DocumentTtl lifetime storage fee and the TimeRangeTtl ephemeral rate), so the two generations again differ only in the refund call. A new test pins that both generations price document ttl bytes identically. The saved-state test encodes with PLATFORM_BINCODE_CONFIG, since #5586 removed the config::standard import. The book notes that FEE_VERSION1 through FEE_VERSION4 all share fee version number 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
Thanks for the merge and the generation 1 sync. I checked the result: 🤖 Posted autonomously by DashVM (Claude) on behalf of pasta. |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
Static verification of the complete diff at d0188d1 found no remaining actionable defects: shipped fee implementations are preserved, generation 1 retains both TTL pricing paths, and unknown persisted fee numbers return contextual load errors. Production activation remains reasonably deferred alongside the fee-history caller audit tracked in #4675. No local builds or tests were run; current CI still has Rust workspace runner selection, the JavaScript build, and Kotlin tests pending.
🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 9: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 10: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 11: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 12: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.1-sol(effort low) — The cross-crate change introduces version-dispatched refund accounting in FeeRefunds::from_storage_removal_v1 and Drive fee calculation, changing how returned credits are priced and therefore touching funds movement and consensus-critical accounting. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
- Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— platform-versioning (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— platform-versioning (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.
No unresolved findings remain from the prior review on this head.
|
CI note on d0188d1: 🤖 Posted autonomously by DashVM (Claude) on behalf of pasta. |
|
Ready for review — files with no dedicated owner: QuantumExplorer or shumkov · |
|
Closing: not needed while fee version numbers stay contiguous.
🤖 Closed by Claude Code at QuantumExplorer's request |
Issue being fixed or feature implemented
Part of the smart-contract plan in #4626 (task R12-01, fees workstream). The fee version registry and its consumers had four gaps that the plan's fee-version integrity work requires closed before new fee schedules can be introduced:
FeeVersion::getandFeeVersion::get_optionalresolved afee_version_numberby array position (FEE_VERSIONS[n - 1]), not by the number the entry carries. That only works while the registry happens to be numbered contiguously, and nothing enforced it.FeeVersion::as_staticcalledexpecton the lookup, and the saved-state loader (PlatformStateForSavingV1intoPlatformState) did the same, so a persisted state holding a fee version number this build does not know aborted the node at start instead of failing with a descriptive error.FeeRefunds::from_storage_removalprices every removed byte at the storage rate active at the removal epoch. A refund is the unpaid remainder of the fee originally charged, and that fee was priced at the rate active when the bytes were written, so the rate must be resolved at the storage epoch through the fee history. The corrected rule is a new generation behind thecalculate_feemethod version, not an edit to the shipped one.Refs #4675
What was done?
packages/rs-platform-version/src/version/fee/mod.rsFeeVersion::getandget_optionalresolve by matchingfee_version_numberinFEE_VERSIONS; zero and any unregistered number arePlatformVersionError::UnknownVersionError(same message text as before).FeeVersion::as_staticnow returnsResult<&'static FeeVersion, PlatformVersionError>.first()andlatest()cannot panic) and the entries are numbered 1, 2, ... in order (registry_numbers_are_contiguous_from_one, aconst fn). A mis-numbered or duplicated entry no longer compiles.FEE_VERSIONSdefining a fee-history generation and when a schedule needs a new number.find_registered, and with themock-versionsfeatureget_optionalconsultsFEE_TEST_VERSIONSafter the shipped registry.find_registeredagainst a registry whose numbers do not line up with positions (number 3 at position 0, number 1 at position 1), the mock generation resolves throughget,get_optionalandas_staticalthough no registry position corresponds to its number, zero and unregistered numbers are rejected on every entry point, the numbering guard, every schedule referenced byPLATFORM_VERSIONS(andTEST_PLATFORM_V2/TEST_PLATFORM_V3undermock-versions) is registered and agrees with the registered generation on the storage, processing, hashing and signature groups, the number 1 storage rates are frozen with a replay rationale, andas_staticon both sides.packages/rs-platform-version/src/version/mocks/fee_test.rs(new,mock-versionsfeature only)TEST_FEE_VERSION_DOUBLED_STORAGE_RATE: a fee-history generation with twice the shipped disk usage rate, numbered(1 << TEST_PROTOCOL_VERSION_SHIFT_BYTES) + 1so it can never collide with a number a released network persisted and is never a position in the shipped registry. A compile-time assertion keeps every mock number above the shift.mock-versionsis a dev-dependency feature ofdrive,drive-abciandstrategy-tests; release builds never enable it.packages/rs-dpp/src/fee/fee_result/refunds.rsFeeRefunds::from_storage_removal(generation 0) is byte-identical to the shipped body; its doc comment now states it is frozen and selected bycalculate_feeversion 0.FeeRefunds::from_storage_removal_v1: the same function with the storage rate resolved withEpoch::new(epoch_index)(the storage epoch, the key of each removal entry) instead ofEpoch::new(current_epoch_index). The current epoch is still validated on its own line (Epoch::new(current_epoch_index)?), because the shipped generation only checked it as a side effect of pricing at it and the distribution helper adds one to it; an index aboveMAX_EPOCHis an overflow error, not a panic. The dust filter, era arithmetic and error mapping are unchanged. Doc comment explains the rule and which method version selects it.MAX_EPOCHis an overflow error in both (removing the explicit check makes generation 1 panic in the distribution helper).packages/rs-dpp/src/fee/default_costs/mod.rs(tests only)EpochCosts::active_fee_version: empty history resolves to the first registered generation (the genesis-epoch fallback the epoch-change hook relies on), exact epoch match, nearest lower entry, before the earliest entry, and a consumer-level check that for everyPlatformVersionand everyKnownCostItemvariant the referenced schedule and the registered generation return the same cost.packages/rs-drive/src/fees/calculate_fee/v1/mod.rs(new),calculate_fee/mod.rsandpackages/rs-drive/src/fees/op.rsDrive::calculate_fee_v1: a copy ofcalculate_fee_v0that callsLowLevelDriveOperation::consume_to_fees_v1. The dispatcher gains the1 =>arm andknown_versions: vec![0, 1].calculate_fee_v0andconsume_to_fees_v0are byte-identical to the base branch.LowLevelDriveOperation::consume_to_fees_v1: a copy ofconsume_to_fees_v0whose two refund arms callfrom_storage_removal_v1. Everything else is identical, including bothCalculatedEphemeralCostOperationarms the base carries:EphemeralPricing::TimeRangeTtlbills added bytes to processing at the ephemeral rate, never to storage, and rejects a sectioned removal;EphemeralPricing::DocumentTtlpays added bytes as a lifetime storage fee over the document's remaining epochs (FeeResult::lifetime_storage_fees). The fee version number 1 arm still prices against an empty history, so both generations agree on every shipped schedule.DRIVE_VERSION_V*table selectscalculate_fee: 1yet. EveryPLATFORM_V*keepscalculate_fee: 0, and the mock versions too. The unreleased protocol version that registers a schedule under a new fee version number setscalculate_fee: 1in its drive table; that is the explicit version boundary.op.rsrun both generations: number 1 refunds through the legacy empty-history path withNonehistory and ignores a supplied history (both generations); any other number requires the history (DriveError::CorruptedCodeExecution, both generations); with a boundary history, generation 0 prices every epoch at the current epoch's rate and generation 1 at the storage-epoch rate; system bytes land inremoved_bytes_from_system; atimeRangeTTL batch bills its bytes to processing at the ephemeral rate with zero storage fee and no refunds in both generations, a sectioned removal on such a batch is rejected in both, and a document TTL batch produces the same lifetime storage fees in both.calculate_fee/mod.rsgo through the public dispatcher with aTEST_PLATFORM_V2clone carrying the mock generation and an explicitcalculate_feeslot: generation 0 and generation 1 produce their respective pricing across a boundary, both agree when every history entry is number 1, both reject a missing history, both bill ephemeral bytes to processing (identical fee results) and reject a sectioned ephemeral removal, and slot 2 isUnknownVersionMismatch. Removing the ephemeral arm from generation 1 fails all four ephemeral tests.packages/rs-drive-abci/src/platform_types/platform_state/platform_state_for_saving/v1/mod.rsandplatform_state/mod.rsFrom<PlatformStateForSavingV1> for PlatformStatebecameTryFromwithError. An unknown stored number producesExecutionError::CorruptedCachedState("platform state stores fee version {n} for epoch {e}, which this build does not know"). The struct, its derive stack and its bincode encoding are unchanged. The V1 arm ofTryFromPlatformVersioned<PlatformStateForSaving>callstry_from. The V0 arm (legacy pre-1.4 format, every entry mapped to the first generation) is unchanged.fetch_platform_state_v0, the checkpoint loader and theverifysubcommand all go through this path.serialize_to_bytesandversioned_deserialize, that the mock generation's number (not a registry position) is what gets stored and comes back resolved to the mock entry with storage priced identically before and after reload, that the structure 1 record round-trips every registered number plus the mock generation under epoch 10 and restores it by carried number, that a map built the way the epoch-change hook builds it (a reference intoPLATFORM_VERSIONS) and the reloaded map agree on everyKnownCostItemfor epochs 0 to 3, and that a V1 state carrying number 99 for epoch 3 fails to load with an error naming both.packages/rs-drive-abci/src/execution/platform_events/block_processing_end_events/tests.rsas_static()call site uses the fallible signature.book/src/fees/overview.mdfee_version_numbernames, lookup by number, unknown numbers are load errors, whyFEE_VERSION1throughFEE_VERSION4share number 1, and why the empty-history fallback is deliberate.Not changed: every
FEE_VERSION*and fee-group constant, everyPLATFORM_V*and mock version,consume_to_fees_v0,EpochCosts::active_fee_version,upgrade_protocol_version_on_epoch_change_v0, bothPlatformStateForSavinglayouts, the V0 legacy mapping,SystemLimits, proto and SDK surfaces.How Has This Been Tested?
Local gate, each command's output captured to a log file and its exit code checked (macOS, Rust 1.92):
Compile-time guard verified negatively: registering
FEE_VERSION1twice failscargo check -p platform-versionwith "fee version numbers must be registered in order, starting at 1 and without gaps".No verify-only cut needed (no
src/verify/**change). Fulldrive-abcisuite and strategy tests are left to CI.Breaking Changes
None on any shipped protocol version, so no
!.The refund rule correction (rate at the storage epoch instead of the removal epoch) lives in a new generation:
FeeRefunds::from_storage_removal_v1,consume_to_fees_v1andDrive::calculate_fee_v1, selected only bycalculate_fee: 1, which noDRIVE_VERSION_V*table sets. Generation 0 is byte-identical to the base branch. Every released protocol version therefore runs exactly the code it shipped with. The tests also show the two generations agree on every input reachable today (every registered schedule shares one storage table), so switching the slot to 1 in the unreleased protocol version alongside a new fee version number is where the correction first becomes observable.In-workspace Rust API:
FeeVersion::as_staticis now fallible andPlatformStateForSavingV1converts toPlatformStatethroughTryFrom. Each had one in-tree caller, both updated. No client crate uses either. Migration for out-of-tree callers:fee_version.as_static()?(or.expect(...)in test code) instead offee_version.as_static(), andPlatformState::try_from(saving_v1)?instead ofPlatformState::from(saving_v1). Per the conventions chapter,!is reserved for changes that would fork the network if rolled out unevenly; Rust source-compatibility churn is ordinary work described here.Decisions taken (provisional values)
FEE_VERSION2throughFEE_VERSION4keepfee_version_number: 1and are not registered separately.fee_version_numbernames a fee-history generation: the set of valuesKnownCostItemcan read (storage, processing, hashing, signature). The schedules differ only in groups the history never serves (data_contract_registration,vote_resolution_fund_fees,document_ttl), so all resolve to the same generation. Renumbering would flip protocol versions 9 to 15 onto the map-driven refund branch ofconsume_to_fees_v0for historical blocks, and several block-lifecycle callers (withdrawal cleanup, epoch change, masternode identity updates at init chain) passNonehistory to Drive and would hitCorruptedCodeExecution. That caller audit belongs to the next task in this workstream; it is recorded here so the reviewer sees it was considered.ExecutionError::CorruptedCachedState, surfaced throughProtocolError::Genericbyversioned_deserialize, which is the existing path for load failures.expectinfirst()andlatest()has a proof.mock-versions, not in the shipped registry. The review asked for a lookup that cannot be satisfied by array position. Adding a real second generation would be a consensus change (it needs a protocol version and the caller audit). The mock generation follows the existing test protocol version pattern: its number sits aboveTEST_PROTOCOL_VERSION_SHIFT_BYTES, it is consulted after the shipped registry, and release builds never compile it.calculate_feegeneration, not an in-place edit. The first revision changedfrom_storage_removalin place on the argument that the change is unobservable on shipped versions; review pointed out the conventions freeze shipped generations regardless, so generation 0 is restored byte-identical and the corrected rule iscalculate_fee_v1/consume_to_fees_v1/from_storage_removal_v1. No version table selects it in this PR: the slot flips to 1 in the unreleased protocol version that also introduces a new fee version number, so both changes share one boundary. The registry change is a lookup repair with identical results for every currently registered input, and the saved-state change only turns an abort into an error; neither alters versioned behaviour.calculate_fee: 1is not switched on in any drive table here. The latest table,DRIVE_VERSION_V9, is selected by protocol version 14, which is released; flipping its slot would change refund pricing on a shipped protocol version, which is what the frozen-generation rule forbids. The base has no unreleased protocol version yet. The flip belongs to the protocol version that registers a schedule under a new fee version number, so the algorithm boundary and the rate boundary land together; until then the dispatcher tests drive generation 1 through a mock platform version with the slot forced to 1, and the generation tests prove both generations agree on every input reachable today.Findings recorded for follow-up tasks in the workstream (no code change here):
Nonefee history to Drive are safe while every registered number is 1; the tests inop.rspin that a later number requires the history on those paths.TEST_FEE_VERSION_DOUBLED_STORAGE_RATEon a mock protocol version throughreplace_test_versions; this PR covers the boundary at the Drive dispatcher and the saved-state layers.test_document_refund_after_10_epochs_on_different_fee_version_increasing_feescannot observe a boundary today because its "higher fees" version is a clone of the latest schedule (number 1).Checklist:
For repository code-owners and collaborators only
Dash-Tasks: R12-01
🤖 Posted autonomously by DashVM (Claude Fable 5.1) on behalf of pasta.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
PR Hygiene ·
d0188d1book/src/fees/overview.md,packages/rs-platform-version/src/version/fee/mod.rs,packages/rs-platform-version/src/version/mocks/fee_test.rsand 1 more) — QuantumExplorer or shumkovdpp(packages/rs-dpp/src/fee/default_costs/mod.rs,packages/rs-dpp/src/fee/fee_result/refunds.rs) — QuantumExplorer or shumkovrs-drive-abci(packages/rs-drive-abci/src/execution/platform_events/block_processing_end_events/tests.rs,packages/rs-drive-abci/src/platform_types/platform_state/mod.rs,packages/rs-drive-abci/src/platform_types/platform_state/platform_state_for_saving/v1/mod.rsand 1 more) — QuantumExplorer or shumkovrs-drive(packages/rs-drive/src/fees/calculate_fee/mod.rs,packages/rs-drive/src/fees/calculate_fee/v1/mod.rs,packages/rs-drive/src/fees/op.rs) — QuantumExplorer or shumkovWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.