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

Skip interest accrual if already accrued in the same block #182

Merged
merged 6 commits into from
Jul 31, 2023

Conversation

makcandrov
Copy link
Contributor

Jean-Grimal
Jean-Grimal previously approved these changes Jul 26, 2023
pakim249CAL
pakim249CAL previously approved these changes Jul 26, 2023
Rubilmax
Rubilmax previously approved these changes Jul 26, 2023
@makcandrov makcandrov requested a review from QGarchery July 26, 2023 14:08
Copy link
Contributor

@MathisGD MathisGD left a comment

Choose a reason for hiding this comment

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

Can you provide a gas diff (with your assumptions etc) please

@makcandrov
Copy link
Contributor Author

The current testing suite already performs several operations in the same block. The gas diff output is as follows:

image

I created two custom simple tests that execute two operations on the same market, one with 1 block in between, and one without:

image

src/Blue.sol Show resolved Hide resolved
MerlinEgalite
MerlinEgalite previously approved these changes Jul 26, 2023
@Rubilmax
Copy link
Collaborator

Rubilmax commented Jul 26, 2023

@makcandrov can you run the main hardhat test suite pls? It also mines up to 100 blocks 50% of the time, pls?

IMO, having this PR + expecting integrators to accrue interests by exposing the function public is optimal. So we wouldn't need #171 or #138, which are sub-optimal. Offchain, you can just staticcall accrueInterests.

@makcandrov
Copy link
Contributor Author

Is there an easy way to make a gas diff with hadhat?

@Rubilmax
Copy link
Collaborator

Rubilmax commented Jul 26, 2023

Is there an easy way to make a gas diff with hadhat?

There's none, you have to compare results ahah:
image

EDIT: on avg, the change is insignificant according to hardhat tests. I'll compare by never mining blocks:
image

EDIT2: perhaps is it because the IRM is too simple? I can't register any difference in gas cost using hardhat tests

@MathisGD
Copy link
Contributor

Is there an easy way to make a gas diff with hadhat?

we could do it though, it does not seem to hard and there are great software devs in this room

@MathisGD
Copy link
Contributor

Can we make sure that with a heavier IRM we have the results that we expect please ?

@makcandrov
Copy link
Contributor Author

I can't register any difference in gas cost using hardhat tests

I did notice a notable difference with Foundry tests (I also used a custom one without fuzzing) (see here). Can't it be a Hardhat quirk? I don't know much about Hardhat, but is it possible that it skips a block between each call by default?

@makcandrov
Copy link
Contributor Author

I conducted some debugging, and indeed, by default, a block is mined after each transaction. It can be disabled by specifying it in the config (thanks StackOverflow):

networks: {
  hardhat: {
    mining: {
      auto: false,
      interval: 5000
    }
  }
}

However, with these settings, the liquidation tests fail (even on the main branch), so I'm still investigating...

@makcandrov
Copy link
Contributor Author

I tried to compare using hardhat, but not mining a block after each transaction produces all kinds of bugs from hardhat. I guess we'll have to settle for Foundry gas diff for now...

@makcandrov makcandrov requested a review from MathisGD July 31, 2023 07:57
@Rubilmax
Copy link
Collaborator

Rubilmax commented Jul 31, 2023

I tried it and here's how I made it work: #198

Because blocks are still mined sometimes, only the minimum gas cost is relevant to look at:
image

@makcandrov
Copy link
Contributor Author

Very nice, thanks!

src/Blue.sol Show resolved Hide resolved
MathisGD
MathisGD previously approved these changes Jul 31, 2023
Jean-Grimal
Jean-Grimal previously approved these changes Jul 31, 2023
pakim249CAL
pakim249CAL previously approved these changes Jul 31, 2023
@MathisGD MathisGD merged commit 4e10a7b into main Jul 31, 2023
@MathisGD MathisGD deleted the refactor/skip-interest-accrual branch July 31, 2023 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Skip interest accrual if already accrued in the same block?
6 participants