You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Used in multiple places (lines 525-537, 652-666, etc.)
Testing Considerations
Add unit tests for:
min(balance, equity) logic with various scenarios (positive/negative unrealized PnL)
Idle miner detection edge cases (no positions, no orders, exactly at threshold)
Promotion logic when equity > balance vs balance > equity
Integration test scenarios:
Miner with high unrealized profit shouldn't be promoted if balance is low
Miner at exactly 60 days idle should/shouldn't be eliminated
Proper handling when position client returns None/empty data
Performance
Batch position queries: The idle miner check calls get_positions_for_hotkeys with all candidates at once (good!), but verify this doesn't cause memory issues with large datasets.
Cache drawdown stats: Already implemented, but ensure cache invalidation is correct when account state changes.
🔒 Security Notes
MEDIUM: Potential for promoting miners with manipulated unrealized PnL
The change to use min(balance, equity) is good security practice
However, if unrealized PnL can be manipulated (e.g., by placing orders in illiquid markets), a miner could still game the system by withdrawing while showing high balance
Consider additional validation: check that balance hasn't decreased significantly right before promotion
accounts.get(hotkey) could return None, causing AttributeError
Should use accounts.get(hotkey, {}).get('balance', 0)
LOW: Division by zero potential
Line 448:
balance_ret=balance/account_size
If account_size is 0, this will raise ZeroDivisionError
The check on line 441 validates account_size, but it checks account.get('account_size') while this uses the extracted account_size variable
Should add explicit zero check: if account_size <= 0: return None
📋 Action Items
Must Fix Before Merge:
✅ Fix log message formatting (missing separators) on lines 581-583
✅ Replace hardcoded timestamp with named constant/datetime
✅ Fix potential None.get() error on line 582
✅ Add consistent type hints (PEP 604 vs Optional)
Should Fix:
5. ⚠️ Add logging when current_return is None (helps debugging)
6. ⚠️ Extract repeated drawdown stats dict to helper method (DRY principle)
7. ⚠️ Optimize idle miner order time calculation
Nice to Have:
8. 💭 Add comprehensive unit tests for new promotion logic
9. 💭 Document the rationale for using min(balance, equity) in code comments
10. 💭 Consider adding metrics/alerts when miners are near promotion/elimination thresholds
Final Recommendation
🟡 CONDITIONAL APPROVAL - The core logic changes are sound and address real issues, but there are several bugs that must be fixed before merging. The min(balance, equity) change is a good security improvement. Fix the critical items above, and this will be good to merge.
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
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.
Taoshi Pull Request
Description
Related Issues (JIRA)
[Reference any related issues or tasks that this pull request addresses or closes.]
Checklist
Reviewer Instructions
[Provide any specific instructions or areas you would like the reviewer to focus on.]
Definition of Done
Checklist (for the reviewer)
Optional: Deploy Notes
[Any instructions or notes related to deployment, if applicable.]
/cc @mention_reviewer