fix(cancel_refund): zero entry.net and decrement market totals on refund - #114
Open
esthereze wants to merge 1 commit into
Open
fix(cancel_refund): zero entry.net and decrement market totals on refund#114esthereze wants to merge 1 commit into
esthereze wants to merge 1 commit into
Conversation
After a successful refund, cancel_refund now: - Zeroes entry.net alongside entry.gross (was left stale, causing get_bet to report a non-zero staked amount after the refund) - Decrements market.total_yes or market.total_no by the refunded net amount, keeping market totals consistent with the bet ledger BetEntry already carries both is_yes and net, so no storage-model change is required -- the fix is purely localised to cancel_refund. saturating_sub is used defensively to prevent any underflow edge case. Test added: test_cancel_refund_clears_net_and_market_totals verifies that after cancel_refund both get_bet(amount) == 0 and market totals are decremented to 0 for a two-bettor scenario. Closes SPulse-Org#58
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
Fixes the inconsistency reported in #58 where
cancel_refundzeroedentry.grossbut leftentry.netintact, causingget_betto still report a non-zero staked amount after a refund, and markettotal_yes/total_noto remain inflated.Root cause
cancel_refundonly did:This left
entry.netuntouched, so:get_betreturnedamount: e.net(non-zero) even after the bet was refundedmarket.total_yes/total_nowere never decremented, so market totals were inconsistent with the refunded bet stateFix
BetEntryalready carries bothis_yesandnet, so no storage-model change is required. The fix is entirely localised tocancel_refund:The issue description claimed this was unsolvable without a storage-model change, but that is not the case — per-bet side (
is_yes) and net amount are already stored onBetEntry, making the fix purely local.saturating_subis used defensively to prevent underflow.Changes
prediction_market/src/lib.rs:cancel_refundnow zeroesentry.netand decrements the appropriate market totalprediction_market/src/tests.rs: New testtest_cancel_refund_clears_net_and_market_totalsverifies both invariantsTesting
New test
test_cancel_refund_clears_net_and_market_totalscovers:get_bet(amount)returns 0 aftercancel_refund(was non-zero before fix)market.total_yesandmarket.total_noare both 0 after all bettors have been refunded (were inflated before fix)get_bet_grossstill returns 0 (existing idempotency guard unchanged)Closes #58