-
Notifications
You must be signed in to change notification settings - Fork 53
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
refactor: use early return in _accrueInterests
#233
Conversation
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.
This eases the code reading
Lol have you talked with @MathisGD?
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.
I'm ok with either, with a slight preference to applying the changes of this PR.
115c848
485bec0
115c848
to
485bec0
Compare
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.
This early return (but same for the previous if):
- saves a lot of gas when you _accrueInterest and the totalBorrow is zero
- cost a little bit of gas to any other interaction (not sure how much)
Assuming that a market very rarely is at zero total borrow it might not be worth from a total gas spent pov. Wdyt ?
If we assume this check costs 1 warm SLOAD + 1 equality check + some stack management, it should cost 150 gas max Because of the order of magnitude of the gas cost and how often a market has no borrow, it's not much of a matter to me but I prefer having it to decrease the gas cost of suppliers at the beginning of a market (early returns or if conditions are dangerous to me when a software evolves a lot ; which is not the case of Blue thanks to your fight for minimalism) |
Maybe we can roll back and store |
c96d67e
Signed-off-by: julien <[email protected]>
Actually I just realized that removing the condition now makes Blue emit |
I don't understand why the early return is removed if Moreover, if this check isn't done in Blue, it will need to be done in the IRM, because the IRM usually divides by Therefore, this change doesn't save any gas in the general case. |
I support your point but I don't get this. Dividing by |
|
Indeed, but the IRM cannot assume it'll be queried only when |
I guess it depends on the point of view. Both are ok for me. Currently, that's not the case with our mock IRM (which is why the hardhat tests fail btw). But anyway, I think we should skip the IRM call if there is no borrow. |
Agree with Maxime in the end, let's close this |
Pull request
Use early return instead of wrapping multiple lines of code with a if block.
This eases the code reading
The
totalBorrow[id] != 0
is not useful. All the logic is ok since you're adding 0 interests.The only consideration of letting all the logic wrapped is in case of a non-borrowed market, you'll Emit an AccrueInterest event with 0 interest generated, which is an edge case in fact.
So I suggest just to add
0
if the market is not borrowed