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

submit solution only if solution is better than the solution in the chain #269

Closed
wants to merge 4 commits into from

Conversation

josojo
Copy link
Contributor

@josojo josojo commented Oct 4, 2019

As title


Testplan:
unit tests

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 {
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 was searching here for a more elegant solution, but I can not find it.

Thread discussing it:
rust-lang/rfcs#929 (comment)

Copy link
Contributor

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.

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 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.

Copy link
Contributor

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
            },
        };

Copy link
Contributor

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
        };

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.

Looks pretty good, made one inline comment about what appears to be duplicate code!

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 like the purpose of the PR. Right now we are comparing utility with volume, which we should probably fix before merging.

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 {
Copy link
Contributor

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.

@bh2smith bh2smith self-requested a review October 11, 2019 12:02
josojo added a commit that referenced this pull request Oct 24, 2019
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);
Copy link
Contributor

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.

Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Contributor

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.

@josojo
Copy link
Contributor Author

josojo commented Nov 12, 2019

This PR is no longer necessary, as #296 will just prevent submitting solutions with less objective value

@josojo josojo closed this Nov 12, 2019
@fleupold fleupold deleted the onlySubmitSolutionIfBetterSolution branch November 24, 2019 09:58
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.

4 participants