Skip to content

Commit 28e4ae9

Browse files
Gudahttmcmire
andauthored
Retry failed token price updates (#3655)
## 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]>
1 parent 83d37dc commit 28e4ae9

File tree

7 files changed

+497
-25
lines changed

7 files changed

+497
-25
lines changed

packages/assets-controllers/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@metamask/utils": "^8.2.0",
4949
"@types/uuid": "^8.3.0",
5050
"async-mutex": "^0.2.6",
51+
"cockatiel": "3.1.1",
5152
"ethereumjs-util": "^7.0.10",
5253
"lodash": "^4.17.21",
5354
"multiformats": "^9.5.2",

packages/assets-controllers/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ export {
1313
formatIconUrlWithProxy,
1414
getFormattedIpfsUrl,
1515
} from './assetsUtil';
16-
export { codefiTokenPricesServiceV2 } from './token-prices-service';
16+
export { CodefiTokenPricesServiceV2 } from './token-prices-service';

0 commit comments

Comments
 (0)