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

feat[geth]: add gas pricer for congestion fees #1103

Merged
merged 3 commits into from
Jul 8, 2021
Merged

Conversation

karlfloersch
Copy link
Contributor

@karlfloersch karlfloersch commented Jun 15, 2021

Description
Adds a new Go package to the monorepo, go/gas-oracle that includes the gas pricing algorithms in the gasprices package and a service to automatically update gas prices in the oracle package.

The gasprices package has unit tests written by @karlfloersch and the oracle package has unit tests written by @tynes. These tests run in CI and the code is also linted in CI with 2 new Github workflows added.

The main.go file is the entrypoint to the gas-oracle service, that polls the sequencer to see how much gas is being used and then it sends transactions to the sequencer to update the L2 gas price. This means that the service must be configured with the OVM_GasPriceOracle Owner key. As gas is used over time, the algorithms in the gasprices package will return values for the gas-oracle to use when updating the gas price.

It will only update the L2 gas price when the change is significant enough - ie only update the gas price if it changes more than 5%, this is to save the need to send additional transactions to the chain. The significance factor can be configured via CLI. All config options are documented in the README.md.

A follow up PR will add a docker build/tag/publish Github workflow

Fixes OP-874

@changeset-bot
Copy link

changeset-bot bot commented Jun 15, 2021

🦋 Changeset detected

Latest commit: c718bcd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@eth-optimism/gas-oracle Patch

Not sure what this means? Click here to learn what changesets are.

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

@codecov-commenter
Copy link

codecov-commenter commented Jun 16, 2021

Codecov Report

Merging #1103 (85ec67c) into develop (99e3adb) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #1103   +/-   ##
========================================
  Coverage    86.05%   86.05%           
========================================
  Files           49       49           
  Lines         1936     1936           
  Branches       307      307           
========================================
  Hits          1666     1666           
  Misses         270      270           
Impacted Files Coverage Δ
...cts/optimistic-ethereum/OVM/predeploys/OVM_ETH.sol 0.00% <0.00%> (ø)
...optimistic-ethereum/libraries/utils/Lib_Buffer.sol 100.00% <0.00%> (ø)
...imistic-ethereum/libraries/trie/Lib_MerkleTrie.sol 98.30% <0.00%> (ø)
...mistic-ethereum/OVM/execution/OVM_StateManager.sol 79.79% <0.00%> (ø)
...mistic-ethereum/OVM/predeploys/ERC1820Registry.sol 0.00% <0.00%> (ø)
...mistic-ethereum/libraries/utils/Lib_ErrorUtils.sol 100.00% <0.00%> (ø)
...mistic-ethereum/libraries/utils/Lib_MerkleTree.sol 100.00% <0.00%> (ø)
...istic-ethereum/OVM/execution/OVM_SafetyChecker.sol 100.00% <0.00%> (ø)
...stic-ethereum/OVM/verification/OVM_BondManager.sol 100.00% <0.00%> (ø)
...ic-ethereum/OVM/chain/OVM_StateCommitmentChain.sol 87.50% <0.00%> (ø)
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 99e3adb...85ec67c. Read the comment docs.

@karlfloersch karlfloersch marked this pull request as ready for review June 16, 2021 17:13
@karlfloersch
Copy link
Contributor Author

Good catch @tynes updated it!

@tynes tynes mentioned this pull request Jun 17, 2021
@tynes tynes force-pushed the feat/gas-pricer branch from 6ad6470 to 87c8757 Compare June 25, 2021 23:09
@karlfloersch karlfloersch marked this pull request as draft June 26, 2021 00:00
@karlfloersch karlfloersch marked this pull request as ready for review June 28, 2021 06:18
@karlfloersch
Copy link
Contributor Author

@tynes sorry I didn't notice that you had integrated the gas price oracle service into this PR. That's my bad.

Do you think it makes sense to split up these PRs so we can get the business logic reviewed first and then get the service reviewed?

@tynes
Copy link
Contributor

tynes commented Jun 28, 2021

@tynes sorry I didn't notice that you had integrated the gas price oracle service into this PR. That's my bad.

Do you think it makes sense to split up these PRs so we can get the business logic reviewed first and then get the service reviewed?

I can split up the PRs, basing it on the same branch was a lot easier to get it working with your changes. My main concern about doing the split of the code is that there are loglines in the library itself which is kind of an antipattern. This means that we could work on better abstractions for the service to consume. All of the loglines should be happening in the service itself.

Edit: @karlfloersch I'd prefer to not break this up unless part of breaking it up involved refactoring the interface such that we didn't need to have loglines inside of the library itself

@github-actions github-actions bot added A-ci and removed A-geth labels Jun 29, 2021
@tynes
Copy link
Contributor

tynes commented Jun 29, 2021

So now that I see we are in the rebase and merge workflow, I will force push this with a clean git history

Copy link
Contributor Author

@karlfloersch karlfloersch left a comment

Choose a reason for hiding this comment

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

This is awesome. I left a bunch of comments all over the place, most important notes were around the config.

That said, I love the way you tested this API -- the logic inside start & loop are boilerplate, so it feels less critical to add intensive testing there, but the core logic which connects the GasPriceUpdater/GasPricer to the chain are nicely tested. I have high hopes for this package being quite stable!

Can anyone think of other high leverage unit tests that we can add? I really want to hone our abilities to write testable code & I think this service is a good example of a step in that direction. Very curious if there are more tests folks can think of!

go/gas-oracle/README.md Outdated Show resolved Hide resolved
go/gas-oracle/README.md Outdated Show resolved Hide resolved
--transaction-gas-price value (default: 0) [$GAS_PRICE_ORACLE_TRANSACTION_GAS_PRICE]
--loglevel value log level to emit to the screen (default: 3)
--floor-price value gas price floor (default: 0)
--target-gas-per-second value target gas per second (default: 0)
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 default value is not something that can be used in practice. Maybe just make this a required flag?

Copy link
Contributor

Choose a reason for hiding this comment

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

If we do not specify a default then it prints the default as the zero value, https://tour.golang.org/basics/12

--target-gas-per-second value target gas per second (default: 0)
--max-percent-change-per-epoch value max percent change of gas price per second (default: 0)
--average-block-gas-limit-per-epoch value average block gas limit per epoch (default: 1.1e+07)
--epoch-length-seconds value length of epochs in seconds (default: 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe make required or set to a reasonable value, maybe 30?

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't see this until after I updated it to 10. I'm happy to update all of them in one go to reasonable values if you know what the most reasonable values are for them

go/gas-oracle/abis/OVM_GasPriceOracle.bin Outdated Show resolved Hide resolved
go/gas-oracle/oracle/gas_price_oracle.go Show resolved Hide resolved
go/gas-oracle/oracle/gas_price_oracle.go Outdated Show resolved Hide resolved
go/gas-oracle/oracle/gas_price_oracle.go Outdated Show resolved Hide resolved
@tynes tynes force-pushed the feat/gas-pricer branch from d53b071 to c98850c Compare June 30, 2021 23:10
go/gas-oracle/Makefile Outdated Show resolved Hide resolved
@@ -0,0 +1,99 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Make symbolic link to the contracts

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not going to make this a symbolic link because changes could cause the program to not compile and the binding is committed into the repo and building it is not part of the build step so if this is a symlink then it can get out of date with the binding. Updating it should be explicit and the only time it should change in the near future is for #1190

log.Trace("fetched L2 tx.gasPrice", "gas-price", gasPrice)
opts.GasPrice = gasPrice
} else {
// Allow a configurable gas price to be set
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO: add a polling cache to the sync service that allows through 0 gas price txs iff it is the owner of the OVM_GasPriceOracle

@tynes tynes force-pushed the feat/gas-pricer branch 5 times, most recently from 55a2f69 to 7922229 Compare July 7, 2021 19:58
@tynes tynes force-pushed the feat/gas-pricer branch 2 times, most recently from 569e734 to 3839d6a Compare July 7, 2021 23:06
tynes and others added 2 commits July 7, 2021 16:08
The `gasprices` package implements the logic that updates
L2 gasprices on the Optimistic Ethereum Network.

Co-authored-by: Karl Floersch <[email protected]>
This commit adds the `gas-oracle` which is an offchain entity
that sends transactions to L2 to update the gas price. It must
be configured with a private key as the `OVM_GasPriceOracle`
is owned.

The `gas-oracle` is added to the changesets setup.

Tests are included as well as CI. Dockerizing will happen
in a follow up PR.
@tynes tynes force-pushed the feat/gas-pricer branch 3 times, most recently from 552ef46 to c718bcd Compare July 7, 2021 23:55
Adds a dockerfile for the `gas-oracle` as well as adding it as
a service in the `docker-compose.yaml`. It is not enabled by
default due to memory issues in CI already happening occasionally
where the integration tests are oom killed.

The `gas-oracle` is configured with a key that owns the
`OVM_GasPriceOracle`.

This PR adds the `gas-oracle` to the Github Actions
workflow that is responsible for publishing the docker images.
@tynes tynes merged commit 88832fc into develop Jul 8, 2021
@tynes tynes deleted the feat/gas-pricer branch July 8, 2021 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ops Area: ops
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants