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: rollup gasPrices RPC endpoint #1136

Merged
merged 3 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/little-badgers-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@eth-optimism/integration-tests': patch
'@eth-optimism/l2geth': patch
---

Add new RPC endpoint `rollup_gasPrices`
11 changes: 11 additions & 0 deletions integration-tests/test/rpc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,15 @@ describe('Basic RPC tests', () => {
.reverted
})
})

describe('rollup_gasPrices', () => {
it('should return the L1 and L2 gas prices', async () => {
const result = await provider.send('rollup_gasPrices', []);
const l1GasPrice = await env.l1Wallet.provider.getGasPrice()
const l2GasPrice = await env.gasPriceOracle.gasPrice()
Copy link
Contributor

Choose a reason for hiding this comment

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

Any chance this could result in a flaky test if the gas price oracle is updated immediately after the call to rollup_gasPrices?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah this test will be a little sketchy against kovan

Copy link
Contributor

Choose a reason for hiding this comment

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

but I can't think of a good alternative to test. Probably best to just skip this test on Kovan

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can add them all to a Promise.all to slightly decrease the chance of race condition


expect(BigNumber.from(result.l1GasPrice)).to.deep.eq(l1GasPrice)
expect((BigNumber.from(result.l2GasPrice))).to.deep.eq(l2GasPrice)
})
})
})
9 changes: 8 additions & 1 deletion integration-tests/test/shared/env.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getContractFactory } from '@eth-optimism/contracts'
import { getContractFactory, predeploys } from '@eth-optimism/contracts'
import { Watcher } from '@eth-optimism/core-utils'
import { Contract, utils, Wallet } from 'ethers'
import {
Expand Down Expand Up @@ -32,6 +32,7 @@ export class OptimismEnv {
ovmEth: Contract
l2Bridge: Contract
l2Messenger: Contract
gasPriceOracle: Contract

// The L1 <> L2 State watcher
watcher: Watcher
Expand All @@ -47,6 +48,7 @@ export class OptimismEnv {
this.ovmEth = args.ovmEth
this.l2Bridge = args.l2Bridge
this.l2Messenger = args.l2Messenger
this.gasPriceOracle = args.gasPriceOracle
this.watcher = args.watcher
this.l1Wallet = args.l1Wallet
this.l2Wallet = args.l2Wallet
Expand Down Expand Up @@ -79,12 +81,17 @@ export class OptimismEnv {
.connect(l1Wallet)
.attach(ctcAddress)

const gasPriceOracle = getContractFactory('OVM_GasPriceOracle')
.connect(l2Wallet)
.attach(predeploys.OVM_GasPriceOracle)

return new OptimismEnv({
addressManager,
l1Bridge,
ctc,
l1Messenger,
ovmEth,
gasPriceOracle,
l2Bridge,
l2Messenger,
watcher,
Expand Down
21 changes: 21 additions & 0 deletions l2geth/internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1983,6 +1983,27 @@ func (api *PublicRollupAPI) GetInfo(ctx context.Context) rollupInfo {
}
}

type gasPrices struct {
L1GasPrice *hexutil.Big `json:"l1GasPrice"`
L2GasPrice *hexutil.Big `json:"l2GasPrice"`
}

// GasPrices returns the L1 and L2 gas price known by the node
func (api *PublicRollupAPI) GasPrices(ctx context.Context) (*gasPrices, error) {
l1GasPrice, err := api.b.SuggestL1GasPrice(ctx)
if err != nil {
return nil, err
}
l2GasPrice, err := api.b.SuggestL2GasPrice(ctx)
if err != nil {
return nil, err
}
return &gasPrices{
L1GasPrice: (*hexutil.Big)(l1GasPrice),
L2GasPrice: (*hexutil.Big)(l2GasPrice),
}, nil
}

// PrivatelRollupAPI provides private RPC methods to control the sequencer.
// These methods can be abused by external users and must be considered insecure for use by untrusted users.
type PrivateRollupAPI struct {
Expand Down