fix: invalidate full cache key set after write handlers commit - #946
Merged
fejilaup-cloud merged 1 commit intoAug 28, 2026
Merged
Conversation
Write handlers (transfer_ip, accept_swap, reveal_key, cancel_swap, cancel_expired_swap) invalidated only the single record key before the RPC write, leaving owner/seller/buyer list caches stale and opening a read-repopulate race once get_ip/get_swap are wired to RPC (AtomicIP#37, AtomicIP#46). Add compound invalidate_ip/invalidate_swap helpers covering the record plus list prefixes, call them post-write in every write handler, and reuse them in invalidate_on_contract_event. reveal_key also clears the reputation cache since a completed swap updates both parties' scores. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
|
@Prasiejames Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Closes #849
Closes #850
Closes #851
Closes #852
Summary
The Redis-backed cache (#786) sits in front of the read handlers (
get_ip,get_swap,list_ip_by_owner, ...), but the write handlers (transfer_ip,accept_swap,reveal_key,cancel_swap,cancel_expired_swap) invalidated only the single record key and did so before the write. Both defects become correctness bugs the moment reads are wired to Soroban RPC (#37, #46) and start repopulating the cache from chain state:ip:list:*); accept/reveal/cancel change seller/buyer list membership (swap:seller:*,swap:buyer:*). Only theip:{id}/swap:{id}keys were cleared, so cached list pages served stale results for the full TTL (30–60s).Changes
api-server/src/cache.rsinvalidate_ip(ip_id)helper — clearsip:{id}+ allip:list:*pages.invalidate_swap(swap_id)helper — clearsswap:{id}+swap:seller:*+swap:buyer:*pages.invalidate_on_contract_eventnow delegates to these helpers (behavior unchanged — event-driven invalidation is inherently post-commit).api-server/src/handlers.rstransfer_ip→invalidate_ip(ip_id)after the RPC call.accept_swap,cancel_swap,cancel_expired_swap→invalidate_swap(swap_id)after the RPC call.reveal_key→invalidate_swap(swap_id)+ clearsreputation:*(a completed swap updates both parties' reputation), after the RPC call.Testing
test_invalidate_ip_clears_record_and_owner_lists,test_invalidate_swap_clears_record_and_lists(cargo test --lib cache).test_invalidate_on_contract_event_*) continue to pass unchanged.cargowas unavailable in the authoring environment, so the suite could not be executed there; the Redis integration tests (cache_redis_cross_instance,cache_redis_fallback) are unaffected in behavior.Related