-
Notifications
You must be signed in to change notification settings - Fork 9
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
Change get_standing_orders_of_slot to return always all standing_orders, including non-placed ones #155
Conversation
driver/src/db_interface.rs
Outdated
); | ||
let mut standing_orders = vec![empty_standing_order; models::NUM_RESERVED_ACCOUNTS as usize]; | ||
for standing_order in non_zero_standing_orders { | ||
standing_orders[standing_order.account_id as usize] = standing_order.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to be less clonely(), but did not find a way to do it. I have seen people switching to references or using std::mem::swap. But I think neither of these methods is appropriated here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does foreach work (https://docs.rs/foreach/0.3.0/foreach/)?
ForEach trait and for_each! macro allow you to use iterator inside iteration loop, which is not posible when using for-in loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use for_each now. It makes the code easier to understand. However, I was not able to remove the clone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should populate the accountId correctly even in the fake records.
Also could get_standing_orders_of_slot
now return a fixed length array of size NUM_RESERVED_ACCOUNTS?
driver/src/db_interface.rs
Outdated
); | ||
let mut standing_orders = vec![empty_standing_order; models::NUM_RESERVED_ACCOUNTS as usize]; | ||
for standing_order in non_zero_standing_orders { | ||
standing_orders[standing_order.account_id as usize] = standing_order.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does foreach work (https://docs.rs/foreach/0.3.0/foreach/)?
ForEach trait and for_each! macro allow you to use iterator inside iteration loop, which is not posible when using for-in loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is starting to look very "Rustic"!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What were your thoughts around changing the return type of get_standing_orders_of_slot
to Result<[models::StandingOrder; models::NUM_RESERVED_ACCOUNTS as usize], DriverError>;
to make clear that it will always contain the full list augmented with empty StandingOrders?
Tests appear to be failing here because of maximum retires:
Maybe it is a good time for us to try and fix this. |
I figured out that using : |
c2d6857
to
4e3b417
Compare
You are right. I wonder if this is something we need to change in the future as in the snark we will likely fill up unoccupied slots with 0s. |
Yeah, then many things might be needed to change. Also, our rolling hash of the normal orders would be required to be computed differently. It would always need to be a rolling hash of 500 orders, just x<500 would no longer be an option, as the snark would also always compute 500 rolling hashes. |
@fleupold I think the PR is ready. Changing the rolling_hash construction should be done in another pr, if we decided to do it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reviewed before, but now it looks so much better. Great work! 🧀
I pushed the code for a potential solution for using arrays for standing orders. Using arrays, which for types not implementing the Copy trait is a f... pain. I could not implement the macro solution, as rust does not implement a clean way to share a macro over several crates
because only traits defined in the current crate can be implemented for arbitrary types. Now, I came up with a solution, but it uses unsafe code. I think it would be cleaner and safer to just use vectors instead of unsafe code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All looks really nice. Getting rustier and rustier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I'm just a bit confused by the non-rust code changes.
I could not find a solution for the clippy issue:
--- locally I can just run: Does anyone have a suggestion? |
Hey @josojo - It appears there is a problem compiling a couple dependencies? Is this because of the rust version or clippy?
|
Just a question here: |
Yes, totally. |
tackels #152
testplan:
unit tests only