Skip to content

Commit 1296a2c

Browse files
authored
Merge pull request ethereum#148 from ethereum-optimism/chain-config-db
superchain: beta feature flag for overriding chain-config with superchain-registry
2 parents 1e6910b + 80ac0fa commit 1296a2c

File tree

8 files changed

+86
-16
lines changed

8 files changed

+86
-16
lines changed

cmd/geth/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ var (
153153
utils.RollupDisableTxPoolGossipFlag,
154154
utils.RollupComputePendingBlock,
155155
utils.RollupHaltOnIncompatibleProtocolVersionFlag,
156+
utils.RollupSuperchainUpgradesFlag,
156157
configFileFlag,
157158
}, utils.NetworkFlags, utils.DatabasePathFlags)
158159

cmd/utils/flags.go

+6
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,11 @@ var (
918918
Usage: "Opt-in option to halt on incompatible protocol version requirements of the given level (major/minor/patch/none), as signaled through the Engine API by the rollup node",
919919
Category: flags.RollupCategory,
920920
}
921+
RollupSuperchainUpgradesFlag = &cli.BoolFlag{
922+
Name: "beta.rollup.superchain-upgrades",
923+
Usage: "Beta feature: apply superchain-registry config changes to the local chain-configuration",
924+
Category: flags.EthCategory,
925+
}
921926

922927
// Metrics flags
923928
MetricsEnabledFlag = &cli.BoolFlag{
@@ -1884,6 +1889,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
18841889
cfg.RollupDisableTxPoolGossip = ctx.Bool(RollupDisableTxPoolGossipFlag.Name)
18851890
cfg.RollupDisableTxPoolAdmission = cfg.RollupSequencerHTTP != "" && !ctx.Bool(RollupEnableTxPoolAdmissionFlag.Name)
18861891
cfg.RollupHaltOnIncompatibleProtocolVersion = ctx.String(RollupHaltOnIncompatibleProtocolVersionFlag.Name)
1892+
cfg.ApplySuperchainUpgrades = ctx.Bool(RollupSuperchainUpgradesFlag.Name)
18871893
// Override any default configs for hard coded networks.
18881894
switch {
18891895
case ctx.Bool(MainnetFlag.Name):

core/gen_genesis.go

+15-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/genesis.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
"math/big"
2626
"strings"
2727

28+
"github.com/ethereum-optimism/superchain-registry/superchain"
29+
2830
"github.com/ethereum/go-ethereum/common"
2931
"github.com/ethereum/go-ethereum/common/hexutil"
3032
"github.com/ethereum/go-ethereum/common/math"
@@ -288,7 +290,8 @@ type ChainOverrides struct {
288290
OverrideCancun *uint64
289291
OverrideVerkle *uint64
290292
// optimism
291-
OverrideOptimismCanyon *uint64
293+
OverrideOptimismCanyon *uint64
294+
ApplySuperchainUpgrades bool
292295
}
293296

294297
// SetupGenesisBlock writes or updates the genesis block in db.
@@ -314,6 +317,19 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *trie.Database, gen
314317
}
315318
applyOverrides := func(config *params.ChainConfig) {
316319
if config != nil {
320+
// If applying the superchain-registry to a known OP-Stack chain,
321+
// then override the local chain-config with that from the registry.
322+
if overrides != nil && overrides.ApplySuperchainUpgrades && config.IsOptimism() && config.ChainID != nil && genesis.Config.ChainID.IsUint64() {
323+
if _, ok := superchain.OPChains[config.ChainID.Uint64()]; ok {
324+
conf, err := params.LoadOPStackChainConfig(config.ChainID.Uint64())
325+
if err != nil {
326+
log.Warn("failed to load chain config from superchain-registry, skipping override", "err", err, "chain_id", config.ChainID)
327+
} else {
328+
*config = *conf
329+
}
330+
}
331+
}
332+
317333
if config.IsOptimism() && config.ChainID != nil && config.ChainID.Cmp(big.NewInt(params.OPGoerliChainID)) == 0 {
318334
// Apply Optimism Goerli regolith time
319335
config.RegolithTime = &params.OptimismGoerliRegolithTime

core/superchain_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import (
44
"testing"
55

66
"github.com/ethereum-optimism/superchain-registry/superchain"
7+
8+
"github.com/ethereum/go-ethereum/core/rawdb"
9+
"github.com/ethereum/go-ethereum/trie"
710
)
811

912
func TestOPStackGenesis(t *testing.T) {
@@ -15,3 +18,37 @@ func TestOPStackGenesis(t *testing.T) {
1518
t.Logf("chain: %d, genesis block hash: %s", id, gen.ToBlock().Hash())
1619
}
1720
}
21+
22+
func TestRegistryChainConfigOverride(t *testing.T) {
23+
db := rawdb.NewMemoryDatabase()
24+
genesis, err := LoadOPStackGenesis(10)
25+
if err != nil {
26+
t.Fatal(err)
27+
}
28+
if genesis.Config.RegolithTime == nil {
29+
t.Fatal("expected non-nil regolith time")
30+
}
31+
expectedRegolithTime := *genesis.Config.RegolithTime
32+
genesis.Config.RegolithTime = nil
33+
34+
// initialize the DB
35+
tdb := trie.NewDatabase(db, newDbConfig(rawdb.PathScheme))
36+
genesis.MustCommit(db, tdb)
37+
bl := genesis.ToBlock()
38+
rawdb.WriteCanonicalHash(db, bl.Hash(), 0)
39+
rawdb.WriteBlock(db, bl)
40+
41+
// create chain config, even with incomplete genesis input: the chain config should be corrected
42+
chainConfig, _, err := SetupGenesisBlockWithOverride(db, tdb, genesis, &ChainOverrides{
43+
ApplySuperchainUpgrades: true,
44+
})
45+
if err != nil {
46+
t.Fatal(err)
47+
}
48+
// check if we have a corrected chain config
49+
if chainConfig.RegolithTime == nil {
50+
t.Fatal("expected regolith time to be corrected, but time is still nil")
51+
} else if *chainConfig.RegolithTime != expectedRegolithTime {
52+
t.Fatalf("expected regolith time to be %d, but got %d", expectedRegolithTime, *chainConfig.RegolithTime)
53+
}
54+
}

eth/backend.go

+1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
215215
if config.OverrideOptimismCanyon != nil {
216216
overrides.OverrideOptimismCanyon = config.OverrideOptimismCanyon
217217
}
218+
overrides.ApplySuperchainUpgrades = config.ApplySuperchainUpgrades
218219
eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, config.Genesis, &overrides, eth.engine, vmConfig, eth.shouldPreserve, &config.TransactionHistory)
219220
if err != nil {
220221
return nil, err

eth/ethconfig/config.go

+3
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ type Config struct {
170170

171171
OverrideOptimismCanyon *uint64 `toml:",omitempty"`
172172

173+
// ApplySuperchainUpgrades requests the node to load chain-configuration from the superchain-registry.
174+
ApplySuperchainUpgrades bool `toml:",omitempty"`
175+
173176
RollupSequencerHTTP string
174177
RollupHistoricalRPC string
175178
RollupHistoricalRPCTimeout time.Duration

eth/ethconfig/gen_config.go

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)