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

fix: safeguard LastInterestTime against hard forks #1288

Merged
merged 7 commits into from
Aug 30, 2022
Merged

Conversation

toteki
Copy link
Member

@toteki toteki commented Aug 26, 2022

Description

This will prevent the excessive (~10^20 factor) interest accrued during our hard fork of asherah testnet, where we modified LastInterestTime in genesis.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • added appropriate labels to the PR
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@toteki toteki added T:Bug A regression or bug in the Umee codebase. C:x/leverage labels Aug 26, 2022
CHANGELOG.md Outdated Show resolved Hide resolved
@toteki toteki marked this pull request as ready for review August 26, 2022 06:42
@toteki toteki requested review from a team as code owners August 26, 2022 06:42
@codecov-commenter
Copy link

codecov-commenter commented Aug 26, 2022

Codecov Report

Merging #1288 (2101dbf) into main (1f36d96) will increase coverage by 0.22%.
The diff coverage is 71.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1288      +/-   ##
==========================================
+ Coverage   51.34%   51.57%   +0.22%     
==========================================
  Files          68       68              
  Lines        6834     6852      +18     
==========================================
+ Hits         3509     3534      +25     
+ Misses       3067     3061       -6     
+ Partials      258      257       -1     
Impacted Files Coverage Δ
x/leverage/keeper/interest.go 79.51% <71.42%> (+7.22%) ⬆️

@RafilxTenfen RafilxTenfen self-requested a review August 26, 2022 15:37
@RafilxTenfen
Copy link
Contributor

can we backport this to 2.x.x ?

Copy link
Member

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

Could you add a bit more comments? You are investigating cases which potentially are not possible. It's OK to make that check, but let's describe it for completness when these things can happen. Otherwise it's a bit confusing.... it's like checking if 2+2 > 0.

x/leverage/keeper/interest.go Show resolved Hide resolved
x/leverage/keeper/interest.go Show resolved Hide resolved
x/leverage/keeper/keeper_test.go Outdated Show resolved Hide resolved
@toteki
Copy link
Member Author

toteki commented Aug 26, 2022

How it is possible that we can each such a long diff? The interest is accruing regularly.

Scenarios where time difference of a year would be possible

  • If a chain halt was so long, the next block would be a year later. (This is not what I expect)
  • If BlockTime behaves incorrectly (Shouldn't happen, but bugs are always possible and this one would be lethal to our users.)
  • If LastInterestTime in genesis file was modified during a hard fork, and the next block would see massive interest accrue on all borrows to catch up (we suspect this just happened on Asherah-2).

Curiously, the if lastInterestTime == 0 condition in AccrueAllInterest should have protected us, but it didn't.

@toteki
Copy link
Member Author

toteki commented Aug 26, 2022

can we backport this to 2.x.x ?

Yeah (might take a few manual adjustments on the backport PR).

Also I need to add a gov proposal types to adjust interest scalar and set reserve amounts - those will be a separate PR but if we backport them rather than modifying genesis file, we could fix Asherah-2 with a binary swap + proposals instead of directly editing genesis. Might be faster to just edit the file though.

x/leverage/keeper/interest.go Outdated Show resolved Hide resolved
@mergify mergify bot merged commit 030c464 into main Aug 30, 2022
@mergify mergify bot deleted the adam/interest-time branch August 30, 2022 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:Automerge C:x/leverage T:Bug A regression or bug in the Umee codebase.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants