Skip to content

Commit

Permalink
Updates to work with upstream geth v1.14.12 changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-bayardo committed Nov 20, 2024
1 parent b05ec5a commit e64e849
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 80 deletions.
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ require (
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/status-im/keycard-go v0.2.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/supranational/blst v0.3.13 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a // indirect
Expand Down Expand Up @@ -250,9 +249,11 @@ require (
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/ethereum/go-ethereum => github.com/ethereum-optimism/op-geth v1.101411.2-rc.2
//replace github.com/ethereum/go-ethereum => github.com/ethereum-optimism/op-geth v1.101411.2-rc.2

//replace github.com/ethereum/go-ethereum => ../go-ethereum
replace github.com/ethereum/go-ethereum => github.com/roberto-bayardo/op-geth v0.0.0-20241120170924-fdfd720a3d60

//replace github.com/ethereum/go-ethereum => ../op-geth

// replace github.com/ethereum-optimism/superchain-registry/superchain => ../superchain-registry/superchain

Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ github.com/elastic/gosigar v0.14.3 h1:xwkKwPia+hSfg9GqrCUKYdId102m9qTJIIr7egmK/u
github.com/elastic/gosigar v0.14.3/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs=
github.com/ethereum-optimism/go-ethereum-hdwallet v0.1.3 h1:RWHKLhCrQThMfch+QJ1Z8veEq5ZO3DfIhZ7xgRP9WTc=
github.com/ethereum-optimism/go-ethereum-hdwallet v0.1.3/go.mod h1:QziizLAiF0KqyLdNJYD7O5cpDlaFMNZzlxYNcWsJUxs=
github.com/ethereum-optimism/op-geth v1.101411.2-rc.2 h1:3suWTU9DwBdY8Yy/ZgZLB/yBy3TwpntpkUn61mZgNpY=
github.com/ethereum-optimism/op-geth v1.101411.2-rc.2/go.mod h1:dITJzx1KXsV2KusscsktidEb00blTSyFhalq8CjfsUY=
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20241119111730-bee358f6d6e6 h1:+AIYWDX7FeWRLnBVqPiwireTacLLGGww1slGyv+YN0o=
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20241119111730-bee358f6d6e6/go.mod h1:9feO8jcL5OZ1tvRjEfNAHz4Aggvd6373l+ZxmZZAyZs=
github.com/ethereum/c-kzg-4844 v1.0.0 h1:0X1LBXxaEtYD9xsyj9B9ctQEZIpnvVDeoBx8aHEwTNA=
Expand Down Expand Up @@ -711,6 +709,8 @@ github.com/raulk/go-watchdog v1.3.0/go.mod h1:fIvOnLbF0b0ZwkB9YU4mOW9Did//4vPZtD
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/roberto-bayardo/op-geth v0.0.0-20241120170924-fdfd720a3d60 h1:ayTFlteIPMYAFu4L0kx/DJCgmP/m8AeZj3AYAHdg3ZA=
github.com/roberto-bayardo/op-geth v0.0.0-20241120170924-fdfd720a3d60/go.mod h1:RSgQAtx+b5n1GsLTZU6rURjXXfDIUOziVK7O1DJNVRI=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
Expand Down Expand Up @@ -760,8 +760,6 @@ github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA=
github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
Expand Down
16 changes: 9 additions & 7 deletions op-chain-ops/cmd/check-canyon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/mattn/go-isatty"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
Expand Down Expand Up @@ -48,19 +47,22 @@ func CalcBaseFee(parent eth.BlockInfo, elasticity uint64, canyonActive bool) *bi
num.Mul(num, parent.BaseFee())
num.Div(num, denom.SetUint64(parentGasTarget))
num.Div(num, denom.SetUint64(denomUint))
baseFeeDelta := math.BigMax(num, common.Big1)

return num.Add(parent.BaseFee(), baseFeeDelta)
if num.Cmp(common.Big1) < 0 {
num.Set(common.Big1)
}
return num.Add(num, parent.BaseFee())
} else {
// Otherwise if the parent block used less gas than its target, the baseFee should decrease.
// max(0, parentBaseFee * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator)
num.SetUint64(parentGasTarget - parent.GasUsed())
num.Mul(num, parent.BaseFee())
num.Div(num, denom.SetUint64(parentGasTarget))
num.Div(num, denom.SetUint64(denomUint))
baseFee := num.Sub(parent.BaseFee(), num)

return math.BigMax(baseFee, common.Big0)
num.Sub(parent.BaseFee(), num)
if num.Cmp(common.Big0) < 0 {
return common.Big0
}
return num
}
}

Expand Down
62 changes: 30 additions & 32 deletions op-chain-ops/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,34 @@ func NewL2Genesis(config *DeployConfig, l1StartHeader *types.Header) (*core.Gene
l1StartTime := l1StartHeader.Time

optimismChainConfig := params.ChainConfig{
ChainID: new(big.Int).SetUint64(config.L2ChainID),
HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil,
DAOForkSupport: false,
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0),
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
ArrowGlacierBlock: big.NewInt(0),
GrayGlacierBlock: big.NewInt(0),
MergeNetsplitBlock: big.NewInt(0),
TerminalTotalDifficulty: big.NewInt(0),
TerminalTotalDifficultyPassed: true,
BedrockBlock: new(big.Int).SetUint64(uint64(config.L2GenesisBlockNumber)),
RegolithTime: config.RegolithTime(l1StartTime),
CanyonTime: config.CanyonTime(l1StartTime),
ShanghaiTime: config.CanyonTime(l1StartTime),
CancunTime: config.EcotoneTime(l1StartTime),
EcotoneTime: config.EcotoneTime(l1StartTime),
FjordTime: config.FjordTime(l1StartTime),
GraniteTime: config.GraniteTime(l1StartTime),
HoloceneTime: config.HoloceneTime(l1StartTime),
InteropTime: config.InteropTime(l1StartTime),
ChainID: new(big.Int).SetUint64(config.L2ChainID),
HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil,
DAOForkSupport: false,
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0),
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
ArrowGlacierBlock: big.NewInt(0),
GrayGlacierBlock: big.NewInt(0),
MergeNetsplitBlock: big.NewInt(0),
TerminalTotalDifficulty: big.NewInt(0),
BedrockBlock: new(big.Int).SetUint64(uint64(config.L2GenesisBlockNumber)),
RegolithTime: config.RegolithTime(l1StartTime),
CanyonTime: config.CanyonTime(l1StartTime),
ShanghaiTime: config.CanyonTime(l1StartTime),
CancunTime: config.EcotoneTime(l1StartTime),
EcotoneTime: config.EcotoneTime(l1StartTime),
FjordTime: config.FjordTime(l1StartTime),
GraniteTime: config.GraniteTime(l1StartTime),
HoloceneTime: config.HoloceneTime(l1StartTime),
InteropTime: config.InteropTime(l1StartTime),
Optimism: &params.OptimismConfig{
EIP1559Denominator: eip1559Denom,
EIP1559Elasticity: eip1559Elasticity,
Expand Down Expand Up @@ -143,9 +142,8 @@ func NewL1Genesis(config *DeployConfig) (*core.Genesis, error) {
ShanghaiTime: u64ptr(0),
CancunTime: u64ptr(0),
// To enable post-Merge consensus at genesis
MergeNetsplitBlock: big.NewInt(0),
TerminalTotalDifficulty: big.NewInt(0),
TerminalTotalDifficultyPassed: true,
MergeNetsplitBlock: big.NewInt(0),
TerminalTotalDifficulty: big.NewInt(0),
}

gasLimit := config.L1GenesisBlockGasLimit
Expand Down
8 changes: 4 additions & 4 deletions op-chain-ops/script/forking/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ func (f *ForkDB) TrieDB() *triedb.Database {
IsVerkle: false,
HashDB: nil,
PathDB: &pathdb.Config{
StateHistory: 0,
CleanCacheSize: 0,
DirtyCacheSize: 0,
ReadOnly: true,
StateHistory: 0,
CleanCacheSize: 0,
WriteBufferSize: 0,
ReadOnly: true,
},
})
return tdb
Expand Down
20 changes: 10 additions & 10 deletions op-chain-ops/script/forking/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,12 @@ func (fst *ForkableState) CreateContract(address common.Address) {
fst.stateFor(address).CreateContract(address)
}

func (fst *ForkableState) SubBalance(address common.Address, u *uint256.Int, reason tracing.BalanceChangeReason) {
fst.stateFor(address).SubBalance(address, u, reason)
func (fst *ForkableState) SubBalance(address common.Address, u *uint256.Int, reason tracing.BalanceChangeReason) uint256.Int {
return fst.stateFor(address).SubBalance(address, u, reason)
}

func (fst *ForkableState) AddBalance(address common.Address, u *uint256.Int, reason tracing.BalanceChangeReason) {
fst.stateFor(address).AddBalance(address, u, reason)
func (fst *ForkableState) AddBalance(address common.Address, u *uint256.Int, reason tracing.BalanceChangeReason) uint256.Int {
return fst.stateFor(address).AddBalance(address, u, reason)
}

func (fst *ForkableState) GetBalance(address common.Address) *uint256.Int {
Expand Down Expand Up @@ -306,8 +306,8 @@ func (fst *ForkableState) GetState(address common.Address, k common.Hash) common
return fst.stateFor(address).GetState(address, k)
}

func (fst *ForkableState) SetState(address common.Address, k common.Hash, v common.Hash) {
fst.stateFor(address).SetState(address, k, v)
func (fst *ForkableState) SetState(address common.Address, k common.Hash, v common.Hash) common.Hash {
return fst.stateFor(address).SetState(address, k, v)
}

func (fst *ForkableState) GetStorageRoot(addr common.Address) common.Hash {
Expand All @@ -322,16 +322,16 @@ func (fst *ForkableState) SetTransientState(addr common.Address, key, value comm
fst.stateFor(addr).SetTransientState(addr, key, value)
}

func (fst *ForkableState) SelfDestruct(address common.Address) {
fst.stateFor(address).SelfDestruct(address)
func (fst *ForkableState) SelfDestruct(address common.Address) uint256.Int {
return fst.stateFor(address).SelfDestruct(address)
}

func (fst *ForkableState) HasSelfDestructed(address common.Address) bool {
return fst.stateFor(address).HasSelfDestructed(address)
}

func (fst *ForkableState) Selfdestruct6780(address common.Address) {
fst.stateFor(address).Selfdestruct6780(address)
func (fst *ForkableState) SelfDestruct6780(address common.Address) (uint256.Int, bool) {
return fst.stateFor(address).SelfDestruct6780(address)
}

func (fst *ForkableState) Exist(address common.Address) bool {
Expand Down
11 changes: 5 additions & 6 deletions op-chain-ops/script/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,11 @@ func NewHost(
GrayGlacierBlock: big.NewInt(0),
MergeNetsplitBlock: big.NewInt(0),
// Ethereum forks in proof-of-stake era.
TerminalTotalDifficulty: big.NewInt(1),
TerminalTotalDifficultyPassed: true,
ShanghaiTime: new(uint64),
CancunTime: new(uint64),
PragueTime: nil,
VerkleTime: nil,
TerminalTotalDifficulty: big.NewInt(1),
ShanghaiTime: new(uint64),
CancunTime: new(uint64),
PragueTime: nil,
VerkleTime: nil,
// OP-Stack forks are disabled, since we use this for L1.
BedrockBlock: nil,
RegolithTime: nil,
Expand Down
4 changes: 4 additions & 0 deletions op-program/client/l2/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func (o *OracleKeyValueStore) Delete(key []byte) error {
panic("not supported")
}

func (o *OracleKeyValueStore) DeleteRange(start, end []byte) error {
panic("not supported")
}

func (o *OracleKeyValueStore) Stat() (string, error) {
panic("not supported")
}
Expand Down
10 changes: 5 additions & 5 deletions op-program/client/l2/engineapi/l2_engine_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (ea *L2EngineAPI) NewPayloadV1(ctx context.Context, payload *eth.ExecutionP
return &eth.PayloadStatusV1{Status: eth.ExecutionInvalid}, engine.InvalidParams.With(errors.New("withdrawals not supported in V1"))
}

return ea.newPayload(ctx, payload, nil, nil)
return ea.newPayload(ctx, payload, nil, nil, nil)
}

func (ea *L2EngineAPI) NewPayloadV2(ctx context.Context, payload *eth.ExecutionPayload) (*eth.PayloadStatusV1, error) {
Expand All @@ -313,7 +313,7 @@ func (ea *L2EngineAPI) NewPayloadV2(ctx context.Context, payload *eth.ExecutionP
return &eth.PayloadStatusV1{Status: eth.ExecutionInvalid}, engine.InvalidParams.With(errors.New("non-nil withdrawals pre-shanghai"))
}

return ea.newPayload(ctx, payload, nil, nil)
return ea.newPayload(ctx, payload, nil, nil, nil)
}

// Ported from: https://github.com/ethereum-optimism/op-geth/blob/c50337a60a1309a0f1dca3bf33ed1bb38c46cdd7/eth/catalyst/api.go#L486C1-L507
Expand Down Expand Up @@ -342,7 +342,7 @@ func (ea *L2EngineAPI) NewPayloadV3(ctx context.Context, params *eth.ExecutionPa
}
}

return ea.newPayload(ctx, params, versionedHashes, beaconRoot)
return ea.newPayload(ctx, params, versionedHashes, beaconRoot, nil)
}

func (ea *L2EngineAPI) getPayload(_ context.Context, payloadId eth.PayloadID) (*eth.ExecutionPayloadEnvelope, error) {
Expand Down Expand Up @@ -479,7 +479,7 @@ func toGethWithdrawals(payload *eth.ExecutionPayload) []*types.Withdrawal {
return result
}

func (ea *L2EngineAPI) newPayload(_ context.Context, payload *eth.ExecutionPayload, hashes []common.Hash, root *common.Hash) (*eth.PayloadStatusV1, error) {
func (ea *L2EngineAPI) newPayload(_ context.Context, payload *eth.ExecutionPayload, hashes []common.Hash, root *common.Hash, requests [][]byte) (*eth.PayloadStatusV1, error) {
ea.log.Trace("L2Engine API request received", "method", "ExecutePayload", "number", payload.BlockNumber, "hash", payload.BlockHash)
txs := make([][]byte, len(payload.Transactions))
for i, tx := range payload.Transactions {
Expand All @@ -503,7 +503,7 @@ func (ea *L2EngineAPI) newPayload(_ context.Context, payload *eth.ExecutionPaylo
Withdrawals: toGethWithdrawals(payload),
ExcessBlobGas: (*uint64)(payload.ExcessBlobGas),
BlobGasUsed: (*uint64)(payload.BlobGasUsed),
}, hashes, root)
}, hashes, root, requests)
if err != nil {
log.Debug("Invalid NewPayload params", "params", payload, "error", err)
return &eth.PayloadStatusV1{Status: eth.ExecutionInvalidBlockHash}, nil
Expand Down
4 changes: 4 additions & 0 deletions op-program/client/mpt/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func (p DB) Delete(key []byte) error {
return nil
}

func (p *DB) DeleteRange(start, end []byte) error {
panic("not supported")
}

func (p DB) Stat() (string, error) {
panic("not supported")
}
Expand Down
15 changes: 6 additions & 9 deletions op-wheel/cheat/cheat.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethdb/leveldb"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
Expand All @@ -43,18 +44,14 @@ type Cheater struct {

func OpenGethRawDB(dataDirPath string, readOnly bool) (ethdb.Database, error) {
// don't use readonly mode in actual DB, it doesn't work with Geth.
db, err := rawdb.Open(rawdb.OpenOptions{
Type: "leveldb",
Directory: dataDirPath,
AncientsDirectory: filepath.Join(dataDirPath, "ancient"),
Namespace: "",
Cache: 2048,
Handles: 500,
ReadOnly: readOnly,
})
kvs, err := leveldb.New(dataDirPath, 2048, 500, "", readOnly)
if err != nil {
return nil, fmt.Errorf("failed to open leveldb: %w", err)
}
db, err := rawdb.NewDatabaseWithFreezer(kvs, filepath.Join(dataDirPath, "ancient"), "", readOnly)
if err != nil {
return nil, fmt.Errorf("failed to open db with freezer: %w", err)
}
return db, nil
}

Expand Down

0 comments on commit e64e849

Please sign in to comment.