Skip to content

Commit

Permalink
Retry failed token price updates (#3655)
Browse files Browse the repository at this point in the history
## Explanation

The `token-prices-service` will now retry token price updates if they
fail. The retry strategy is designed to let the API recover if it is
experiencing high traffic volumes.

The service now requires state in order to hold onto the retry policy.
It has been converted to a class for that reason. This required no
changes to the abstract price service type or to the
`TokenRatesController`.

## References

Closes #2084

## Changelog

### `@metamask/assets-controllers`

- Changed: The `CodefiTokenPricesServiceV2` will retry if the token
price update fails
- We retry each request up to 3 times using a randomized exponential
backoff strategy
- If the token price update still fails 5 times consecutively (including
the 3 retries each attempt, so 15 consecutive failures total), we stop
trying for 30 minutes before we try again.
- The service has been converted from a collection of functions to a
class. The newly added constructor has these options:
* `tokenPriceRetryAttempts` - Number of retry attempts for each token
rate update.
* `tokenPriceMaximumConsecutiveFailures` - The maximum number of
consecutive failures allowed before breaking the circuit and pausing
further updates.
* `tokenPriceCircuitBreakDuration` - The amount of time to wait when the
circuit breaks from too many consecutive failures.

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate

---------

Co-authored-by: Elliot Winkler <[email protected]>
  • Loading branch information
Gudahtt and mcmire authored Dec 13, 2023
1 parent 83d37dc commit 28e4ae9
Show file tree
Hide file tree
Showing 7 changed files with 497 additions and 25 deletions.
1 change: 1 addition & 0 deletions packages/assets-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@metamask/utils": "^8.2.0",
"@types/uuid": "^8.3.0",
"async-mutex": "^0.2.6",
"cockatiel": "3.1.1",
"ethereumjs-util": "^7.0.10",
"lodash": "^4.17.21",
"multiformats": "^9.5.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export {
formatIconUrlWithProxy,
getFormattedIpfsUrl,
} from './assetsUtil';
export { codefiTokenPricesServiceV2 } from './token-prices-service';
export { CodefiTokenPricesServiceV2 } from './token-prices-service';
Loading

0 comments on commit 28e4ae9

Please sign in to comment.