Skip to content
This repository has been archived by the owner on Apr 11, 2021. It is now read-only.

Sequencer Fee Pricing Part 2: Electric Boogaloo: Override EstimateGas to take data price into account #273

Merged
merged 24 commits into from
Apr 9, 2021

Conversation

gakonst
Copy link
Contributor

@gakonst gakonst commented Mar 10, 2021

Description

Fixes https://github.com/ethereum-optimism/roadmap/issues/715:

  1. implements gas estimation as follows: rollupTxSize * dataPrice + executionPrice * gasUsed, where executionPrice is fetched via the standard eth_gasPrice rules that geth uses based on the current l2 congestion, and dataPrice is a value set by the sequencer based on the current l1 congestion. gasUsed is the standard result of eth_estimateGas for a transaction, and rollupTxSize is the size of the serialized rollup tx if it were published on L1
    1. eth_gasPrice is set to always return 1 to clients
    2. eth_estimateGas returns the overridden value from step 1, this means that transactions with GasLimit > block.GasLimit are now valid, requiring that we disable a check in the mempool. It's not clear if this approach is DoS-safe.
  2. the L1 gas price is automatically fetched from the Data Transport Layer at the beginning of the sequencing loop
  3. allows the sequencer to configure the L1 Gas Price over a rollup_personal namespace via a setL1GasPrice method. This approach is nice because the gasPrice is stored in memory, configurable via CLI/RPC and requires nothing else.

@gakonst gakonst marked this pull request as draft March 10, 2021 13:43
@gakonst gakonst requested a review from karlfloersch March 10, 2021 13:46
internal/ethapi/api.go Outdated Show resolved Hide resolved
eth/backend.go Outdated Show resolved Hide resolved
eth/backend.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@tynes tynes left a comment

Choose a reason for hiding this comment

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

This approach generally looks good so far

internal/ethapi/api.go Show resolved Hide resolved
internal/ethapi/api.go Show resolved Hide resolved
Copy link
Contributor

@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.

Awesome! This looks great to me so far! Structure seems pretty perfect. I'm curious what is going wrong with the unit tests though hmm

internal/ethapi/api.go Show resolved Hide resolved
internal/ethapi/api.go Outdated Show resolved Hide resolved
internal/ethapi/api.go Show resolved Hide resolved
@gakonst gakonst changed the title feat: Sequencer Fee Pricing Sequencer Fee Pricing Part 2: Override EstimateGas to take data price into account Mar 11, 2021
@gakonst gakonst changed the base branch from master to fix/gas-estimation March 11, 2021 14:02
@gakonst gakonst marked this pull request as ready for review March 11, 2021 14:07
@smartcontracts smartcontracts changed the title Sequencer Fee Pricing Part 2: Override EstimateGas to take data price into account Sequencer Fee Pricing Part 2: Electric Boogaloo: Override EstimateGas to take data price into account Mar 11, 2021
@gakonst gakonst force-pushed the fix/gas-estimation branch from da52ce3 to 5081b63 Compare March 17, 2021 18:37
@gakonst gakonst changed the base branch from fix/gas-estimation to master March 18, 2021 10:43
@gakonst gakonst changed the base branch from master to fix/gas-estimation March 18, 2021 10:43
@gakonst gakonst requested a review from tynes March 18, 2021 10:48
Copy link
Collaborator

@tynes tynes left a comment

Choose a reason for hiding this comment

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

Generally looks good to me, left a few comments

internal/ethapi/api.go Show resolved Hide resolved
rollup/sync_service.go Show resolved Hide resolved
internal/ethapi/api.go Outdated Show resolved Hide resolved
/// ROLLUP_BASE_TX_SIZE is the encoded rollup transaction's compressed size excluding
/// the variable length data.
/// Ref: https://github.com/ethereum-optimism/contracts/blob/409f190518b90301db20d0d4f53760021bc203a8/contracts/optimistic-ethereum/OVM/precompiles/OVM_SequencerEntrypoint.sol#L47
var ROLLUP_BASE_TX_SIZE int = 96
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will likely need to change due to ethereum-optimism/contracts#300
Also what do you think about making this a const?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 if that PR gets merged first, I'll adjust it. This means I'll have to serialize the transaction each time, instead of assuming that the data is constant size right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yup, will need to rlp.EncodeToBytes and use the length of that -

func EncodeToBytes(val interface{}) ([]byte, error) {

core/rollup_fee.go Outdated Show resolved Hide resolved
rollup/sync_service.go Show resolved Hide resolved
@gakonst gakonst force-pushed the fix/gas-estimation branch from 5081b63 to 117494d Compare March 23, 2021 10:41
@gakonst gakonst force-pushed the feat/fee-pricing branch 2 times, most recently from b236ab7 to f6bf300 Compare March 23, 2021 10:52
@gakonst gakonst changed the base branch from fix/gas-estimation to master March 23, 2021 11:22
smartcontracts and others added 2 commits March 29, 2021 16:50
* experimenting with gas fudge factor

* fix formatting

* try using 1m gas constant

* Add log statement for the gas estimate

* Add more detail to gas estimate log

* one more log edit

* Try new formula

* Bump base gas

* Even more base gas

* even more

* Just 1m?

* one more time

* Final cleanup

* Minor fix

* Update internal/ethapi/api.go

* don't use cap-1

* Make sure data is not nil

Co-authored-by: Karl Floersch <[email protected]>
@smartcontracts smartcontracts self-requested a review as a code owner April 5, 2021 20:48
@@ -585,13 +590,15 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
// whitelisted, preventing any associated transaction from being dropped out of the pool
// due to pricing constraints.
func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err error) {
log.Debug("received tx", "gas", tx.Gas(), "gasprice", tx.GasPrice().Uint64())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Transactions are not added to the TxPool so this should never log

Copy link
Contributor

@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.

LGTM

@tynes tynes merged commit 30b541a into master Apr 9, 2021
@tynes tynes deleted the feat/fee-pricing branch April 9, 2021 04:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants