fix(prediction_market): extend TTL on read paths and add bump_ttl - #181
fix(prediction_market): extend TTL on read paths and add bump_ttl#181Abdulrasaq1515 wants to merge 3 commits into
Conversation
Extend TTL in every view/read path that touches user-claimable state: - get_payout, get_market, get_bet, get_user_bet_count, get_bet_gross, get_pending_withdrawal now rebump their storage keys on read. Add public bump_ttl(market_id, user) so anyone can refresh a near-expiry BetEntry before it becomes unrecoverable. Emit claim_window_expired event from claim and cancel_refund when the BetEntry is missing so off-chain indexers can alert users. Closes SPulse-Org#174
Muyideen-js
left a comment
There was a problem hiding this comment.
@Abdulrasaq1515, the PR improves TTL handling but does not fully solve the issue. Critical gaps: 1) get_market_state is not updated to extend TTL on read, so frequent queries can still accelerate expiry. 2) get_payout only extends TTL for the Payout key, not the BetEntry, which is the primary claimable state. 3) TTLs are still set at creation time, not relative to resolution_time + 30 days, so markets with long resolution windows remain vulnerable. 4) Missing tests for get_market_state rebump and for TTL set relative to claim window. Please update get_market_state to extend TTL for all relevant keys, ensure get_payout extends TTL for BetEntry, adjust TTL setting logic, and add corresponding tests.
Muyideen-js
left a comment
There was a problem hiding this comment.
@Abdulrasaq1515, the PR adds read-path TTL bumps and a bump_ttl function, but it does not fully solve the issue. The issue explicitly requires setting TTLs relative to the maximum possible claim window (resolution_time + 30 days) at write time. The diff only adds a constant CLAIM_WINDOW_TTL and uses it in refresh_market_keys, but not when initially storing BetEntry or Payout entries. Also, get_payout extends the Bet TTL even when payout is zero, which may be unintended. Please update the write paths (place_bet, resolve_market, cancel_refund, etc.) to set TTLs to CLAIM_WINDOW_TTL or longer, and fix get_payout to only extend Bet TTL when payout is non-zero. Additionally, add tests that simulate actual expiry (by advancing ledgers beyond TTL) rather than manually removing keys, and cover edge cases like missing entries. CI is not run, so please ensure all tests pass.
|
get_market_state — this function doesn't exist in the codebase. The closest equivalent, get_market, already rebumps the Market key TTL on read. No other change needed |
Extend TTL in every view/read path that touches user-claimable state: - get_payout, get_market, get_bet, get_user_bet_count, get_bet_gross, get_pending_withdrawal now rebump their storage keys on read. - get_payout also rebumps the BetEntry TTL. Add public bump_ttl(market_id, user) so anyone can refresh a near-expiry BetEntry before it becomes unrecoverable. Emit claim_window_expired event from claim and cancel_refund when the BetEntry is missing so off-chain indexers can alert users. Set bet/payout TTL relative to claim window at resolve time via CLAIM_WINDOW_TTL constant. Closes SPulse-Org#174
Muyideen-js
left a comment
There was a problem hiding this comment.
@Abdulrasaq1515, the PR addresses some aspects but does not completely solve the issue. Key problems: 1) Extending TTL on read paths is ineffective if the entry has already expired; the issue requires preventing expiry before it happens. 2) The claim_window_expired event is only emitted in claim and cancel_refund, but the issue requires it in get_payout and get_market_state as well. 3) The bump_ttl function cannot recover an expired entry, so it does not prevent permanent loss. 4) TTLs are not set relative to resolution_time + 30 days; they are only changed at write time. 5) The read-accelerated expiry issue is not fully addressed because frequent reads still consume gas without guaranteeing TTL extension. 6) No batch-refresh mechanism or keeper guarantee is provided. Please revise to ensure TTLs are set to cover the full claim window, emit the event in all relevant read paths, and provide a mechanism to prevent expiry before it occurs.
…xpiry tests - Use TTL_HIGH for BetEntry at placement so it survives market life + claim window - Use CLAIM_WINDOW_TTL for Payout entries at resolution - Use CLAIM_WINDOW_TTL for BetEntry updates in claim and cancel_refund - Fix get_payout to only extend BetEntry TTL when payout is non-zero - Add tests that simulate actual expiry by advancing ledgers beyond TTL - Add tests for get_payout extending TTL only when payout > 0 - Keep manual-removal tests for missing-entry edge cases Closes SPulse-Org#174
Extend TTL in every view/read path that touches user-claimable state:
Add public bump_ttl(market_id, user) so anyone can refresh a near-expiry BetEntry before it becomes unrecoverable.
Emit claim_window_expired event from claim and cancel_refund when the BetEntry is missing so off-chain indexers can alert users.
Closes #174