From 94ca39a682d6980558d1d852ac2cd57de019a3ff Mon Sep 17 00:00:00 2001 From: jholdstock Date: Sat, 4 Apr 2026 13:20:02 +0800 Subject: [PATCH 1/2] swap: Ensure processBlock evaluates all matches. It seemed that return was being used instead of continue mistakenly, which could lead to situations where the loop incorrectly exits early and not all matches are evaluated. --- server/swap/swap.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/swap/swap.go b/server/swap/swap.go index 06e0a35455..273197f547 100644 --- a/server/swap/swap.go +++ b/server/swap/swap.go @@ -1097,7 +1097,7 @@ func (s *Swapper) processBlock(ctx context.Context, block *blockNotification) { // If it's neither of the match assets, nothing to do. if match.makerStatus.swapAsset != block.assetID && match.takerStatus.swapAsset != block.assetID { - return + continue } // Lock the matchTracker so the following checks and updates are atomic From 7be48b1e7d77784add807d8fabf67fc1def4a0d5 Mon Sep 17 00:00:00 2001 From: jholdstock Date: Mon, 6 Apr 2026 10:17:26 +0800 Subject: [PATCH 2/2] swap: Don't defer mutex unlock in a loop. Using defer to unlock the mutex means that the mutex can be locked repeatedly during the loop and only unlocked when the function returns, rather than being unlocked at the end of the current loop iteration. This can lead to the mutex being held for longer than required. --- server/swap/swap.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/swap/swap.go b/server/swap/swap.go index 273197f547..c9026429b8 100644 --- a/server/swap/swap.go +++ b/server/swap/swap.go @@ -1103,7 +1103,6 @@ func (s *Swapper) processBlock(ctx context.Context, block *blockNotification) { // Lock the matchTracker so the following checks and updates are atomic // with respect to Status. match.mtx.RLock() - defer match.mtx.RUnlock() switch match.Status { case order.MakerSwapCast: @@ -1127,6 +1126,8 @@ func (s *Swapper) processBlock(ctx context.Context, block *blockNotification) { s.unlockOrderCoins(match.Taker) } } + + match.mtx.RUnlock() } }