fix(core): refactor account update to prevent race condition - #763
Conversation
Greptile SummaryThe PR separates authoritative local account mutations from conditional remote or database hydration, resolving fetched accounts under the SVM write lock so concurrent local writes win.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the current code skips the entire fetched composite when its primary is already live and refreshes returned coupled dependencies from retained local state. Important Files Changed
Reviews (8): Last reviewed commit: "Merge branch 'main' into fix/race" | Re-trigger Greptile |
|
Nice fix! The policy enum reads like the row selector of a decision table: given a policy and the account's local state, each cell is the action taken. Writing that table out might be worth a few minutes; it would make a compact rustdoc for Two things to consider while filling it in:
My attempts at those cells kept needing footnotes 😞 , which usually means I'm missing an input; curious what you get. |
- Introduced AccountUpdatePolicy enum to manage authoritative vs. cache hydration updates. - Replaced direct calls to write_account_update with apply_account_update across multiple modules. - Updated logic in SurfnetSvm to handle account updates based on the new policy, ensuring local state is preserved when appropriate. - Enhanced tests to validate behavior of local vs. remote account updates, ensuring local writes are not overwritten by stale remote data. - Removed deprecated write_multiple_account_updates method and consolidated account update logic for clarity and maintainability.
Thank you @Arrowana for identifying this bug! Replaces #738