mirror of
https://github.com/luxfi/dex.git
synced 2026-09-24 00:26:31 +00:00
Borrow and Repay used a per-AssetPool mutex (pool.mu) while Supply, Withdraw and the read accessors all serialize via the LendingPool-wide lock (lp.mu). The shared LendingPool maps (TotalBorrowed, UtilizationRates, AccruedFees, ReserveFunds) and per-pool fields written by updateInterestRates (UtilizationRate, BorrowRate, SupplyRate) were therefore protected by two different locks, so concurrent Supply + Borrow races on the same asset — reliably reproduced by TestLendingPool_ConcurrentAccess under -race. Use lp.mu in Borrow and Repay so every mutator on a given LendingPool serializes through the same mutex, and drop the now-dead AssetPool.mu field (single way to do everything). Verified with: go test -race -count=50 -run TestLendingPool_ConcurrentAccess