This repository has been archived by the owner on Apr 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Sequencer Fee Pricing Part 2: Electric Boogaloo: Override EstimateGas to take data price into account #273
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
4290b08
fix: add nil check when estimating gas to avoid panic during contract…
ben-chain ad78282
fix: revert DoEstimateGas changes introduced as a temp fix in #22
gakonst a1dabb6
Tweak fudge factor for Geth gas estimation (#292)
smartcontracts 486d555
feat(api): make eth_gasPrice always return 1 gwei
gakonst e99c376
feat: overload estimateGas to return the data+execution fee
gakonst 0abd730
feat: implement static L1 Gas Price oracle
gakonst eb3e487
feat: allow configuring the L1GasPrice via CLI at node startup
gakonst 40fe63a
feat: allow configuring the L1GasPrice remotely over a new private RP…
gakonst 4c78233
Sequencer Fee Pricing Part 3, feat: Pull L1Gasprice from the Data Ser…
gakonst a7eead8
chore: expose L1Gpo in the sync service
gakonst 0603746
refactor: create helper function for calculating the rollup fee
gakonst b7a2c6c
docs: add doc for rollup tx size constant
gakonst 147b81c
chore(console_test): add rollup_personal to test
gakonst 68ba95a
chore: remove empty line
gakonst ea47616
chore: adjust review comments
gakonst 32a4e5d
chore: re-order imports
gakonst 9113ae9
fix: skip txpool max gas check for rollup txs
gakonst 42c8e30
chore: debug log
gakonst bcbbfb4
fix(rollup_fee): normalize charged gas by the charged gas price
gakonst e02931d
Merge branch 'master' into feat/fee-pricing
smartcontracts 45b3516
remove intrinsic gas checks
smartcontracts 4b78e4e
move intrinsic gas check behind non-ovm codepath
smartcontracts f5eb534
remove fudging code
smartcontracts 65f2d58
fix wrong gas limit
smartcontracts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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,22 @@ | ||
package core | ||
|
||
import ( | ||
"math/big" | ||
) | ||
|
||
/// 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 | ||
const ROLLUP_BASE_TX_SIZE int = 96 | ||
|
||
/// CalculateFee calculates the fee that must be paid to the Rollup sequencer, taking into | ||
/// account the cost of publishing data to L1. | ||
/// Returns: (ROLLUP_BASE_TX_SIZE + len(data)) * dataPrice + executionPrice * gasUsed | ||
func CalculateRollupFee(data []byte, gasUsed uint64, dataPrice, executionPrice *big.Int) *big.Int { | ||
dataLen := int64(ROLLUP_BASE_TX_SIZE + len(data)) | ||
// get the data fee | ||
dataFee := new(big.Int).Mul(dataPrice, big.NewInt(dataLen)) | ||
executionFee := new(big.Int).Mul(executionPrice, new(big.Int).SetUint64(gasUsed)) | ||
fee := new(big.Int).Add(dataFee, executionFee) | ||
return fee | ||
} |
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,34 @@ | ||
package core | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
) | ||
|
||
var feeTests = map[string]struct { | ||
dataLen int | ||
gasUsed uint64 | ||
dataPrice int64 | ||
executionPrice int64 | ||
}{ | ||
"simple": {10000, 10, 20, 30}, | ||
"zero gas used": {10000, 0, 20, 30}, | ||
"zero data price": {10000, 0, 0, 30}, | ||
"zero execution price": {10000, 0, 0, 0}, | ||
} | ||
|
||
func TestCalculateRollupFee(t *testing.T) { | ||
for name, tt := range feeTests { | ||
t.Run(name, func(t *testing.T) { | ||
data := make([]byte, 0, tt.dataLen) | ||
fee := CalculateRollupFee(data, tt.gasUsed, big.NewInt(tt.dataPrice), big.NewInt(tt.executionPrice)) | ||
|
||
dataFee := uint64((ROLLUP_BASE_TX_SIZE + len(data)) * int(tt.dataPrice)) | ||
executionFee := uint64(tt.executionPrice) * tt.gasUsed | ||
expectedFee := dataFee + executionFee | ||
if fee.Cmp(big.NewInt(int64(expectedFee))) != 0 { | ||
t.Errorf("rollup fee check failed: expected %d, got %s", expectedFee, fee.String()) | ||
} | ||
}) | ||
} | ||
} |
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
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
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
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
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
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
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
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
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,24 @@ | ||
package gasprice | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
) | ||
|
||
type L1Oracle struct { | ||
gasPrice *big.Int | ||
} | ||
|
||
func NewL1Oracle(gasPrice *big.Int) *L1Oracle { | ||
return &L1Oracle{gasPrice} | ||
} | ||
|
||
/// SuggestDataPrice returns the gas price which should be charged per byte of published | ||
/// data by the sequencer. | ||
func (gpo *L1Oracle) SuggestDataPrice(ctx context.Context) (*big.Int, error) { | ||
return gpo.gasPrice, nil | ||
} | ||
|
||
func (gpo *L1Oracle) SetL1GasPrice(gasPrice *big.Int) { | ||
gpo.gasPrice = gasPrice | ||
} |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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