Files
dex/pkg
zeekayandGitHub 70eb29cee0 lx: fix data race in LendingPool.Borrow/Repay (#5)
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
2026-05-16 19:21:46 -07:00
..