From 6ed10bce816a69ba45592a9ef011a52f8b8faef0 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Wed, 9 Oct 2024 21:52:35 +0200 Subject: [PATCH] fix_: native token not found error when generating a new route issue fixed This commit fixes `native token not found` issue that occurs only when the input params of an already successfully generated route for a fast chain (refers to a chain that generates new block very fast, like optimism, arbitrum) are updated. The reason of the issue was that active route remains the same until the resolving of a new route for updated input parameters gets generated, for fast chains that was enough time to generate a new block and send fees update for the previously active route. This commit fixes that possibility by aborting updates in a better way. --- services/wallet/router/router.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/services/wallet/router/router.go b/services/wallet/router/router.go index 8a6d8ab5a..799d2f503 100644 --- a/services/wallet/router/router.go +++ b/services/wallet/router/router.go @@ -202,25 +202,35 @@ func (r *Router) SuggestedRoutesAsync(input *requests.RouteInputParams) { }) } +func (r *Router) clearActiveRoute() { + r.activeRoutesMutex.Lock() + r.activeRoutes = nil + r.activeRoutesMutex.Unlock() +} + func (r *Router) markRouteCanceled(value bool) { r.routeCanceledMutex.Lock() r.routeCanceled = value r.routeCanceledMutex.Unlock() } -func (r *Router) StopSuggestedRoutesAsyncCalculation() { +func (r *Router) abortUpdates() { r.markRouteCanceled(true) r.unsubscribeFeesUpdateAccrossAllChains() +} + +func (r *Router) StopSuggestedRoutesAsyncCalculation() { + r.abortUpdates() r.scheduler.Stop() } func (r *Router) StopSuggestedRoutesCalculation() { - r.unsubscribeFeesUpdateAccrossAllChains() + r.abortUpdates() } func (r *Router) SuggestedRoutes(ctx context.Context, input *requests.RouteInputParams) (suggestedRoutes *SuggestedRoutes, err error) { - // unsubscribe from updates - r.unsubscribeFeesUpdateAccrossAllChains() + r.clearActiveRoute() + r.abortUpdates() r.markRouteCanceled(false) // clear all processors