-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
20 changed files
with
2,528 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@eth-optimism/gas-oracle': patch | ||
--- | ||
|
||
Initial implementation of the `gas-oracle` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: gas-oracle unit tests | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'go/gas-oracle/**' | ||
branches: | ||
- 'master' | ||
- 'develop' | ||
- '*rc' | ||
- 'regenesis/*' | ||
pull_request: | ||
paths: | ||
- 'go/gas-oracle/**' | ||
branches: | ||
- 'master' | ||
- 'develop' | ||
- '*rc' | ||
- 'regenesis/*' | ||
workflow_dispatch: | ||
|
||
defaults: | ||
run: | ||
working-directory: ./go/gas-oracle | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.16.x | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install | ||
run: make | ||
|
||
- name: Test | ||
run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: golangci-lint | ||
on: | ||
push: | ||
paths: | ||
- 'go/gas-oracle/**' | ||
branches: | ||
- 'master' | ||
- 'develop' | ||
- '*rc' | ||
- 'regenesis/*' | ||
pull_request: | ||
paths: | ||
- 'go/gas-oracle/**' | ||
branches: | ||
- 'master' | ||
- 'develop' | ||
- '*rc' | ||
- 'regenesis/*' | ||
jobs: | ||
golangci: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v2 | ||
with: | ||
version: v1.29 | ||
working-directory: go/gas-oracle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
gas-oracle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
SHELL := /bin/bash | ||
|
||
GITCOMMIT := $(shell git rev-parse HEAD) | ||
GITDATE := $(shell git show -s --format='%ct') | ||
GITVERSION := $(shell cat package.json | jq .version) | ||
|
||
LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT) | ||
LDFLAGSSTRING +=-X main.GitDate=$(GITDATE) | ||
LDFLAGSSTRING +=-X main.GitVersion=$(GITVERSION) | ||
LDFLAGS :=-ldflags "$(LDFLAGSSTRING)" | ||
|
||
gas-oracle: | ||
env GO111MODULE=on go build $(LDFLAGS) | ||
|
||
clean: | ||
rm gas-oracle | ||
|
||
test: | ||
go test -v ./... | ||
|
||
lint: | ||
golangci-lint run ./... | ||
|
||
binding: | ||
$(eval temp := $(shell mktemp)) | ||
|
||
cat abis/OVM_GasPriceOracle.json \ | ||
| jq -r .bin > $(temp) | ||
|
||
cat abis/OVM_GasPriceOracle.json \ | ||
| jq .abi \ | ||
| abigen --pkg bindings \ | ||
--abi - \ | ||
--out bindings/gaspriceoracle.go \ | ||
--type GasPriceOracle \ | ||
--bin $(temp) | ||
|
||
rm $(temp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# gas-oracle | ||
|
||
This service is responsible for sending transactions to the Sequencer to update | ||
the L2 gas price over time. It consists of a set of functions found in the | ||
`gasprices` package that define the parameters of how the gas prices are updated | ||
and then the `oracle` package is responsible for observing the Sequencer over | ||
time and send transactions that actually do update the gas prices. | ||
|
||
### Generating the Bindings | ||
|
||
Note: this only needs to happen if the ABI of the `OVM_GasPriceOracle` is | ||
updated. | ||
|
||
This project uses `abigen` to automatically create smart contract bindings in | ||
Go. To generate the bindings, be sure that the latest ABI and bytecode are | ||
committed into the repository in the `abis` directory. | ||
|
||
Use the following command to generate the bindings: | ||
|
||
```bash | ||
$ make binding | ||
``` | ||
|
||
Be sure to use `abigen` built with the same version of `go-ethereum` as what is | ||
in the `go.mod` file. | ||
|
||
### Building the service | ||
|
||
The service can be built with the `Makefile`. A binary will be produced | ||
called the `gas-oracle`. | ||
|
||
```bash | ||
$ make gas-oracle | ||
``` | ||
|
||
### Running the service | ||
|
||
Use the `--help` flag when running the `gas-oracle` to see it's configuration | ||
options. | ||
|
||
``` | ||
NAME: | ||
gas-oracle - Remotely Control the Optimistic Ethereum Gas Price | ||
USAGE: | ||
gas-oracle [global options] command [command options] [arguments...] | ||
VERSION: | ||
0.0.0-1.10.4-stable | ||
DESCRIPTION: | ||
Configure with a private key and an Optimistic Ethereum HTTP endpoint to send transactions that update the L2 gas price. | ||
COMMANDS: | ||
help, h Shows a list of commands or help for one command | ||
GLOBAL OPTIONS: | ||
--ethereum-http-url value Sequencer HTTP Endpoint (default: "http://127.0.0.1:8545") [$GAS_PRICE_ORACLE_ETHEREUM_HTTP_URL] | ||
--chain-id value L2 Chain ID (default: 0) [$GAS_PRICE_ORACLE_CHAIN_ID] | ||
--gas-price-oracle-address value Address of OVM_GasPriceOracle (default: "0x420000000000000000000000000000000000000F") [$GAS_PRICE_ORACLE_GAS_PRICE_ORACLE_ADDRESS] | ||
--private-key value Private Key corresponding to OVM_GasPriceOracle Owner [$GAS_PRICE_ORACLE_PRIVATE_KEY] | ||
--transaction-gas-price value Hardcoded tx.gasPrice, not setting it uses gas estimation (default: 0) [$GAS_PRICE_ORACLE_TRANSACTION_GAS_PRICE] | ||
--loglevel value log level to emit to the screen (default: 3) [$GAS_PRICE_ORACLE_LOG_LEVEL] | ||
--floor-price value gas price floor (default: 1) [$GAS_PRICE_ORACLE_FLOOR_PRICE] | ||
--target-gas-per-second value target gas per second (default: 11000000) [$GAS_PRICE_ORACLE_TARGET_GAS_PER_SECOND] | ||
--max-percent-change-per-epoch value max percent change of gas price per second (default: 0.1) [$GAS_PRICE_ORACLE_MAX_PERCENT_CHANGE_PER_EPOCH] | ||
--average-block-gas-limit-per-epoch value average block gas limit per epoch (default: 1.1e+07) [$GAS_PRICE_ORACLE_AVERAGE_BLOCK_GAS_LIMIT_PER_EPOCH] | ||
--epoch-length-seconds value length of epochs in seconds (default: 10) [$GAS_PRICE_ORACLE_EPOCH_LENGTH_SECONDS] | ||
--significant-factor value only update when the gas price changes by more than this factor (default: 0.05) [$GAS_PRICE_ORACLE_SIGNIFICANT_FACTOR] | ||
--wait-for-receipt wait for receipts when sending transactions [$GAS_PRICE_ORACLE_WAIT_FOR_RECEIPT] | ||
--metrics Enable metrics collection and reporting [$GAS_PRICE_ORACLE_METRICS_ENABLE] | ||
--metrics.addr value Enable stand-alone metrics HTTP server listening interface (default: "127.0.0.1") [$GAS_PRICE_ORACLE_METRICS_HTTP] | ||
--metrics.port value Metrics HTTP server listening port (default: 6060) [$GAS_PRICE_ORACLE_METRICS_PORT] | ||
--metrics.influxdb Enable metrics export/push to an external InfluxDB database [$GAS_PRICE_ORACLE_METRICS_ENABLE_INFLUX_DB] | ||
--metrics.influxdb.endpoint value InfluxDB API endpoint to report metrics to (default: "http://localhost:8086") [$GAS_PRICE_ORACLE_METRICS_INFLUX_DB_ENDPOINT] | ||
--metrics.influxdb.database value InfluxDB database name to push reported metrics to (default: "gas-oracle") [$GAS_PRICE_ORACLE_METRICS_INFLUX_DB_DATABASE] | ||
--metrics.influxdb.username value Username to authorize access to the database (default: "test") [$GAS_PRICE_ORACLE_METRICS_INFLUX_DB_USERNAME] | ||
--metrics.influxdb.password value Password to authorize access to the database (default: "test") [$GAS_PRICE_ORACLE_METRICS_INFLUX_DB_PASSWORD] | ||
--help, -h show help | ||
--version, -v print the version | ||
``` | ||
|
||
### Testing the service | ||
|
||
The service can be tested with the `Makefile` | ||
|
||
``` | ||
$ make test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
{ | ||
"abi": [ | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "_owner", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "_initialGasPrice", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "previousOwner", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "newOwner", | ||
"type": "address" | ||
} | ||
], | ||
"name": "OwnershipTransferred", | ||
"type": "event" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "gasPrice", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "owner", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "renounceOwnership", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "_gasPrice", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "setGasPrice", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "newOwner", | ||
"type": "address" | ||
} | ||
], | ||
"name": "transferOwnership", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
} | ||
], | ||
"bin": "0x608060405234801561001057600080fd5b5060405161061d38038061061d8339818101604052604081101561003357600080fd5b5080516020909101516000610046610097565b600080546001600160a01b0319166001600160a01b0383169081178255604051929350916000805160206105fd833981519152908290a3506100878161009b565b61009082610102565b5050610201565b3390565b6100a3610097565b6001600160a01b03166100b46101f2565b6001600160a01b0316146100fd576040805162461bcd60e51b815260206004820181905260248201526000805160206105dd833981519152604482015290519081900360640190fd5b600155565b61010a610097565b6001600160a01b031661011b6101f2565b6001600160a01b031614610164576040805162461bcd60e51b815260206004820181905260248201526000805160206105dd833981519152604482015290519081900360640190fd5b6001600160a01b0381166101a95760405162461bcd60e51b81526004018080602001828103825260268152602001806105b76026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216916000805160206105fd83398151915291a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b031690565b6103a7806102106000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c8063715018a61461005c5780638da5cb5b14610066578063bf1fe4201461008a578063f2fde38b146100a7578063fe173b97146100cd575b600080fd5b6100646100e7565b005b61006e6101a5565b604080516001600160a01b039092168252519081900360200190f35b610064600480360360208110156100a057600080fd5b50356101b4565b610064600480360360208110156100bd57600080fd5b50356001600160a01b031661022d565b6100d5610341565b60408051918252519081900360200190f35b6100ef610347565b6001600160a01b03166101006101a5565b6001600160a01b03161461015b576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6000546001600160a01b031690565b6101bc610347565b6001600160a01b03166101cd6101a5565b6001600160a01b031614610228576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600155565b610235610347565b6001600160a01b03166102466101a5565b6001600160a01b0316146102a1576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b0381166102e65760405162461bcd60e51b815260040180806020018281038252602681526020018061034c6026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b60015481565b339056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373a26469706673582212205ffb3c08a20124b777934c7f2adbd124e8d73ee3f782032330e9b5c98715395a64736f6c634300070600334f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573734f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65728be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0" | ||
} |
Oops, something went wrong.