Skip to content

Comments

feat: L1Block uses average L1 basefee#2583

Closed
tynes wants to merge 2 commits intodevelopfrom
feat/avg-l1-basefee
Closed

feat: L1Block uses average L1 basefee#2583
tynes wants to merge 2 commits intodevelopfrom
feat/avg-l1-basefee

Conversation

@tynes
Copy link
Contributor

@tynes tynes commented May 18, 2022

Description
This PR adds L1 basefee smoothing. The final numbers are pending but I think its ok to merge this for now and then tweak the numbers later pending internal devnet simulations

@changeset-bot
Copy link

changeset-bot bot commented May 18, 2022

⚠️ No Changeset found

Latest commit: 7182950

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@mergify mergify bot requested review from Inphi and mslipper May 18, 2022 21:25
@tynes tynes force-pushed the feat/avg-l1-basefee branch from 0f7069b to 7f73802 Compare May 18, 2022 21:35
@mergify
Copy link
Contributor

mergify bot commented May 18, 2022

This PR changes implementation code, but doesn't include a changeset. Did you forget to add one?

@mergify
Copy link
Contributor

mergify bot commented May 18, 2022

Hey @tynes! This PR has merge conflicts. Please fix them before continuing review.

@mergify mergify bot added the conflict label May 18, 2022
@tynes tynes force-pushed the feat/avg-l1-basefee branch 2 times, most recently from 0ad43c4 to 5ca8db2 Compare May 18, 2022 22:05
@mergify mergify bot removed the conflict label May 18, 2022
@tynes tynes force-pushed the feat/avg-l1-basefee branch from 5ca8db2 to 51aa096 Compare May 18, 2022 22:08
@tynes
Copy link
Contributor Author

tynes commented May 19, 2022

I created some figures based on the formula used in this PR to see how changes in the basefee would impact the average value. You can see that the more skewed the ratio is, the less volatile the changes are


average * (uint256(7) / uint256(10)) + basefee * (uint256(3) / uint256(10))
70-30

average * (uint256(8) / uint256(10)) + basefee * (uint256(2) / uint256(10))
80-20

average * (uint256(5) / uint256(10)) + basefee * (uint256(5) / uint256(10))
50-50

@trianglesphere
Copy link
Contributor

Leaving comment to update gas usage of the L1 Info Deposit (see #2582). The other option (annoying) is to not meter the L1 Info transaction's gas usage at all (but that does have some nice benefits).

@mergify
Copy link
Contributor

mergify bot commented Jun 2, 2022

Hey @tynes! This PR has merge conflicts. Please fix them before continuing review.

@mergify mergify bot added the conflict label Jun 2, 2022
@tynes
Copy link
Contributor Author

tynes commented Jun 2, 2022

@K-Ho - Any progress on the numbers that we can use for this? We could do something that is "good enough" for devnet/testnet and tweak later on if necessary

@K-Ho
Copy link
Contributor

K-Ho commented Jun 3, 2022

@K-Ho - Any progress on the numbers that we can use for this? We could do something that is "good enough" for devnet/testnet and tweak later on if necessary

Currently working out the best formula to use w Michael. For now let’s just leave the averaging as a TODO and just use the vanilla basefee

@tynes tynes force-pushed the feat/avg-l1-basefee branch from ab04bae to bad2edc Compare June 7, 2022 20:22
@mergify mergify bot removed the conflict label Jun 7, 2022
Copy link
Contributor

@trianglesphere trianglesphere left a comment

Choose a reason for hiding this comment

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

Formula's wrong

@tynes
Copy link
Contributor Author

tynes commented Jun 7, 2022

Formula's wrong

I'm gonna write the formula as a library and test directly

@trianglesphere
Copy link
Contributor

I'm gonna write the formula as a library and test directly

That's one good solution. The reason that this wasn't caught in the tests is that you compared the formula to itself rather than hardcoded values which would have made it obvious that the formula was not producing numbers we expect.

@mergify
Copy link
Contributor

mergify bot commented Jun 7, 2022

Hey @tynes! This PR has merge conflicts. Please fix them before continuing review.

@mergify mergify bot added the conflict label Jun 7, 2022
@tynes tynes force-pushed the feat/avg-l1-basefee branch from 58b9751 to 78bbe86 Compare June 8, 2022 03:13
@mergify mergify bot removed the conflict label Jun 8, 2022
@tynes
Copy link
Contributor Author

tynes commented Jun 8, 2022

I'm gonna write the formula as a library and test directly

That's one good solution. The reason that this wasn't caught in the tests is that you compared the formula to itself rather than hardcoded values which would have made it obvious that the formula was not producing numbers we expect.

I've turned the logic into a library but its not yet properly tested. I think that I am using too many decimals (1e18), the basefee could technically grow large enough to lose precision. Maybe we should use less decimals (1e3) ?
Also do you think the best way to test this would be to differentially test it against an implementation in another language to ensure that there aren't precision errors?

@tynes tynes force-pushed the feat/avg-l1-basefee branch from 78bbe86 to c4e5777 Compare June 8, 2022 03:20
}

function test_averageBasefee() external {
uint256 expect = Lib_FeeSmoothing.rollingAverage(0, 3);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not sufficient as a test, we need unit tests that are realistic

function test_l1BaseFee() external {
uint256 l1BaseFee = gasOracle.l1BaseFee();
assertEq(l1BaseFee, 100);
uint256 expect = Lib_FeeSmoothing.rollingAverage(0, 100);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The value here is 30 which I believe is realistic if 70% weighted towards prev value and 30% weighted towards next value. We need unit tests for the rollingAverage function, not 100% sure of the best way to go about it

tynes added 2 commits June 7, 2022 20:43
Adds simple L1 fee smoothing to improve the UX
so that the L1 fee spikes do not impact end users
as much.
@tynes tynes force-pushed the feat/avg-l1-basefee branch from c4e5777 to 7182950 Compare June 8, 2022 03:43
@mergify
Copy link
Contributor

mergify bot commented Jun 8, 2022

Hey @tynes! This PR has merge conflicts. Please fix them before continuing review.

@mergify mergify bot added the conflict label Jun 8, 2022
@trianglesphere
Copy link
Contributor

I'm gonna write the formula as a library and test directly

That's one good solution. The reason that this wasn't caught in the tests is that you compared the formula to itself rather than hardcoded values which would have made it obvious that the formula was not producing numbers we expect.

I've turned the logic into a library but its not yet properly tested. I think that I am using too many decimals (1e18), the basefee could technically grow large enough to lose precision. Maybe we should use less decimals (1e3) ? Also do you think the best way to test this would be to differentially test it against an implementation in another language to ensure that there aren't precision errors?

I don't actually care that much about precision errors, just that the output is close enough.

In terms of decimals, during. the Yuga labs spike, the L1 base fee got up to 8 terra-wei (8e12). A uint256 can hold up to 1e77. So using 18 decimals is totally fine & won't overflow (it makes the effective max base fee 1e59 which is stupidly large).

@mslipper mslipper marked this pull request as draft June 21, 2022 17:14
@github-actions
Copy link
Contributor

github-actions bot commented Jul 6, 2022

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Jul 6, 2022
@tynes tynes removed the Stale label Jul 6, 2022
@tynes tynes closed this Jul 11, 2022
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.

5 participants