-
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
submit solution only if solution is better than the solution in the chain #269
Conversation
driver/src/driver/stablex_driver.rs
Outdated
info!("Successfully applied solution to batch {}", batch); | ||
true | ||
let current_objective_value = self.contract.get_current_objective_value()?; | ||
let submitted = if let Some(surplus) = solution.surplus { |
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 was searching here for a more elegant solution, but I can not find it.
Thread discussing it:
rust-lang/rfcs#929 (comment)
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.
You are comparing surplus (should probably be renamed to utility in a separate PR) with the current_objective_value (which at the moment is volume). I don't think this works in the current setting as a solution with little surplus would not be corrected as long as it had more volume than a new solution had utility. Can't we compute and compare the proper volume instead?
As for how to make this more elegant with less nested if statements, you could have a helper method that returns a SolutionSubmission
enum (e.g. Trivial, NotGoodEnough, Submit) and then have a match statement with only one level.
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 thought, although this is not the correct solution, it is better than checking just that is is not the trivial solution.
Not sure, whether it is worth to code the volume formula ( actually the fee formula), as the rounding that would be needed to be considered is non-trivial.
But yeah, I am happy to pause this PR and keep it for later, once Tom's solver and the smart contract calculate the same objective value.
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.
You could use match statements with conditional patterns, something like this:
let submitted = match solution.surplus {
Some(surplus) if current_objective_value < surplus => {
self.contract.submit_solution(batch, orders, solution)?;
info!("Successfully applied solution to batch {}", batch);
true
},
_ => {
info!("Not submitting trivial solution for batch {}", batch);
false
},
};
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.
You could also use Option::map
and do something like:
let submitted = if Some(true) = solution.surplus.map(|surplus| current_objective_value < surplus) {
self.contract.submit_solution(batch, orders, solution)?;
info!("Successfully applied solution to batch {}", batch);
true
} else {
info!("Not submitting trivial solution for batch {}", batch);
false
};
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 pretty good, made one inline comment about what appears to be duplicate 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.
I like the purpose of the PR. Right now we are comparing utility with volume, which we should probably fix before merging.
driver/src/driver/stablex_driver.rs
Outdated
info!("Successfully applied solution to batch {}", batch); | ||
true | ||
let current_objective_value = self.contract.get_current_objective_value()?; | ||
let submitted = if let Some(surplus) = solution.surplus { |
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.
You are comparing surplus (should probably be renamed to utility in a separate PR) with the current_objective_value (which at the moment is volume). I don't think this works in the current setting as a solution with little surplus would not be corrected as long as it had more volume than a new solution had utility. Can't we compute and compare the proper volume instead?
As for how to make this more elegant with less nested if statements, you could have a helper method that returns a SolutionSubmission
enum (e.g. Trivial, NotGoodEnough, Submit) and then have a match statement with only one level.
As Felix mentioned in the other PR #269, our solution model is used in different contexts. Hence, it is appropriate to replace the name surplus with a more general name. testplan: unit tests
info!("Successfully applied solution to batch {}", batch); | ||
true | ||
} else { | ||
info!("Not submitting trivial solution for batch {}", batch); |
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 log message seems off.
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 agree. Also, this wouldn't be possible anyway.
true | ||
let current_objective_value = self.contract.get_current_objective_value()?; | ||
let submitted = if let Some(objective_value) = solution.objective_value { | ||
if current_objective_value < objective_value { |
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.
How about an objective value of 0? Would that ever get submitted?
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.
At the moment, the contract does not allow for trivial solution submission. Furthermore, it does not accept solutions with zero objective evaluation either.
This PR is no longer necessary, as #296 will just prevent submitting solutions with less objective value |
As title
Testplan:
unit tests