-
Notifications
You must be signed in to change notification settings - Fork 250
perf(market-data): add update backoff strategy and guard against fetching tx history of unactivated assets #3162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
takenagain
merged 7 commits into
feat/zhtlc-asset-support
from
perf/mm-update-backoff-strategy
Oct 1, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b85c889
fix(wallet): add resilience to delisted coins for wallet coin metadata
takenagain a130697
fix(version-info): ensure that apiversion and commit has persist
takenagain c17ebf1
perf(market-metrics): add backoff strategy for periodic updates
takenagain 0410a12
refactor(market-metrics): extract common coin filtering for test coin…
takenagain eb6aaf9
refactor(market-metrics): extract calculation functions into extension
takenagain ad248ed
perf(coins-bloc): add initialisation status tracking for startup
takenagain df47d45
refactor: add loop exits, update comments, remove unused event member
takenagain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
lib/bloc/cex_market_data/common/update_frequency_backoff_strategy.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import 'dart:math' as math; | ||
|
|
||
| /// A strategy for implementing exponential backoff with paired intervals. | ||
| /// The pattern is: 1min, 1min, 2min, 2min, 4min, 4min, 8min, 8min, etc. | ||
| /// This reduces API calls while still providing reasonable update frequency. | ||
| class UpdateFrequencyBackoffStrategy { | ||
| UpdateFrequencyBackoffStrategy({ | ||
| this.baseInterval = const Duration(minutes: 1), | ||
| this.maxInterval = const Duration(hours: 1), | ||
| }); | ||
|
|
||
| /// The base interval for the first attempts (default: 2 minutes) | ||
| final Duration baseInterval; | ||
|
|
||
| /// The maximum interval to backoff to (default: 1 hour) | ||
| final Duration maxInterval; | ||
|
|
||
| int _attemptCount = 0; | ||
|
|
||
| /// Reset the backoff strategy to start from the beginning | ||
| void reset() { | ||
| _attemptCount = 0; | ||
| } | ||
|
|
||
| /// Get the current attempt count | ||
| int get attemptCount => _attemptCount; | ||
|
|
||
| /// Get the next interval duration and increment the attempt count | ||
| Duration getNextInterval() { | ||
| final interval = getCurrentInterval(); | ||
| _attemptCount++; | ||
| return interval; | ||
| } | ||
|
|
||
| /// Get the current interval duration without incrementing the attempt count | ||
| Duration getCurrentInterval() { | ||
| // Calculate which "pair" we're in (0, 1, 2, 3, ...) | ||
| // Each pair has 2 attempts with the same interval | ||
| final pairIndex = _attemptCount ~/ 2; | ||
|
|
||
| // Calculate the multiplier: 2^pairIndex | ||
| final multiplier = math.pow(2, pairIndex).toInt(); | ||
|
|
||
| // Calculate the interval | ||
| final intervalMs = baseInterval.inMilliseconds * multiplier; | ||
|
|
||
| // Cap at maximum interval | ||
| final cappedIntervalMs = math.min(intervalMs, maxInterval.inMilliseconds); | ||
|
|
||
| return Duration(milliseconds: cappedIntervalMs); | ||
| } | ||
|
|
||
| /// Check if we should update the cache on the current attempt | ||
| /// Returns true for cache update attempts, false for cache-only reads | ||
| bool shouldUpdateCache() { | ||
| // Update cache on every attempt for now, but this could be modified | ||
| // to only update on certain intervals if needed | ||
| return true; | ||
| } | ||
|
|
||
| /// Get a preview of the next N intervals without affecting the state | ||
| List<Duration> previewNextIntervals(int count) { | ||
| final currentAttempt = _attemptCount; | ||
| final intervals = <Duration>[]; | ||
|
|
||
| for (int i = 0; i < count; i++) { | ||
| final pairIndex = (currentAttempt + i) ~/ 2; | ||
| final multiplier = math.pow(2, pairIndex).toInt(); | ||
| final intervalMs = baseInterval.inMilliseconds * multiplier; | ||
| final cappedIntervalMs = math.min(intervalMs, maxInterval.inMilliseconds); | ||
| intervals.add(Duration(milliseconds: cappedIntervalMs)); | ||
| } | ||
|
|
||
| return intervals; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.