Commit 6215a2e7 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

Merge pull request #1270 from ethereum-optimism/develop

Develop -> Master PR
parents ddb6580d 7edfa1a6
---
'@eth-optimism/l2geth': patch
---
Give a better error message for when the fee is too high when sending transactions to the sequencer
---
'@eth-optimism/l2geth': patch
---
Fix a bug in the fee logic that allowed for fees that were too low to get through
---
'@eth-optimism/integration-tests': patch
'@eth-optimism/batch-submitter': patch
'@eth-optimism/common-ts': patch
'@eth-optimism/contracts': patch
'@eth-optimism/core-utils': patch
'@eth-optimism/data-transport-layer': patch
'@eth-optimism/message-relayer': patch
'@eth-optimism/smock': patch
---
Update the typescript version to `4.3.5`
...@@ -3,6 +3,7 @@ package fees ...@@ -3,6 +3,7 @@ package fees
import ( import (
"errors" "errors"
"fmt" "fmt"
"math"
"math/big" "math/big"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -115,7 +116,7 @@ func PaysEnough(opts *PaysEnoughOpts) error { ...@@ -115,7 +116,7 @@ func PaysEnough(opts *PaysEnoughOpts) error {
return fmt.Errorf("%w: no expected fee", errMissingInput) return fmt.Errorf("%w: no expected fee", errMissingInput)
} }
fee := opts.ExpectedFee fee := new(big.Int).Set(opts.ExpectedFee)
// Allow for a downward buffer to protect against L1 gas price volatility // Allow for a downward buffer to protect against L1 gas price volatility
if opts.ThresholdDown != nil { if opts.ThresholdDown != nil {
fee = mulByFloat(fee, opts.ThresholdDown) fee = mulByFloat(fee, opts.ThresholdDown)
...@@ -129,7 +130,7 @@ func PaysEnough(opts *PaysEnoughOpts) error { ...@@ -129,7 +130,7 @@ func PaysEnough(opts *PaysEnoughOpts) error {
if opts.ThresholdUp != nil { if opts.ThresholdUp != nil {
// overpaying = user fee - expected fee // overpaying = user fee - expected fee
overpaying := new(big.Int).Sub(opts.UserFee, opts.ExpectedFee) overpaying := new(big.Int).Sub(opts.UserFee, opts.ExpectedFee)
threshold := mulByFloat(overpaying, opts.ThresholdUp) threshold := mulByFloat(opts.ExpectedFee, opts.ThresholdUp)
// if overpaying > threshold, return error // if overpaying > threshold, return error
if overpaying.Cmp(threshold) == 1 { if overpaying.Cmp(threshold) == 1 {
return ErrFeeTooHigh return ErrFeeTooHigh
...@@ -140,9 +141,10 @@ func PaysEnough(opts *PaysEnoughOpts) error { ...@@ -140,9 +141,10 @@ func PaysEnough(opts *PaysEnoughOpts) error {
func mulByFloat(num *big.Int, float *big.Float) *big.Int { func mulByFloat(num *big.Int, float *big.Float) *big.Int {
n := new(big.Float).SetUint64(num.Uint64()) n := new(big.Float).SetUint64(num.Uint64())
n = n.Mul(n, float) product := n.Mul(n, float)
value, _ := float.Uint64() pfloat, _ := product.Float64()
return new(big.Int).SetUint64(value) rounded := math.Ceil(pfloat)
return new(big.Int).SetUint64(uint64(rounded))
} }
// calculateL1GasLimit computes the L1 gasLimit based on the calldata and // calculateL1GasLimit computes the L1 gasLimit based on the calldata and
......
...@@ -157,13 +157,40 @@ func TestPaysEnough(t *testing.T) { ...@@ -157,13 +157,40 @@ func TestPaysEnough(t *testing.T) {
}, },
"fee-threshold-up": { "fee-threshold-up": {
opts: &PaysEnoughOpts{ opts: &PaysEnoughOpts{
UserFee: common.Big3, UserFee: common.Big256,
ExpectedFee: common.Big1, ExpectedFee: common.Big1,
ThresholdUp: new(big.Float).SetFloat64(1.5), ThresholdUp: new(big.Float).SetFloat64(1.5),
ThresholdDown: nil, ThresholdDown: nil,
}, },
err: ErrFeeTooHigh, err: ErrFeeTooHigh,
}, },
"fee-too-low-high": {
opts: &PaysEnoughOpts{
UserFee: new(big.Int).SetUint64(10_000),
ExpectedFee: new(big.Int).SetUint64(1),
ThresholdUp: new(big.Float).SetFloat64(3),
ThresholdDown: new(big.Float).SetFloat64(0.8),
},
err: ErrFeeTooHigh,
},
"fee-too-low-down": {
opts: &PaysEnoughOpts{
UserFee: new(big.Int).SetUint64(1),
ExpectedFee: new(big.Int).SetUint64(10_000),
ThresholdUp: new(big.Float).SetFloat64(3),
ThresholdDown: new(big.Float).SetFloat64(0.8),
},
err: ErrFeeTooLow,
},
"fee-too-low-down-2": {
opts: &PaysEnoughOpts{
UserFee: new(big.Int).SetUint64(0),
ExpectedFee: new(big.Int).SetUint64(10_000),
ThresholdUp: new(big.Float).SetFloat64(3),
ThresholdDown: new(big.Float).SetFloat64(0.8),
},
err: ErrFeeTooLow,
},
} }
for name, tt := range tests { for name, tt := range tests {
......
...@@ -858,9 +858,6 @@ func (s *SyncService) verifyFee(tx *types.Transaction) error { ...@@ -858,9 +858,6 @@ func (s *SyncService) verifyFee(tx *types.Transaction) error {
// Only count the calldata here as the overhead of the fully encoded // Only count the calldata here as the overhead of the fully encoded
// RLP transaction is handled inside of EncodeL2GasLimit // RLP transaction is handled inside of EncodeL2GasLimit
expectedTxGasLimit := fees.EncodeTxGasLimit(tx.Data(), l1GasPrice, l2GasLimit, l2GasPrice) expectedTxGasLimit := fees.EncodeTxGasLimit(tx.Data(), l1GasPrice, l2GasLimit, l2GasPrice)
if err != nil {
return err
}
// This should only happen if the unscaled transaction fee is greater than 18.44 ETH // This should only happen if the unscaled transaction fee is greater than 18.44 ETH
if !expectedTxGasLimit.IsUint64() { if !expectedTxGasLimit.IsUint64() {
...@@ -868,9 +865,10 @@ func (s *SyncService) verifyFee(tx *types.Transaction) error { ...@@ -868,9 +865,10 @@ func (s *SyncService) verifyFee(tx *types.Transaction) error {
} }
userFee := new(big.Int).Mul(new(big.Int).SetUint64(tx.Gas()), tx.GasPrice()) userFee := new(big.Int).Mul(new(big.Int).SetUint64(tx.Gas()), tx.GasPrice())
expectedFee := new(big.Int).Mul(expectedTxGasLimit, fees.BigTxGasPrice)
opts := fees.PaysEnoughOpts{ opts := fees.PaysEnoughOpts{
UserFee: userFee, UserFee: userFee,
ExpectedFee: expectedTxGasLimit.Mul(expectedTxGasLimit, fees.BigTxGasPrice), ExpectedFee: expectedFee,
ThresholdUp: s.feeThresholdUp, ThresholdUp: s.feeThresholdUp,
ThresholdDown: s.feeThresholdDown, ThresholdDown: s.feeThresholdDown,
} }
...@@ -881,7 +879,8 @@ func (s *SyncService) verifyFee(tx *types.Transaction) error { ...@@ -881,7 +879,8 @@ func (s *SyncService) verifyFee(tx *types.Transaction) error {
fees.ErrFeeTooLow, userFee, expectedTxGasLimit, fees.BigTxGasPrice) fees.ErrFeeTooLow, userFee, expectedTxGasLimit, fees.BigTxGasPrice)
} }
if errors.Is(err, fees.ErrFeeTooHigh) { if errors.Is(err, fees.ErrFeeTooHigh) {
return fmt.Errorf("%w: %d", fees.ErrFeeTooHigh, userFee) return fmt.Errorf("%w: %d, use less than %d * %f", fees.ErrFeeTooHigh, userFee,
expectedFee, s.feeThresholdDown)
} }
return err return err
} }
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
"lerna": "^4.0.0", "lerna": "^4.0.0",
"patch-package": "^6.4.7", "patch-package": "^6.4.7",
"prettier": "^2.3.1", "prettier": "^2.3.1",
"typescript": "^4.2.3" "typescript": "^4.3.5"
}, },
"scripts": { "scripts": {
"clean": "yarn lerna run clean", "clean": "yarn lerna run clean",
......
...@@ -14305,6 +14305,11 @@ typescript@^4.2.3, typescript@^4.3.4: ...@@ -14305,6 +14305,11 @@ typescript@^4.2.3, typescript@^4.3.4:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.4.tgz#3f85b986945bcf31071decdd96cf8bfa65f9dcbc" resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.4.tgz#3f85b986945bcf31071decdd96cf8bfa65f9dcbc"
integrity sha512-uauPG7XZn9F/mo+7MrsRjyvbxFpzemRjKEZXS4AK83oP2KKOJPvb+9cO/gmnv8arWZvhnjVOXz7B49m1l0e9Ew== integrity sha512-uauPG7XZn9F/mo+7MrsRjyvbxFpzemRjKEZXS4AK83oP2KKOJPvb+9cO/gmnv8arWZvhnjVOXz7B49m1l0e9Ew==
typescript@^4.3.5:
version "4.3.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4"
integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==
typewise-core@^1.2, typewise-core@^1.2.0: typewise-core@^1.2, typewise-core@^1.2.0:
version "1.2.0" version "1.2.0"
resolved "https://registry.yarnpkg.com/typewise-core/-/typewise-core-1.2.0.tgz#97eb91805c7f55d2f941748fa50d315d991ef195" resolved "https://registry.yarnpkg.com/typewise-core/-/typewise-core-1.2.0.tgz#97eb91805c7f55d2f941748fa50d315d991ef195"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment