-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Colocation notify - bad scores refactor and fixes (#2022)
# Description Contains various fixes around scores validation. Currently, score validation is messy and very complicated. I tried to summarize all checks to only 4 of them: 1. Score > 0 2. Score <= Quality, where Quality = surplus + fees. 3. SuccessProbability in range [0,1] 4. ObjectiveValue > 0, where ObjectiveValue = Quality - GasCost (1) and (2) are checked for all scores as per CIP20. (3) and (4) are checked only for `RiskAdjusted` scores (scores based on success probability used by `ScoreCalculator`), and they represent validation of the input to the `ScoreCalculator` which demands these checks in order for computation to be meaningful. # Changes - [ ] Moved out `ObjectiveValueNonPositive` and `SuccessProbabilityOutOfRange` so that all errors from score calculator are now boundary errors as they should be (I don't want to import `ScoringError` into `boundary`) - [ ] Fixed a bug: `score > quality` instead of `score > objective_value` - [ ] `ScoreHigherThanObjective` removed completely since this is an internal error in score calculator and it should never happen unless there is a bug in the code. Anyway, this is definitely not a special case I want to handle. - [ ] `TooHighScore` replaced with `ScoreHigherThanQuality`
- Loading branch information
Showing
23 changed files
with
304 additions
and
296 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,31 @@ | ||
use { | ||
crate::{ | ||
boundary, | ||
domain::{ | ||
competition::score::{self, SuccessProbability}, | ||
competition::score::{ | ||
self, | ||
risk::{ObjectiveValue, SuccessProbability}, | ||
}, | ||
eth, | ||
}, | ||
util::conv::u256::U256Ext, | ||
}, | ||
score::{ObjectiveValue, Score}, | ||
solver::settlement_rater::{ScoreCalculator, ScoringError}, | ||
score::Score, | ||
solver::settlement_rater::ScoreCalculator, | ||
}; | ||
|
||
pub fn score( | ||
score_cap: Score, | ||
objective_value: ObjectiveValue, | ||
success_probability: SuccessProbability, | ||
failure_cost: eth::Ether, | ||
) -> Result<Score, score::Error> { | ||
match ScoreCalculator::new(score_cap.0.to_big_rational()).compute_score( | ||
&objective_value.0.to_big_rational(), | ||
failure_cost.0.to_big_rational(), | ||
failure_cost: eth::GasCost, | ||
) -> Result<Score, boundary::Error> { | ||
match ScoreCalculator::new(score_cap.0.get().to_big_rational()).compute_score( | ||
&objective_value.0.get().to_big_rational(), | ||
failure_cost.0 .0.to_big_rational(), | ||
success_probability.0, | ||
) { | ||
Ok(score) => Ok(score.into()), | ||
Err(ScoringError::ObjectiveValueNonPositive(_)) => { | ||
Err(score::Error::ObjectiveValueNonPositive) | ||
} | ||
Err(ScoringError::ScoreHigherThanObjective(score, objective_value)) => { | ||
Err(score::Error::ScoreHigherThanObjective( | ||
eth::U256::from_big_rational(&score)?.into(), | ||
eth::U256::from_big_rational(&objective_value)?.into(), | ||
)) | ||
} | ||
Err(ScoringError::SuccessProbabilityOutOfRange(value)) => Err( | ||
score::Error::SuccessProbabilityOutOfRange(SuccessProbability(value)), | ||
), | ||
Err(ScoringError::InternalError(err)) => Err(score::Error::Boundary(err)), | ||
Ok(score) => Ok(score.try_into()?), | ||
Err(err) => Err(err.into()), | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.