Skip to content

Commit c48b8aa

Browse files
trianglespheremslipperprotolambdatynesmaurelian
committed
optimism: historical Bedrock geth rollup changes
This commit squashes the op-geth fork history into a more maintainable diff for rebasing upon upstream geth. reference-optimistic-geth changes (origins of op-geth in early Bedrock development stage): - Deposit TX Type - Enable deposit tx in EVM/tx pool - Change deposit nonce to not be the max nonce - Extend PayloadAttributesV1 with a Transactions field - Force deposits at the start of each L2 block - Fix height check - noTxPool flag, reproduce block in verifier mode without tx pool interference - Fix RPC json marshalling (ref op-geth PR 4) - Deposit txs block height check in block body validation (ref op-geth PR 5) - core: do not try to reinject deposit txs into tx-pool (ref-op-geth PR 6) - deposit source hash field instead of L2 block height and tx index combination - Include invalid deposits, rewind state, but always persist mint (ethereum#10) - Provide gas to Call/Create in deposit transactions (ethereum#12) - Add docker builds (ref-op-geth PR 16, 17) - Don't panic on deposit transaction signature values or chain ID (ref-op-geth PR 18) - core: Add version to DepositTx (ref-op-geth PR 19) - Enable Geth build/lint/test in CircleCI (ref-op-geth PR 23) - core: Include guaranteed gas in the gas pool (ref-op-geth PR 21) - core: handle base fee, l1 availability fee, tx fee (ref-op-geth PR 27) - fix: deposit tx hash - fix l1 fee cache, rpc, tracing and tx pool - core: remove deposit-tx sub-type (a.k.a. deposit version byte) - eth/catalyst: allow engine user to reorg own chain - miner: restore ability to reorg deep as block builder - params: print Optimism consensus type in banner - core/types: remove unused protected() method, see upstream PR 23376 - core: do not mutate original balance value in tx pool l1 cost adjustment - core: subtract deposit gas from pool, so other txs do not use the same gas. And fail tx processing if deposits reach gas limit - core/types: deposits do not tip, avoid basefee subtraction - Unmeter the L1 Attributes Transaction - miner: handle force tx errors as critical, clean up diff - ci: Switch branch - eth,miner: return STATUS_INVALID when failing to process forced transactions in request (ref-op-geth PR 40) - verifier: forward tx to sequencer based on flag - txpool: add flag to disable tx gossip (ref-op-geth PR 42) - Add op-geth version in addition to geth version (ref-op-geth PR 43) - ci: CircleCI improvements (ref-op-geth PR 44) - Rename to op-geth - Build latest tag on optimism branch op-geth changes: - Expose cache config in simulated backend (#2) - Add EIP-1559 parameters - eth/catalyst: update payload id computation (#1) - make eip1559 configurable (#4) - post-merge network should not log warnings about missing transition information (#5) - Make the simulator more configurable (ethereum#6) - fix OPB-6 - IsDepositTx check instead of artificial nonce value check (ethereum#7) - Simulated backend - enable proof of stake consensus type and fix performance issue (ethereum#8) - accounts: simulated backend consensus engine option and immediate tx indexing - consensus/beacon: recognize all blocks as reached TTD with 0 TTD in chain config - Add --rollup.historicalhttp CLI flag and fix backend iface - Flags and interfaces for historical RPC requests (ethereum#12) - Redirect historical RPC requests (ethereum#13) - Use the pre-existing ethereum.NotFound error (ethereum#18) - Add historical endpoint to TraceBlockByNumber and TraceBlockByHash (ethereum#19) - Add historical endpoint to TraceTransaction (ethereum#20) - Add historical endpoint to TraceCall (ethereum#21) - optimism: fee params from info txi, update l1 cost func GPO params read (ethereum#15) - add hardcoded addresses for fee payouts (ethereum#23) - dynamic gas limit via engine API (ethereum#22) Co-authored-by: Matthew Slipper <me@matthewslipper.com> Co-authored-by: Joshua Gutow <jgutow@oplabs.co> Co-authored-by: protolambda <proto@protolambda.com> Co-authored-by: Mark Tyneway <mark.tyneway@gmail.com> Co-authored-by: Maurelian <maurelian@protonmail.ch>
1 parent 73b01f4 commit c48b8aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1399
-72
lines changed

.circleci/config.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
version: 2.1
2+
3+
jobs:
4+
build-geth:
5+
docker:
6+
- image: cimg/go:1.18
7+
resource_class: medium
8+
steps:
9+
- checkout
10+
- run:
11+
command: go run build/ci.go install
12+
unit-test:
13+
resource_class: medium
14+
docker:
15+
- image: cimg/go:1.18
16+
steps:
17+
- checkout
18+
- run:
19+
command: go run build/ci.go test
20+
lint-geth:
21+
resource_class: medium
22+
docker:
23+
- image: cimg/go:1.18
24+
steps:
25+
- checkout
26+
- run:
27+
command: go run build/ci.go lint
28+
29+
push-geth:
30+
docker:
31+
- image: cimg/base:2022.04
32+
steps:
33+
- when:
34+
condition:
35+
or:
36+
- equal: [ optimism, <<pipeline.git.branch>> ]
37+
- equal: [ optimism-history, <<pipeline.git.branch>> ]
38+
steps:
39+
- checkout
40+
- setup_remote_docker:
41+
version: 20.10.12
42+
- run:
43+
name: Build and push
44+
command: |
45+
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USERNAME" --password-stdin
46+
docker build -t "ethereumoptimism/op-geth:$CIRCLE_SHA1" -f Dockerfile .
47+
docker tag "ethereumoptimism/op-geth:$CIRCLE_SHA1" "ethereumoptimism/op-geth:$CIRCLE_BRANCH"
48+
docker push "ethereumoptimism/op-geth:$CIRCLE_SHA1"
49+
docker push "ethereumoptimism/op-geth:$CIRCLE_BRANCH"
50+
51+
if [ $CIRCLE_BRANCH = "optimism" ]
52+
then
53+
docker tag "ethereumoptimism/op-geth:$CIRCLE_SHA1" "ethereumoptimism/op-geth:latest"
54+
docker push "ethereumoptimism/op-geth:latest"
55+
pwd
56+
fi
57+
# Below step is required to prevent CircleCI from barfing on a
58+
# job with no steps
59+
- run: echo 0
60+
61+
workflows:
62+
main:
63+
jobs:
64+
- build-geth:
65+
name: Build geth
66+
- unit-test:
67+
name: Run unit tests for geth
68+
- lint-geth:
69+
name: Run linter over geth
70+
- push-geth:
71+
name: Push geth

accounts/abi/bind/backends/simulated.go

Lines changed: 94 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/ethereum/go-ethereum/common"
3131
"github.com/ethereum/go-ethereum/common/hexutil"
3232
"github.com/ethereum/go-ethereum/common/math"
33+
"github.com/ethereum/go-ethereum/consensus"
3334
"github.com/ethereum/go-ethereum/consensus/ethash"
3435
"github.com/ethereum/go-ethereum/core"
3536
"github.com/ethereum/go-ethereum/core/bloombits"
@@ -63,6 +64,8 @@ type SimulatedBackend struct {
6364
database ethdb.Database // In memory database to store our testing data
6465
blockchain *core.BlockChain // Ethereum blockchain to handle the consensus
6566

67+
consensus consensus.Engine
68+
6669
mu sync.Mutex
6770
pendingBlock *types.Block // Currently pending block that will be imported on request
6871
pendingState *state.StateDB // Currently pending state that will be the active on request
@@ -78,34 +81,100 @@ type SimulatedBackend struct {
7881
// and uses a simulated blockchain for testing purposes.
7982
// A simulated backend always uses chainID 1337.
8083
func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
81-
genesis := core.Genesis{
82-
Config: params.AllEthashProtocolChanges,
83-
GasLimit: gasLimit,
84-
Alloc: alloc,
84+
return NewSimulatedBackendWithOpts(WithDatabase(database), WithAlloc(alloc), WithGasLimit(gasLimit))
85+
}
86+
87+
// NewSimulatedBackend creates a new binding backend using a simulated blockchain
88+
// for testing purposes.
89+
// A simulated backend always uses chainID 1337.
90+
func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
91+
return NewSimulatedBackendWithOpts(WithGasLimit(gasLimit), WithAlloc(alloc))
92+
}
93+
94+
type simulatedBackendConfig struct {
95+
genesis core.Genesis
96+
cacheConfig *core.CacheConfig
97+
database ethdb.Database
98+
vmConfig vm.Config
99+
consensus consensus.Engine
100+
}
101+
102+
type SimulatedBackendOpt func(s *simulatedBackendConfig)
103+
104+
func WithDatabase(database ethdb.Database) SimulatedBackendOpt {
105+
return func(s *simulatedBackendConfig) {
106+
s.database = database
107+
}
108+
}
109+
110+
func WithGasLimit(gasLimit uint64) SimulatedBackendOpt {
111+
return func(s *simulatedBackendConfig) {
112+
s.genesis.GasLimit = gasLimit
113+
}
114+
}
115+
116+
func WithAlloc(alloc core.GenesisAlloc) SimulatedBackendOpt {
117+
return func(s *simulatedBackendConfig) {
118+
s.genesis.Alloc = alloc
119+
}
120+
}
121+
122+
func WithCacheConfig(cacheConfig *core.CacheConfig) SimulatedBackendOpt {
123+
return func(s *simulatedBackendConfig) {
124+
s.cacheConfig = cacheConfig
85125
}
86-
blockchain, _ := core.NewBlockChain(database, nil, &genesis, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
126+
}
127+
128+
func WithGenesis(genesis core.Genesis) SimulatedBackendOpt {
129+
return func(s *simulatedBackendConfig) {
130+
s.genesis = genesis
131+
}
132+
}
133+
134+
func WithVMConfig(vmConfig vm.Config) SimulatedBackendOpt {
135+
return func(s *simulatedBackendConfig) {
136+
s.vmConfig = vmConfig
137+
}
138+
}
139+
140+
func WithConsensus(consensus consensus.Engine) SimulatedBackendOpt {
141+
return func(s *simulatedBackendConfig) {
142+
s.consensus = consensus
143+
}
144+
}
145+
146+
// NewSimulatedBackendWithOpts creates a new binding backend based on the given database
147+
// and uses a simulated blockchain for testing purposes. It exposes additional configuration
148+
// options that are useful to
149+
func NewSimulatedBackendWithOpts(opts ...SimulatedBackendOpt) *SimulatedBackend {
150+
config := &simulatedBackendConfig{
151+
genesis: core.Genesis{Config: params.AllEthashProtocolChanges, GasLimit: 100000000, Alloc: make(core.GenesisAlloc)},
152+
database: rawdb.NewMemoryDatabase(),
153+
consensus: ethash.NewFaker(),
154+
}
155+
156+
for _, opt := range opts {
157+
opt(config)
158+
}
159+
160+
config.genesis.MustCommit(config.database)
161+
blockchain, _ := core.NewBlockChain(config.database, config.cacheConfig, &config.genesis, nil, config.consensus, config.vmConfig, nil, nil)
87162

88163
backend := &SimulatedBackend{
89-
database: database,
164+
database: config.database,
90165
blockchain: blockchain,
91-
config: genesis.Config,
166+
config: config.genesis.Config,
167+
consensus: config.consensus,
92168
}
93169

94-
filterBackend := &filterBackend{database, blockchain, backend}
170+
filterBackend := &filterBackend{config.database, blockchain, backend}
95171
backend.filterSystem = filters.NewFilterSystem(filterBackend, filters.Config{})
96172
backend.events = filters.NewEventSystem(backend.filterSystem, false)
97173

98174
backend.rollback(blockchain.CurrentBlock())
99175
return backend
100176
}
101177

102-
// NewSimulatedBackend creates a new binding backend using a simulated blockchain
103-
// for testing purposes.
104-
// A simulated backend always uses chainID 1337.
105-
func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
106-
return NewSimulatedBackendWithDatabase(rawdb.NewMemoryDatabase(), alloc, gasLimit)
107-
}
108-
109178
// Close terminates the underlying blockchain's update loop.
110179
func (b *SimulatedBackend) Close() error {
111180
b.blockchain.Stop()
@@ -121,6 +190,8 @@ func (b *SimulatedBackend) Commit() common.Hash {
121190
if _, err := b.blockchain.InsertChain([]*types.Block{b.pendingBlock}); err != nil {
122191
panic(err) // This cannot happen unless the simulator is wrong, fail in that case
123192
}
193+
// Don't wait for the async tx indexing
194+
rawdb.WriteTxLookupEntriesByBlock(b.database, b.pendingBlock)
124195
blockHash := b.pendingBlock.Hash()
125196

126197
// Using the last inserted block here makes it possible to build on a side
@@ -139,7 +210,7 @@ func (b *SimulatedBackend) Rollback() {
139210
}
140211

141212
func (b *SimulatedBackend) rollback(parent *types.Block) {
142-
blocks, _ := core.GenerateChain(b.config, parent, ethash.NewFaker(), b.database, 1, func(int, *core.BlockGen) {})
213+
blocks, _ := core.GenerateChain(b.config, parent, b.consensus, b.database, 1, func(int, *core.BlockGen) {})
143214

144215
b.pendingBlock = blocks[0]
145216
b.pendingState, _ = state.New(b.pendingBlock.Root(), b.blockchain.StateCache(), nil)
@@ -646,6 +717,7 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM
646717

647718
txContext := core.NewEVMTxContext(msg)
648719
evmContext := core.NewEVMBlockContext(block.Header(), b.blockchain, nil)
720+
evmContext.L1CostFunc = types.NewL1CostFunc(b.config, stateDB)
649721
// Create a new environment which holds all relevant information
650722
// about the transaction and calling mechanisms.
651723
vmEnv := vm.NewEVM(evmContext, txContext, stateDB, b.config, vm.Config{NoBaseFee: true})
@@ -675,7 +747,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
675747
return fmt.Errorf("invalid transaction nonce: got %d, want %d", tx.Nonce(), nonce)
676748
}
677749
// Include tx in chain
678-
blocks, receipts := core.GenerateChain(b.config, block, ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {
750+
blocks, receipts := core.GenerateChain(b.config, block, b.consensus, b.database, 1, func(number int, block *core.BlockGen) {
679751
for _, tx := range b.pendingBlock.Transactions() {
680752
block.AddTxWithChain(b.blockchain, tx)
681753
}
@@ -799,7 +871,7 @@ func (b *SimulatedBackend) AdjustTime(adjustment time.Duration) error {
799871
return fmt.Errorf("could not find parent")
800872
}
801873

802-
blocks, _ := core.GenerateChain(b.config, block, ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {
874+
blocks, _ := core.GenerateChain(b.config, block, b.consensus, b.database, 1, func(number int, block *core.BlockGen) {
803875
block.OffsetTime(int64(adjustment.Seconds()))
804876
})
805877
stateDB, _ := b.blockchain.State()
@@ -831,6 +903,10 @@ func (m callMsg) Gas() uint64 { return m.CallMsg.Gas }
831903
func (m callMsg) Value() *big.Int { return m.CallMsg.Value }
832904
func (m callMsg) Data() []byte { return m.CallMsg.Data }
833905
func (m callMsg) AccessList() types.AccessList { return m.CallMsg.AccessList }
906+
func (m callMsg) IsSystemTx() bool { return false }
907+
func (m callMsg) IsDepositTx() bool { return false }
908+
func (m callMsg) Mint() *big.Int { return nil }
909+
func (m callMsg) RollupDataGas() uint64 { return 0 }
834910

835911
// filterBackend implements filters.Backend to support filtering for logs without
836912
// taking bloom-bits acceleration structures into account.

beacon/engine/gen_blockparams.go

Lines changed: 28 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beacon/engine/types.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,23 @@ type PayloadAttributes struct {
3434
Timestamp uint64 `json:"timestamp" gencodec:"required"`
3535
Random common.Hash `json:"prevRandao" gencodec:"required"`
3636
SuggestedFeeRecipient common.Address `json:"suggestedFeeRecipient" gencodec:"required"`
37-
Withdrawals []*types.Withdrawal `json:"withdrawals"`
37+
Withdrawals []*types.Withdrawal `json:"withdrawals,omitempty" gencodec:"optional"`
38+
39+
// Transactions is a field for rollups: the transactions list is forced into the block
40+
Transactions [][]byte `json:"transactions,omitempty" gencodec:"optional"`
41+
// NoTxPool is a field for rollups: if true, the no transactions are taken out of the tx-pool,
42+
// only transactions from the above Transactions list will be included.
43+
NoTxPool bool `json:"noTxPool,omitempty" gencodec:"optional"`
44+
// GasLimit is a field for rollups: if set, this sets the exact gas limit the block produced with.
45+
GasLimit *uint64 `json:"gasLimit,omitempty" gencodec:"optional"`
3846
}
3947

4048
// JSON type overrides for PayloadAttributes.
4149
type payloadAttributesMarshaling struct {
4250
Timestamp hexutil.Uint64
51+
52+
Transactions []hexutil.Bytes
53+
GasLimit *hexutil.Uint64
4354
}
4455

4556
//go:generate go run github.com/fjl/gencodec -type ExecutableData -field-override executableDataMarshaling -out gen_ed.go

build/ci.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ func doDocker(cmdline []string) {
512512
case env.Branch == "master":
513513
tags = []string{"latest"}
514514
case strings.HasPrefix(env.Tag, "v1."):
515-
tags = []string{"stable", fmt.Sprintf("release-1.%d", params.VersionMinor), "v" + params.Version}
515+
tags = []string{"stable", fmt.Sprintf("release-1.%d", params.OPVersionMinor), "v" + params.Version}
516516
}
517517
// If architecture specific image builds are requested, build and push them
518518
if *image {

cmd/geth/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ var (
149149
utils.GpoMaxGasPriceFlag,
150150
utils.GpoIgnoreGasPriceFlag,
151151
utils.MinerNotifyFullFlag,
152+
utils.RollupSequencerHTTPFlag,
153+
utils.RollupHistoricalRPCFlag,
154+
utils.RollupDisableTxPoolGossipFlag,
152155
configFileFlag,
153156
}, utils.NetworkFlags, utils.DatabasePathFlags)
154157

cmd/geth/misccmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ func printVersion(ctx *cli.Context) error {
137137
if git.Date != "" {
138138
fmt.Println("Git Commit Date:", git.Date)
139139
}
140+
fmt.Println("Upstream Version:", params.GethVersionWithMeta)
140141
fmt.Println("Architecture:", runtime.GOARCH)
141142
fmt.Println("Go Version:", runtime.Version())
142143
fmt.Println("Operating System:", runtime.GOOS)

0 commit comments

Comments
 (0)