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

handle oracle overflow and rounding to zero for extreme values with cross rates #1983

Merged
merged 3 commits into from
Dec 10, 2024

Conversation

udpatil
Copy link
Collaborator

@udpatil udpatil commented Dec 9, 2024

Describe your changes and provide context

This fixes issues that can occur in the most extreme circumstances where extreme values used for cross rates can cause issues during oracle ballot calculations.

Testing performed to validate your change

Unit test + docker cluster testing

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 61.53846% with 5 lines in your changes missing coverage. Please review.

Project coverage is 61.50%. Comparing base (e8e4b3b) to head (e4d335a).
Report is 225 commits behind head on main.

Files with missing lines Patch % Lines
x/oracle/types/ballot.go 44.44% 4 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1983      +/-   ##
==========================================
- Coverage   61.64%   61.50%   -0.15%     
==========================================
  Files         365      263     -102     
  Lines       26178    24339    -1839     
==========================================
- Hits        16138    14970    -1168     
+ Misses       8967     8256     -711     
- Partials     1073     1113      +40     
Files with missing lines Coverage Δ
x/oracle/abci.go 100.00% <100.00%> (ø)
x/oracle/types/ballot.go 74.28% <44.44%> (-3.04%) ⬇️

... and 222 files with indirect coverage changes

x/oracle/abci.go Outdated
@@ -66,6 +66,10 @@ func MidBlocker(ctx sdk.Context, k keeper.Keeper) {
voteMapRD := ballotRD.ToMap()

exchangeRateRD := ballotRD.WeightedMedianWithAssertion()
// handle case where exchange rate is 0
if exchangeRateRD.IsZero() {
// TODO: do stuff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we actually want to do things?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I realized this one can't actually be zero because votes submitted with a zero value are modified to have the vote power set to 0, so the only way to get 0 exchange rates is for really small number divided by really large number which is with the cross rates calculations.

Copy link
Contributor

@stevenlanders stevenlanders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ just wasn't sure of that empty branch, but otherwise lgtm

@udpatil udpatil force-pushed the oracle-fix-division branch from 6048916 to 5324d78 Compare December 10, 2024 17:12
@udpatil udpatil merged commit 86d0381 into main Dec 10, 2024
48 of 49 checks passed
@udpatil udpatil deleted the oracle-fix-division branch December 10, 2024 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants