Commit 021d955c authored by Georgios Konstantopoulos's avatar Georgios Konstantopoulos Committed by GitHub

patch(l2geth): revert back to latest upstream optimism master (#28)

* patch(l2geth): revert back to latest upstream optimism master

* chore: disable android tests
parent 5f2e00a9
**/*_test.go
build/_workspace
build/_bin
tests/testdata
# Auto detect text files and perform LF normalization
* text=auto
*.sol linguist-language=Solidity
[submodule "tests"]
path = tests/testdata
url = https://github.com/ethereum/tests
Jeffrey Wilcke <jeffrey@ethereum.org>
Jeffrey Wilcke <jeffrey@ethereum.org> <geffobscura@gmail.com>
Jeffrey Wilcke <jeffrey@ethereum.org> <obscuren@obscura.com>
Jeffrey Wilcke <jeffrey@ethereum.org> <obscuren@users.noreply.github.com>
Viktor Trón <viktor.tron@gmail.com>
Joseph Goulden <joegoulden@gmail.com>
Nick Savers <nicksavers@gmail.com>
Maran Hidskes <maran.hidskes@gmail.com>
Taylor Gerring <taylor.gerring@gmail.com>
Taylor Gerring <taylor.gerring@gmail.com> <taylor.gerring@ethereum.org>
Bas van Kervel <bas@ethdev.com>
Bas van Kervel <bas@ethdev.com> <basvankervel@ziggo.nl>
Bas van Kervel <bas@ethdev.com> <basvankervel@gmail.com>
Bas van Kervel <bas@ethdev.com> <bas-vk@users.noreply.github.com>
Sven Ehlert <sven@ethdev.com>
Vitalik Buterin <v@buterin.com>
Marian Oancea <contact@siteshop.ro>
Christoph Jentzsch <jentzsch.software@gmail.com>
Heiko Hees <heiko@heiko.org>
Alex Leverington <alex@ethdev.com>
Alex Leverington <alex@ethdev.com> <subtly@users.noreply.github.com>
Zsolt Felföldi <zsfelfoldi@gmail.com>
Gavin Wood <i@gavwood.com>
Martin Becze <mjbecze@gmail.com>
Martin Becze <mjbecze@gmail.com> <wanderer@users.noreply.github.com>
Dimitry Khokhlov <winsvega@mail.ru>
Roman Mandeleil <roman.mandeleil@gmail.com>
Alec Perseghin <aperseghin@gmail.com>
Alon Muroch <alonmuroch@gmail.com>
Arkadiy Paronyan <arkadiy@ethdev.com>
Jae Kwon <jkwon.work@gmail.com>
Aaron Kumavis <kumavis@users.noreply.github.com>
Nick Dodson <silentcicero@outlook.com>
Jason Carver <jacarver@linkedin.com>
Jason Carver <jacarver@linkedin.com> <ut96caarrs@snkmail.com>
Joseph Chow <ethereum@outlook.com>
Joseph Chow <ethereum@outlook.com> ethers <TODO>
Enrique Fynn <enriquefynn@gmail.com>
Vincent G <caktux@gmail.com>
RJ Catalano <catalanor0220@gmail.com>
RJ Catalano <catalanor0220@gmail.com> <rj@erisindustries.com>
Nchinda Nchinda <nchinda2@gmail.com>
Aron Fischer <github@aron.guru> <homotopycolimit@users.noreply.github.com>
Vlad Gluhovsky <gluk256@users.noreply.github.com>
Ville Sundell <github@solarius.fi>
Elliot Shepherd <elliot@identitii.com>
Yohann Léon <sybiload@gmail.com>
Gregg Dourgarian <greggd@tempworks.com>
Casey Detrio <cdetrio@gmail.com>
Jens Agerberg <github@agerberg.me>
Nick Johnson <arachnid@notdot.net>
Henning Diedrich <hd@eonblast.com>
Henning Diedrich <hd@eonblast.com> Drake Burroughs <wildfyre@hotmail.com>
Felix Lange <fjl@twurst.com>
Felix Lange <fjl@twurst.com> <fjl@users.noreply.github.com>
Максим Чусовлянов <mchusovlianov@gmail.com>
Louis Holbrook <dev@holbrook.no>
Louis Holbrook <dev@holbrook.no> <nolash@users.noreply.github.com>
Thomas Bocek <tom@tomp2p.net>
Victor Tran <vu.tran54@gmail.com>
Justin Drake <drakefjustin@gmail.com>
Frank Wang <eternnoir@gmail.com>
Gary Rong <garyrong0905@gmail.com>
Guillaume Nicolas <guin56@gmail.com>
Sorin Neacsu <sorin.neacsu@gmail.com>
Sorin Neacsu <sorin.neacsu@gmail.com> <sorin@users.noreply.github.com>
Valentin Wüstholz <wuestholz@gmail.com>
Valentin Wüstholz <wuestholz@gmail.com> <wuestholz@users.noreply.github.com>
Armin Braun <me@obrown.io>
Ernesto del Toro <ernesto.deltoro@gmail.com>
Ernesto del Toro <ernesto.deltoro@gmail.com> <ernestodeltoro@users.noreply.github.com>
# Build Geth in a stock Go builder container
FROM golang:1.14-alpine as builder
RUN apk add --no-cache make gcc musl-dev linux-headers git
ADD . /go-ethereum
RUN cd /go-ethereum && make geth
# Pull Geth into a second stage deploy alpine container
FROM alpine:latest
RUN apk add --no-cache ca-certificates
COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/
EXPOSE 8545 8546 8547 30303 30303/udp
COPY docker/entrypoint.sh /bin
COPY docker/state_dump_entrypoint.sh /bin
RUN chmod +x /bin/entrypoint.sh \
&& chmod +x /bin/state_dump_entrypoint.sh
ENTRYPOINT ["sh", "/bin/entrypoint.sh"]
# Build Geth in a stock Go builder container
FROM golang:1.14-alpine as builder
RUN apk add --no-cache make gcc musl-dev linux-headers git
ADD . /go-ethereum
RUN cd /go-ethereum && make all
# Pull all binaries into a second stage deploy alpine container
FROM alpine:latest
RUN apk add --no-cache ca-certificates
COPY --from=builder /go-ethereum/build/bin/* /usr/local/bin/
EXPOSE 8545 8546 8547 30303 30303/udp
# Requires the root repo dir to be mounted at /mnt/go-ethereum in order to run this!
FROM golang:1.14-alpine
RUN apk add --no-cache make gcc musl-dev linux-headers git
RUN apk add --no-cache ca-certificates
EXPOSE 8545 8546 8547 30303 30303/udp
# Used to mount the code so image isn't re-built every time code changes
WORKDIR /mnt/go-ethereum
ENTRYPOINT ["sh", "./docker/dev_entrypoint.sh"]
FROM golang:1.14-alpine
RUN apk add --no-cache make gcc musl-dev linux-headers git
ENV GO111MODULE=on
COPY . /go-ethereum
RUN cd /go-ethereum && go run build/ci.go install
COPY docker/test_entrypoint.sh /bin
RUN chmod +x /bin/test_entrypoint.sh
ENTRYPOINT ["sh", "/bin/test_entrypoint.sh"]
os: Visual Studio 2015
# Clone directly into GOPATH.
clone_folder: C:\gopath\src\github.com\ethereum\go-ethereum
clone_depth: 5
version: "{branch}.{build}"
environment:
global:
GO111MODULE: on
GOPATH: C:\gopath
CC: gcc.exe
matrix:
- GETH_ARCH: amd64
MSYS2_ARCH: x86_64
MSYS2_BITS: 64
MSYSTEM: MINGW64
PATH: C:\msys64\mingw64\bin\;C:\Program Files (x86)\NSIS\;%PATH%
- GETH_ARCH: 386
MSYS2_ARCH: i686
MSYS2_BITS: 32
MSYSTEM: MINGW32
PATH: C:\msys64\mingw32\bin\;C:\Program Files (x86)\NSIS\;%PATH%
install:
- git submodule update --init
- rmdir C:\go /s /q
- appveyor DownloadFile https://dl.google.com/go/go1.14.2.windows-%GETH_ARCH%.zip
- 7z x go1.14.2.windows-%GETH_ARCH%.zip -y -oC:\ > NUL
- go version
- gcc --version
build_script:
- go run build\ci.go install
after_build:
- go run build\ci.go archive -type zip -signer WINDOWS_SIGNING_KEY -upload gethstore/builds
- go run build\ci.go nsis -signer WINDOWS_SIGNING_KEY -upload gethstore/builds
test_script:
- set CGO_ENABLED=1
- go run build\ci.go test -coverage
machine:
services:
- docker
dependencies:
cache_directories:
- "~/.ethash" # Cache the ethash DAG generated by hive for consecutive builds
- "~/.docker" # Cache all docker images manually to avoid lengthy rebuilds
override:
# Restore all previously cached docker images
- mkdir -p ~/.docker
- for img in `ls ~/.docker`; do docker load -i ~/.docker/$img; done
# Pull in and hive, restore cached ethash DAGs and do a dry run
- go get -u github.com/karalabe/hive
- (cd ~/.go_workspace/src/github.com/karalabe/hive && mkdir -p workspace/ethash/ ~/.ethash)
- (cd ~/.go_workspace/src/github.com/karalabe/hive && cp -r ~/.ethash/. workspace/ethash/)
- (cd ~/.go_workspace/src/github.com/karalabe/hive && hive --docker-noshell --client=NONE --test=. --sim=. --loglevel=6)
# Cache all the docker images and the ethash DAGs
- for img in `docker images | grep -v "^<none>" | tail -n +2 | awk '{print $1}'`; do docker save $img > ~/.docker/`echo $img | tr '/' ':'`.tar; done
- cp -r ~/.go_workspace/src/github.com/karalabe/hive/workspace/ethash/. ~/.ethash
test:
override:
# Build Geth and move into a known folder
- make geth
- cp ./build/bin/geth $HOME/geth
# Run hive and move all generated logs into the public artifacts folder
- (cd ~/.go_workspace/src/github.com/karalabe/hive && hive --docker-noshell --client=go-ethereum:local --override=$HOME/geth --test=. --sim=.)
- cp -r ~/.go_workspace/src/github.com/karalabe/hive/workspace/logs/* $CIRCLE_ARTIFACTS
......@@ -31,7 +31,7 @@ import (
)
const (
ipcAPIs = "admin:1.0 debug:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0 rollup:1.0 rollup_personal:1.0 rpc:1.0 shh:1.0 txpool:1.0 web3:1.0"
ipcAPIs = "admin:1.0 debug:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0 rollup:1.0 rpc:1.0 shh:1.0 txpool:1.0 web3:1.0"
httpAPIs = "eth:1.0 net:1.0 rpc:1.0 web3:1.0"
)
......
......@@ -164,7 +164,6 @@ var (
utils.RollupStateDumpPathFlag,
utils.RollupDiffDbFlag,
utils.RollupMaxCalldataSizeFlag,
utils.RollupL1GasPriceFlag,
}
rpcFlags = []cli.Flag{
......
......@@ -78,7 +78,6 @@ var AppHelpFlagGroups = []flagGroup{
utils.RollupStateDumpPathFlag,
utils.RollupDiffDbFlag,
utils.RollupMaxCalldataSizeFlag,
utils.RollupL1GasPriceFlag,
},
},
{
......
......@@ -879,12 +879,6 @@ var (
Value: eth.DefaultConfig.Rollup.MaxCallDataSize,
EnvVar: "ROLLUP_MAX_CALLDATA_SIZE",
}
RollupL1GasPriceFlag = BigFlag{
Name: "rollup.l1gasprice",
Usage: "The L1 gas price to use for the sequencer fees",
Value: eth.DefaultConfig.Rollup.L1GasPrice,
EnvVar: "ROLLUP_L1_GASPRICE",
}
)
// MakeDataDir retrieves the currently requested data directory, terminating
......@@ -1158,9 +1152,6 @@ func setRollup(ctx *cli.Context, cfg *rollup.Config) {
if ctx.GlobalIsSet(RollupTimstampRefreshFlag.Name) {
cfg.TimestampRefreshThreshold = ctx.GlobalDuration(RollupTimstampRefreshFlag.Name)
}
if ctx.GlobalIsSet(RollupL1GasPriceFlag.Name) {
cfg.L1GasPrice = GlobalBig(ctx, RollupL1GasPriceFlag.Name)
}
}
// setLes configures the les server and ultra light client settings from the command line flags.
......
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
}
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())
}
})
}
}
......@@ -92,9 +92,8 @@ var (
)
var (
evictionInterval = time.Minute // Time interval to check for evictable transactions
statsReportInterval = 8 * time.Second // Time interval to report transaction pool stats
gwei = big.NewInt(params.GWei) // 1 gwei, used as a flag for "rollup" transactions
evictionInterval = time.Minute // Time interval to check for evictable transactions
statsReportInterval = 8 * time.Second // Time interval to report transaction pool stats
)
var (
......@@ -538,14 +537,10 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
if tx.Value().Sign() < 0 {
return ErrNegativeValue
}
// Ensure the transaction doesn't exceed the current block limit gas.
// We skip this condition check if the transaction's gasPrice is set to 1gwei,
// which indicates a "rollup" transaction that's paying for its data.
if pool.currentMaxGas < tx.Gas() && tx.GasPrice().Cmp(gwei) != 0 {
if pool.currentMaxGas < tx.Gas() {
return ErrGasLimit
}
// Make sure the transaction is signed properly
from, err := types.Sender(pool.signer, tx)
if err != nil {
......@@ -590,7 +585,6 @@ 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())
// If the transaction is already known, discard it
hash := tx.Hash()
if pool.all.Get(hash) != nil {
......@@ -598,7 +592,6 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
knownTxMeter.Mark(1)
return false, fmt.Errorf("known transaction: %x", hash)
}
// If the transaction fails basic validation, discard it
if err := pool.validateTx(tx, local); err != nil {
log.Trace("Discarding invalid transaction", "hash", hash, "err", err)
......
......@@ -46,7 +46,6 @@ type EthAPIBackend struct {
extRPCEnabled bool
eth *Ethereum
gpo *gasprice.Oracle
l1gpo *gasprice.L1Oracle
verifier bool
gasLimit uint64
UsingOVM bool
......@@ -372,14 +371,6 @@ func (b *EthAPIBackend) SuggestPrice(ctx context.Context) (*big.Int, error) {
return b.gpo.SuggestPrice(ctx)
}
func (b *EthAPIBackend) SuggestDataPrice(ctx context.Context) (*big.Int, error) {
return b.l1gpo.SuggestDataPrice(ctx)
}
func (b *EthAPIBackend) SetL1GasPrice(ctx context.Context, gasPrice *big.Int) {
b.l1gpo.SetL1GasPrice(gasPrice)
}
func (b *EthAPIBackend) ChainDb() ethdb.Database {
return b.eth.ChainDb()
}
......
......@@ -15,7 +15,6 @@ func TestGasLimit(t *testing.T) {
extRPCEnabled: false,
eth: nil,
gpo: nil,
l1gpo: nil,
verifier: false,
gasLimit: 0,
UsingOVM: true,
......
......@@ -226,17 +226,13 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
eth.miner = miner.New(eth, &config.Miner, chainConfig, eth.EventMux(), eth.engine, eth.isLocalBlock)
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))
log.Info("Backend Config", "max-calldata-size", config.Rollup.MaxCallDataSize, "gas-limit", config.Rollup.GasLimit, "is-verifier", config.Rollup.IsVerifier, "using-ovm", vm.UsingOVM, "l1-gasprice", config.Rollup.L1GasPrice)
eth.APIBackend = &EthAPIBackend{ctx.ExtRPCEnabled(), eth, nil, nil, config.Rollup.IsVerifier, config.Rollup.GasLimit, vm.UsingOVM, config.Rollup.MaxCallDataSize}
log.Info("Backend Config", "max-calldata-size", config.Rollup.MaxCallDataSize, "gas-limit", config.Rollup.GasLimit, "is-verifier", config.Rollup.IsVerifier, "using-ovm", vm.UsingOVM)
eth.APIBackend = &EthAPIBackend{ctx.ExtRPCEnabled(), eth, nil, config.Rollup.IsVerifier, config.Rollup.GasLimit, vm.UsingOVM, config.Rollup.MaxCallDataSize}
gpoParams := config.GPO
if gpoParams.Default == nil {
gpoParams.Default = config.Miner.GasPrice
}
eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams)
// create the L1 GPO and allow the API backend and the sync service to access it
l1Gpo := gasprice.NewL1Oracle(config.Rollup.L1GasPrice)
eth.APIBackend.l1gpo = l1Gpo
eth.syncService.L1gpo = l1Gpo
return eth, nil
}
......
......@@ -81,7 +81,6 @@ var DefaultConfig = Config{
// is additional overhead that is unaccounted. Round down to 127000 for
// safety.
MaxCallDataSize: 127000,
L1GasPrice: big.NewInt(100 * params.GWei),
},
DiffDbCache: 256,
}
......
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
}
......@@ -32,7 +32,6 @@ require (
github.com/huin/goupnp v1.0.0
github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883
github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458
github.com/jarcoal/httpmock v1.0.8
github.com/jmoiron/sqlx v1.2.0
github.com/julienschmidt/httprouter v1.1.1-0.20170430222011-975b5c4c7c21
github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356
......
......@@ -108,8 +108,6 @@ github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883 h1:FSeK4fZCo
github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY=
github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458 h1:6OvNmYgJyexcZ3pYbTI9jWx5tHo1Dee/tWbLMfPe2TA=
github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/jarcoal/httpmock v1.0.8 h1:8kI16SoO6LQKgPE7PvQuV+YuD/inwHd7fOOe2zMbo4k=
github.com/jarcoal/httpmock v1.0.8/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA=
......
......@@ -63,9 +63,10 @@ func NewPublicEthereumAPI(b Backend) *PublicEthereumAPI {
return &PublicEthereumAPI{b}
}
// GasPrice always returns 1 gwei. See `DoEstimateGas` below for context.
// GasPrice returns a suggestion for a gas price.
func (s *PublicEthereumAPI) GasPrice(ctx context.Context) (*hexutil.Big, error) {
return (*hexutil.Big)(big.NewInt(defaultGasPrice)), nil
price, err := s.b.SuggestPrice(ctx)
return (*hexutil.Big)(price), err
}
// ProtocolVersion returns the current Ethereum protocol version this node supports
......@@ -995,120 +996,74 @@ func (s *PublicBlockChainAPI) Call(ctx context.Context, args CallArgs, blockNrOr
return (hexutil.Bytes)(result), err
}
// Optimism note: The gasPrice in Optimism is modified to always return 1 gwei. We
// use the gasLimit field to communicate the entire user fee. This is done for
// for compatibility reasons with the existing Ethereum toolchain, so that the user
// fees can compensate for the additional costs the sequencer pays for publishing the
// transaction calldata
func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, gasCap *big.Int) (hexutil.Uint64, error) {
if args.Data == nil {
return 0, errors.New("transaction data cannot be nil")
}
// 1. get the gas that would be used by the transaction
gasUsed, err := legacyDoEstimateGas(ctx, b, args, blockNrOrHash, gasCap)
// // Binary search the gas requirement, as it may be higher than the amount used
// var (
// lo uint64 = params.TxGas - 1
// hi uint64
// cap uint64
// )
// if args.Gas != nil && uint64(*args.Gas) >= params.TxGas {
// hi = uint64(*args.Gas)
// } else {
// // Retrieve the block to act as the gas ceiling
// block, err := b.BlockByNumberOrHash(ctx, blockNrOrHash)
// if err != nil {
// return 0, err
// }
// hi = block.GasLimit()
// }
// if gasCap != nil && hi > gasCap.Uint64() {
// log.Warn("Caller gas above allowance, capping", "requested", hi, "cap", gasCap)
// hi = gasCap.Uint64()
// }
// cap = hi
// // Set sender address or use a default if none specified
// if args.From == nil {
// if wallets := b.AccountManager().Wallets(); len(wallets) > 0 {
// if accounts := wallets[0].Accounts(); len(accounts) > 0 {
// args.From = &accounts[0].Address
// }
// }
// }
// // Use zero-address if none other is available
// if args.From == nil {
// args.From = &common.Address{}
// }
// // Create a helper to check if a gas allowance results in an executable transaction
// executable := func(gas uint64) bool {
// args.Gas = (*hexutil.Uint64)(&gas)
// _, _, failed, err := DoCall(ctx, b, args, blockNrOrHash, nil, vm.Config{}, 0, gasCap)
// if err != nil || failed {
// return false
// }
// return true
// }
// // Execute the binary search and hone in on an executable gas limit
// for lo+1 < hi {
// mid := (hi + lo) / 2
// if !executable(mid) {
// lo = mid
// } else {
// hi = mid
// }
// }
// // Reject the transaction as invalid if it still fails at the highest allowance
// if hi == cap {
// if !executable(hi) {
// return 0, fmt.Errorf("gas required exceeds allowance (%d) or always failing transaction", cap)
// }
// }
// return hexutil.Uint64(hi), nil
block, err := b.BlockByNumberOrHash(ctx, blockNrOrHash)
if err != nil {
return 0, err
}
// 2a. fetch the data price, depends on how the sequencer has chosen to update their values based on the
// l1 gas prices
dataPrice, err := b.SuggestDataPrice(ctx)
if err != nil {
return 0, err
}
// 2b. fetch the execution gas price, by the typical mempool dynamics
executionPrice, err := b.SuggestPrice(ctx)
if err != nil {
return 0, err
}
// 3. calculate the fee and normalize by the default gas price
fee := core.CalculateRollupFee(*args.Data, uint64(gasUsed), dataPrice, executionPrice).Uint64() / defaultGasPrice
return (hexutil.Uint64)(fee), nil
}
func legacyDoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, gasCap *big.Int) (hexutil.Uint64, error) {
// Binary search the gas requirement, as it may be higher than the amount used
var (
lo uint64 = params.TxGas - 1
hi uint64
cap uint64
)
if args.Gas != nil && uint64(*args.Gas) >= params.TxGas {
hi = uint64(*args.Gas)
} else {
// Retrieve the block to act as the gas ceiling
block, err := b.BlockByNumberOrHash(ctx, blockNrOrHash)
if err != nil {
return 0, err
}
hi = block.GasLimit()
}
if gasCap != nil && hi > gasCap.Uint64() {
log.Warn("Caller gas above allowance, capping", "requested", hi, "cap", gasCap)
hi = gasCap.Uint64()
}
cap = hi
// Set sender address or use a default if none specified
if args.From == nil {
if wallets := b.AccountManager().Wallets(); len(wallets) > 0 {
if accounts := wallets[0].Accounts(); len(accounts) > 0 {
args.From = &accounts[0].Address
}
}
}
// Use zero-address if none other is available
if args.From == nil {
args.From = &common.Address{}
}
// Create a helper to check if a gas allowance results in an executable transaction
executable := func(gas uint64) bool {
args.Gas = (*hexutil.Uint64)(&gas)
_, _, failed, err := DoCall(ctx, b, args, blockNrOrHash, nil, vm.Config{}, 0, gasCap)
if err != nil || failed {
return false
}
return true
}
// Execute the binary search and hone in on an executable gas limit
for lo+1 < hi {
mid := (hi + lo) / 2
if !executable(mid) {
lo = mid
} else {
hi = mid
}
}
// Fudging to account for gas required to verify signatures + pass around data.
// Specifically, this line accounts for the fact that there's a bit of computation performed in
// a "real" transaction that won't be covered by an eth_call:
// 1. Going into the OVM_SequencerEntrypoint.
// 2. Going into the OVM_ProxyEOA + OVM_ECDSAContractAccount.
// 3. Verify signatures in various places.
// eth_call skips all of this and therefore won't correctly estimate gas by default. We need to
// tweak the gas estimate to account for this discrepancy. Cost is quite high here because of
// the EVM limitation that CALL can only pass 63/64 of total gas available -- so most of this
// gas isn't actually spent during execution but needs to be provided to avoid a revert.
hi += 1000000
if args.Data != nil {
hi += uint64(len([]byte(*args.Data))) * 128
}
if hi > cap {
hi = cap
}
// Reject the transaction as invalid if it still fails at the highest allowance
if hi == cap {
if !executable(hi) {
return 0, fmt.Errorf("gas required exceeds allowance (%d) or always failing transaction", cap)
}
}
return hexutil.Uint64(hi), nil
return hexutil.Uint64(block.GasLimit() - 1), nil
}
// EstimateGas returns an estimate of the amount of gas needed to execute the
......@@ -1967,24 +1922,6 @@ func (api *PublicRollupAPI) GetInfo(ctx context.Context) rollupInfo {
}
}
// 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 {
b Backend
}
// NewPrivateRollupAPI creates a new API definition for the rollup methods of the
// Ethereum service.
func NewPrivateRollupAPI(b Backend) *PrivateRollupAPI {
return &PrivateRollupAPI{b: b}
}
// SetGasPrice sets the gas price to be used when quoting calldata publishing costs
// to users
func (api *PrivateRollupAPI) SetL1GasPrice(ctx context.Context, gasPrice hexutil.Big) {
api.b.SetL1GasPrice(ctx, (*big.Int)(&gasPrice))
}
// PublicDebugAPI is the collection of Ethereum APIs exposed over the public
// debugging endpoint.
type PublicDebugAPI struct {
......
......@@ -94,8 +94,6 @@ type Backend interface {
GetRollupContext() (uint64, uint64)
GasLimit() uint64
GetDiff(*big.Int) (diffdb.Diff, error)
SuggestDataPrice(ctx context.Context) (*big.Int, error)
SetL1GasPrice(context.Context, *big.Int)
}
func GetAPIs(apiBackend Backend) []rpc.API {
......@@ -121,10 +119,6 @@ func GetAPIs(apiBackend Backend) []rpc.API {
Version: "1.0",
Service: NewPublicRollupAPI(apiBackend),
Public: true,
}, {
Namespace: "rollup_personal",
Version: "1.0",
Service: NewPrivateRollupAPI(apiBackend),
}, {
Namespace: "txpool",
Version: "1.0",
......
......@@ -281,16 +281,6 @@ func (b *LesApiBackend) SuggestPrice(ctx context.Context) (*big.Int, error) {
return b.gpo.SuggestPrice(ctx)
}
// NB: Non sequencer nodes cannot suggest L1 gas prices.
func (b *LesApiBackend) SuggestDataPrice(ctx context.Context) (*big.Int, error) {
panic("SuggestDataPrice not implemented")
}
// NB: Non sequencer nodes cannot set L1 gas prices.
func (b *LesApiBackend) SetL1GasPrice(ctx context.Context, gasPrice *big.Int) {
panic("SetL1GasPrice is not implemented")
}
func (b *LesApiBackend) ChainDb() ethdb.Database {
return b.eth.chainDb
}
......
......@@ -155,7 +155,7 @@ public class AndroidTest extends InstrumentationTestCase {
//
// This method has been adapted from golang.org/x/mobile/bind/java/seq_test.go/runTest
func TestAndroid(t *testing.T) {
t.Skip("OVM: Skipping Android Tests")
t.Skip("Skipping Android Test (OVM)")
// Skip tests on Windows altogether
if runtime.GOOS == "windows" {
t.Skip("cannot test Android bindings on Windows, skipping")
......
......@@ -42,10 +42,6 @@ type SyncStatus struct {
CurrentTransactionIndex uint64 `json:"currentTransactionIndex"`
}
type L1GasPrice struct {
GasPrice string `json:"gasPrice"`
}
type transaction struct {
Index uint64 `json:"index"`
BatchIndex uint64 `json:"batchIndex"`
......@@ -96,7 +92,6 @@ type RollupClient interface {
GetLatestEthContext() (*EthContext, error)
GetLastConfirmedEnqueue() (*types.Transaction, error)
SyncStatus() (*SyncStatus, error)
GetL1GasPrice() (*big.Int, error)
}
type Client struct {
......@@ -444,25 +439,3 @@ func (c *Client) SyncStatus() (*SyncStatus, error) {
return status, nil
}
func (c *Client) GetL1GasPrice() (*big.Int, error) {
response, err := c.client.R().
SetResult(&L1GasPrice{}).
Get("/eth/gasprice")
if err != nil {
return nil, fmt.Errorf("Cannot fetch L1 gas price: %w", err)
}
gasPriceResp, ok := response.Result().(*L1GasPrice)
if !ok {
return nil, fmt.Errorf("Cannot parse L1 gas price response")
}
gasPrice, ok := new(big.Int).SetString(gasPriceResp.GasPrice, 10)
if !ok {
return nil, fmt.Errorf("Cannot parse response as big number")
}
return gasPrice, nil
}
package rollup
import (
"fmt"
"math/big"
"testing"
"github.com/jarcoal/httpmock"
)
func TestRollupClientGetL1GasPrice(t *testing.T) {
url := "http://localhost:9999"
endpoint := fmt.Sprintf("%s/eth/gasprice", url)
// url/chain-id does not matter, we'll mock the responses
client := NewClient(url, big.NewInt(1))
// activate the mock
httpmock.ActivateNonDefault(client.client.GetClient())
// The API responds with a string value
expectedGasPrice, _ := new(big.Int).SetString("123132132151245817421893", 10)
body := map[string]interface{}{
"gasPrice": expectedGasPrice.String(),
}
response, _ := httpmock.NewJsonResponder(
200,
body,
)
httpmock.RegisterResponder(
"GET",
endpoint,
response,
)
gasPrice, err := client.GetL1GasPrice()
if err != nil {
t.Fatal("could not get mocked gas price", err)
}
if gasPrice.Cmp(expectedGasPrice) != 0 {
t.Fatal("gasPrice is not parsed properly in the client")
}
}
......@@ -33,6 +33,4 @@ type Config struct {
PollInterval time.Duration
// Interval for updating the timestamp
TimestampRefreshThreshold time.Duration
// The gas price to use when estimating L1 calldata publishing costs
L1GasPrice *big.Int
}
......@@ -19,8 +19,6 @@ import (
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth/gasprice"
)
// OVMContext represents the blocknumber and timestamp
......@@ -44,7 +42,6 @@ type SyncService struct {
eth1ChainId uint64
bc *core.BlockChain
txpool *core.TxPool
L1gpo *gasprice.L1Oracle
client RollupClient
syncing atomic.Value
OVMContext OVMContext
......@@ -360,14 +357,6 @@ func (s *SyncService) SequencerLoop() {
}
func (s *SyncService) sequence() error {
// Update to the latest L1 gas price
l1GasPrice, err := s.client.GetL1GasPrice()
if err != nil {
return err
}
s.L1gpo.SetL1GasPrice(l1GasPrice)
log.Info("Adjusted L1 Gas Price", "gasprice", l1GasPrice)
// Only the sequencer needs to poll for enqueue transactions
// and then can choose when to apply them. We choose to apply
// transactions such that it makes for efficient batch submitting.
......@@ -452,7 +441,6 @@ func (s *SyncService) updateContext() error {
if err != nil {
return err
}
current := time.Unix(int64(s.GetLatestL1Timestamp()), 0)
next := time.Unix(int64(context.Timestamp), 0)
if next.Sub(current) > s.timestampRefreshThreshold {
......
......@@ -14,7 +14,6 @@ import (
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/gasprice"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/params"
)
......@@ -151,37 +150,6 @@ func TestSyncServiceTransactionEnqueued(t *testing.T) {
}
}
func TestSyncServiceL1GasPrice(t *testing.T) {
service, _, _, err := newTestSyncService(true)
setupMockClient(service, map[string]interface{}{})
service.L1gpo = gasprice.NewL1Oracle(big.NewInt(0))
if err != nil {
t.Fatal(err)
}
gasBefore, err := service.L1gpo.SuggestDataPrice(context.Background())
if err != nil {
t.Fatal(err)
}
if gasBefore.Cmp(big.NewInt(0)) != 0 {
t.Fatal("expected 0 gas price, got", gasBefore)
}
// run 1 iteration of the eloop
service.sequence()
gasAfter, err := service.L1gpo.SuggestDataPrice(context.Background())
if err != nil {
t.Fatal(err)
}
if gasAfter.Cmp(big.NewInt(100*int64(params.GWei))) != 0 {
t.Fatal("expected 100 gas price, got", gasAfter)
}
}
// Pass true to set as a verifier
func TestSyncServiceSync(t *testing.T) {
service, txCh, sub, err := newTestSyncService(true)
......@@ -346,7 +314,6 @@ type mockClient struct {
func setupMockClient(service *SyncService, responses map[string]interface{}) {
client := newMockClient(responses)
service.client = client
service.L1gpo = gasprice.NewL1Oracle(big.NewInt(0))
}
func newMockClient(responses map[string]interface{}) *mockClient {
......@@ -433,7 +400,3 @@ func (m *mockClient) SyncStatus() (*SyncStatus, error) {
Syncing: false,
}, nil
}
func (m *mockClient) GetL1GasPrice() (*big.Int, error) {
return big.NewInt(100 * int64(params.GWei)), nil
}
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