-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Implement worst case scenario for price algorithm v1 #2219
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
dc3a670
Extract 'cumulative_percentage()' from algorithm V0
7693ecd
Implement worst_case() for Algorithm V1
334bd3f
Use worst_case in impl of GasPriceAlgorithm for Algorithm
3db5157
Satisfy Clippy
adffd99
Rename 'cumulative_percentage()' to 'cumulative_percentage_change()'
dd6bf4d
Merge branch 'master' into 2203_worst_case_for_algorithm_v1
MitchTurner 512613a
Merge branch 'master' into 2203_worst_case_for_algorithm_v1
MitchTurner 4337b14
Use more clear variable names in `cumulative_percentage_change`
d1672d3
Add `utils` module and move `cumulative_percentage_change` inside
6cb3161
Add additional tests to `Algorithm V1`
8875466
Merge remote-tracking branch 'upstream/master' into 2203_worst_case_f…
c55aa65
Update price algorithm test names
94dc8b7
Modify test to be a little more precise
MitchTurner e2346f1
Merge branch 'master' into 2203_worst_case_for_algorithm_v1
MitchTurner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -2,5 +2,6 @@ | |
| #![deny(clippy::cast_possible_truncation)] | ||
| #![deny(warnings)] | ||
|
|
||
| mod utils; | ||
| pub mod v0; | ||
| pub mod v1; | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #[allow(clippy::cast_possible_truncation)] | ||
| pub(crate) fn cumulative_percentage_change( | ||
| new_exec_price: u64, | ||
| for_height: u32, | ||
| percentage: u64, | ||
| height: u32, | ||
| ) -> u64 { | ||
| let blocks = height.saturating_sub(for_height) as f64; | ||
| let percentage_as_decimal = percentage as f64 / 100.0; | ||
| let multiple = (1.0f64 + percentage_as_decimal).powf(blocks); | ||
| let mut approx = new_exec_price as f64 * multiple; | ||
| // account for rounding errors and take a slightly higher value | ||
| const ROUNDING_ERROR_CUTOFF: f64 = 16948547188989277.0; | ||
| if approx > ROUNDING_ERROR_CUTOFF { | ||
| const ROUNDING_ERROR_COMPENSATION: f64 = 2000.0; | ||
| approx += ROUNDING_ERROR_COMPENSATION; | ||
| } | ||
| // `f64` over `u64::MAX` are cast to `u64::MAX` | ||
| approx.ceil() as u64 | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We should add another test to check for overflows. See the V0 test and this convo:
#2025 (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.
Test added in 6cb3161