Repository navigation
platform_stats: address trust assumption, storage growth, 24h window semantics, and storage_ok invariant - #1196
Merged
Conversation
…ed amount Closes dupdab#1123
…ver in in Closes dupdab#1124
…r-aligned Closes dupdab#1125
…logy — it Closes dupdab#1126
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
platform_stats: address trust assumption, storage growth, 24h window semantics, and storage_ok invariant
What was solved
#1123 — platform_stats::record_payment accepts caller-supplied amount_usd and settled with no on-chain corroboration
The issue asks to address the trust assumption in platform_stats::record_payment, which accepts a caller-supplied amount_usd and settled flag and adds it to TotalSettledVolumeUsd without any on-chain corroboration against settlement_ledger. The suggested fix is either to document the trust assumption explicitly in code or to add a cross-contract call to settlement_ledger::get_settlement to verify the reported amount matches an actual recorded settlement before updating the running total.
Addressed:
#1124 — platform_stats: ActiveBucket entries accumulate forever in instance storage, one per 24h period, never pruned
Fix unbounded instance-storage growth in platform_stats by moving ActiveBucket entries out of instance() storage into persistent() storage with a short TTL that naturally expires once a bucket is no longer current, since stats() only reads the current bucket.
Addressed:
#1125 — platform_stats: active_payments_24h is a fixed ledger-aligned bucket, not a true rolling 24-hour window
Fix the misleading
active_payments_24hsemantics in the platform_stats contract. The field is currently computed from a fixed ledger-sequence-aligned bucket (ledger().sequence() / ACTIVE_WINDOW_LEDGERS), which does not match its name or doc comment implying a rolling 24-hour window. Implement a genuine sliding window by summing the current and previous bucket so activity near a bucket boundary is not immediately dropped, and update the doc comment to accurately describe the semantics.Addressed:
active_payments_24hindabdub_contracts/contracts/platform_stats/src/lib.rsactive_payments_24hso it accurately describes the implemented semantics#1126 — platform_stats::health's storage_ok field is a tautology — it can never report false
Fix the tautological
storage_okfield inplatform_stats::health()so it reports a genuinely falsifiable storage invariant instead of the always-truehas(&DataKey::Admin)check. The fix replaces the check with a verification that the contract's core storage state is internally consistent (e.g. Admin present AND the stats/config keys the contract relies on are present and coherent), so the field can actually reportfalsewhen storage is corrupted or partially initialized.Addressed:
health()indabdub_contracts/contracts/platform_stats/src/lib.rssostorage_okis no longer an unconditional tautology.storage_okmust be derived from a check that can plausibly evaluate tofalse(a real storage invariant), not merelyhas(&DataKey::Admin).SystemHealthstruct shape and thestats()response contract intact unless removal is explicitly required; prefer making the field meaningful over deleting it.Changes
dabdub_contracts/contracts/platform_stats/src/lib.rs(modify)Approach
Issues
Closes #1123
Closes #1124
Closes #1125
Closes #1126