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.
This commit is contained in:
Sale Djenic 2024-10-09 21:52:35 +02:00 committed by saledjenic
parent 97db14083a
commit 6ed10bce81
1 changed files with 14 additions and 4 deletions

View File

@ -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) { func (r *Router) markRouteCanceled(value bool) {
r.routeCanceledMutex.Lock() r.routeCanceledMutex.Lock()
r.routeCanceled = value r.routeCanceled = value
r.routeCanceledMutex.Unlock() r.routeCanceledMutex.Unlock()
} }
func (r *Router) StopSuggestedRoutesAsyncCalculation() { func (r *Router) abortUpdates() {
r.markRouteCanceled(true) r.markRouteCanceled(true)
r.unsubscribeFeesUpdateAccrossAllChains() r.unsubscribeFeesUpdateAccrossAllChains()
}
func (r *Router) StopSuggestedRoutesAsyncCalculation() {
r.abortUpdates()
r.scheduler.Stop() r.scheduler.Stop()
} }
func (r *Router) StopSuggestedRoutesCalculation() { func (r *Router) StopSuggestedRoutesCalculation() {
r.unsubscribeFeesUpdateAccrossAllChains() r.abortUpdates()
} }
func (r *Router) SuggestedRoutes(ctx context.Context, input *requests.RouteInputParams) (suggestedRoutes *SuggestedRoutes, err error) { func (r *Router) SuggestedRoutes(ctx context.Context, input *requests.RouteInputParams) (suggestedRoutes *SuggestedRoutes, err error) {
// unsubscribe from updates r.clearActiveRoute()
r.unsubscribeFeesUpdateAccrossAllChains() r.abortUpdates()
r.markRouteCanceled(false) r.markRouteCanceled(false)
// clear all processors // clear all processors