Enforce total capacity limit constraint in investment - #1496
Draft
AdrianDAlessandro wants to merge 2 commits into
Draft
Enforce total capacity limit constraint in investment#1496AdrianDAlessandro wants to merge 2 commits into
AdrianDAlessandro wants to merge 2 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1496 +/- ##
==========================================
- Coverage 90.26% 90.24% -0.02%
==========================================
Files 60 60
Lines 8614 8658 +44
Branches 8614 8658 +44
==========================================
+ Hits 7775 7813 +38
- Misses 525 531 +6
Partials 314 314 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
11 tasks
Collaborator
Yes and yes! Sorry, should have alerted you more to #1495 as it was intended to make your life easier not harder! |
tsmbland
reviewed
Aug 19, 2026
Comment on lines
571
to
601
| if best_asset.is_candidate() { | ||
| // Candidate assets: remove capacity from the investment limit, if applicable. | ||
| if let Some(remaining_capacity) = remaining_candidate_capacities.get_mut(&best_asset) { | ||
| if let Some(remaining_capacity) = remaining_addition_limit.get_mut(&best_asset) { | ||
| *remaining_capacity -= best_asset.total_capacity(); | ||
|
|
||
| // If there's not enough capacity remaining to install any more units, remove the | ||
| // asset from the investment options. | ||
| if *remaining_capacity < best_asset.total_capacity() { | ||
| let old_idx = opt_assets | ||
| .iter() | ||
| .position(|asset| *asset == best_asset) | ||
| .unwrap(); | ||
| opt_assets.swap_remove(old_idx); | ||
| remaining_candidate_capacities.remove(&best_asset); | ||
| remaining_addition_limit.remove(&best_asset); | ||
| } | ||
| } | ||
| } else { | ||
| // Commissioned assets: we've appraised a single unit, so remove one unit from the | ||
| // remaining units count for this asset. | ||
| let remaining = remaining_units.get_mut(&best_asset).unwrap(); | ||
| *remaining = remaining.saturating_sub(1); | ||
|
|
||
| // If all units have been selected, remove the asset from the investment options. | ||
| if *remaining == 0 { | ||
| let old_idx = opt_assets | ||
| .iter() | ||
| .position(|asset| *asset == best_asset) | ||
| .unwrap(); | ||
| opt_assets.swap_remove(old_idx); | ||
| remaining_units.remove(&best_asset); | ||
| } |
Collaborator
There was a problem hiding this comment.
I think it's possible this part could fail if the asset has already been removed from the asset options by the total capacity limit (trying to remove the same option twice). You'll need to rework this function a bit to account for this
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This is an attempt at enforcing the total capacity limit constraint in the investment. It still needs some tests, but there are some components I wanted to ask about first.
I had made the total capacity limits mapped by
ProcessID, but was going to ask about the function in which I do that (market.rs::collect_total_limits), because I believe it is looping over duplicate processes and just overwriting theHashMapunnecessarily. However, I have just seen #1495 - which I believe answers that question, but will require me to bring this branch up to date with it and then change my implementation.For now, two questions:
Fixes #1493
Type of change
Key checklist
$ cargo test$ cargo docpresent in the previous release
Further checks