Skip to content
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

Merged
merged 22 commits into from
Jul 17, 2019

Conversation

josojo
Copy link
Contributor

@josojo josojo commented Jun 21, 2019

tackels #152

testplan:
unit tests only

@josojo josojo changed the title Change get_standing_orders_of_slot to return always all standing_orders, including non-placed ones [draft]Change get_standing_orders_of_slot to return always all standing_orders, including non-placed ones Jun 21, 2019
@josojo josojo requested review from fleupold and bh2smith June 21, 2019 09:28
@josojo josojo changed the title [draft]Change get_standing_orders_of_slot to return always all standing_orders, including non-placed ones Change get_standing_orders_of_slot to return always all standing_orders, including non-placed ones Jun 21, 2019
);
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();
Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@fleupold fleupold left a 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 Show resolved Hide resolved
);
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();
Copy link
Contributor

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.

driver/src/models/standing_order.rs Outdated Show resolved Hide resolved
driver/src/order_driver.rs Outdated Show resolved Hide resolved
@josojo josojo requested review from fleupold and bh2smith June 24, 2019 06:03
Copy link
Contributor

@bh2smith bh2smith left a 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"!

Copy link
Contributor

@fleupold fleupold left a 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?

driver/src/db_interface.rs Outdated Show resolved Hide resolved
@bh2smith
Copy link
Contributor

Tests appear to be failing here because of maximum retires:

waited 181 seconds
Before retry #1: sleeping 0.3 seconds
Before retry #2: sleeping 0.6 seconds
Before retry #3: sleeping 1.2 seconds
Before retry #4: sleeping 2.4 seconds
Before retry #5: sleeping 4.8 seconds
Retries exhausted
The command "sh ./test/e2e-tests-standing-order.sh" exited with 1.

Maybe it is a good time for us to try and fix this.

@josojo
Copy link
Contributor Author

josojo commented Jun 27, 2019

I figured out that using :
Result<[models::StandingOrder; models::NUM_RESERVED_ACCOUNTS as usize], DriverError>;
is not a wise, as we can not differentiate nullified orders ( orders with just zeros as parameters) and non-placed orders at all. But for the rolling hash caclulation, it actually does make a difference, whether we have a non-placed order or a zero order.
Differentiating these two cases would require the introduction of a counter of orders placed. I think this is unjustified complexity. I will revert the latest changes on this PR.

@josojo josojo force-pushed the newSQLqueryWithZeroEntires branch from c2d6857 to 4e3b417 Compare June 27, 2019 09:26
@fleupold
Copy link
Contributor

fleupold commented Jul 1, 2019

But for the rolling hash caclulation, it actually does make a difference, whether we have a non-placed order or a zero order.

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.

@josojo
Copy link
Contributor Author

josojo commented Jul 1, 2019

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.

@josojo
Copy link
Contributor Author

josojo commented Jul 3, 2019

@fleupold I think the PR is ready. Changing the rolling_hash construction should be done in another pr, if we decided to do it.
Could you review it, please?

Copy link
Contributor

@bh2smith bh2smith left a 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! 🧀

@josojo
Copy link
Contributor Author

josojo commented Jul 3, 2019

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.
See the
https://stackoverflow.com/questions/28656387/initialize-a-large-fixed-size-array-with-non-copy-types

I could not implement the macro solution, as rust does not implement a clean way to share a macro over several crates
I could not use the Default trait, as it would be required to be implemented in std::default::Default.
I can not write the

impl Default for [StandingOrder; models::NUM_RESERVED_ACCOUNTS]

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.

driver/src/db_interface.rs Outdated Show resolved Hide resolved
driver/src/db_interface.rs Show resolved Hide resolved
driver/src/models/standing_order.rs Outdated Show resolved Hide resolved
driver/src/db_interface.rs Outdated Show resolved Hide resolved
driver/src/models/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@bh2smith bh2smith left a 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

Copy link
Contributor

@fleupold fleupold left a 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.

docker/driver/base/Dockerfile Outdated Show resolved Hide resolved
.travis.yml Outdated Show resolved Hide resolved
.travis.yml Outdated Show resolved Hide resolved
@josojo
Copy link
Contributor Author

josojo commented Jul 16, 2019

I could not find a solution for the clippy issue:
rust-lang/rust-clippy#3874

--cap-lints allow would not work, as we want warnings also to trigger a failure of test

--- locally I can just run:
- echo "cognitive-complexity-threshold = 30" > ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mongodb-0.3.12/clippy.toml
and everything works. But this is of course not a good solution.
Also, because the file is created in the moment of running clippy, this does not work in Travis.

Does anyone have a suggestion?

.travis.yml Outdated Show resolved Hide resolved
@bh2smith
Copy link
Contributor

Hey @josojo - It appears there is a problem compiling a couple dependencies? Is this because of the rust version or clippy?

1.83s$ cargo clippy -- cap-lints
    Checking mongodb v0.3.12
    Checking tokio-uds v0.1.7
error: multiple input filenames provided (first two filenames are `/home/travis/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-uds-0.1.7/src/lib.rs` and `cap-lints`)
error: Could not compile `tokio-uds`.
warning: build failed, waiting for other jobs to finish...
error: multiple input filenames provided (first two filenames are `/home/travis/.cargo/registry/src/github.com-1ecc6299db9ec823/mongodb-0.3.12/src/lib.rs` and `cap-lints`)
error: Could not compile `mongodb`.
To learn more, run the command again with --verbose.
The command "cargo clippy -- cap-lints" exited with 101.

@josojo josojo merged commit 5e50642 into master Jul 17, 2019
@bh2smith
Copy link
Contributor

Just a question here:
Does pinning to a specific commit of a repo mean that we should keep an eye open for the next release which includes these changes?

@josojo
Copy link
Contributor Author

josojo commented Jul 17, 2019

Yes, totally.

@fleupold fleupold deleted the newSQLqueryWithZeroEntires branch July 22, 2019 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants