Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

superchain: beta feature flag for overriding chain-config with superchain-registry #148

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ var (
utils.RollupDisableTxPoolGossipFlag,
utils.RollupComputePendingBlock,
utils.RollupHaltOnIncompatibleProtocolVersionFlag,
utils.RollupSuperchainUpgradesFlag,
configFileFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags)

Expand Down
6 changes: 6 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,11 @@ var (
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",
Category: flags.RollupCategory,
}
RollupSuperchainUpgradesFlag = &cli.BoolFlag{
Name: "beta.rollup.superchain-upgrades",
Usage: "Beta feature: apply superchain-registry config changes to the local chain-configuration",
Category: flags.EthCategory,
}

// Metrics flags
MetricsEnabledFlag = &cli.BoolFlag{
Expand Down Expand Up @@ -1884,6 +1889,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
cfg.RollupDisableTxPoolGossip = ctx.Bool(RollupDisableTxPoolGossipFlag.Name)
cfg.RollupDisableTxPoolAdmission = cfg.RollupSequencerHTTP != "" && !ctx.Bool(RollupEnableTxPoolAdmissionFlag.Name)
cfg.RollupHaltOnIncompatibleProtocolVersion = ctx.String(RollupHaltOnIncompatibleProtocolVersionFlag.Name)
cfg.ApplySuperchainUpgrades = ctx.Bool(RollupSuperchainUpgradesFlag.Name)
// Override any default configs for hard coded networks.
switch {
case ctx.Bool(MainnetFlag.Name):
Expand Down
30 changes: 15 additions & 15 deletions core/gen_genesis.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"math/big"
"strings"

"github.com/ethereum-optimism/superchain-registry/superchain"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
Expand Down Expand Up @@ -288,7 +290,8 @@ type ChainOverrides struct {
OverrideCancun *uint64
OverrideVerkle *uint64
// optimism
OverrideOptimismCanyon *uint64
OverrideOptimismCanyon *uint64
ApplySuperchainUpgrades bool
}

// SetupGenesisBlock writes or updates the genesis block in db.
Expand All @@ -314,6 +317,19 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *trie.Database, gen
}
applyOverrides := func(config *params.ChainConfig) {
if config != nil {
// If applying the superchain-registry to a known OP-Stack chain,
// then override the local chain-config with that from the registry.
if overrides != nil && overrides.ApplySuperchainUpgrades && config.IsOptimism() && config.ChainID != nil && genesis.Config.ChainID.IsUint64() {
if _, ok := superchain.OPChains[config.ChainID.Uint64()]; ok {
conf, err := params.LoadOPStackChainConfig(config.ChainID.Uint64())
if err != nil {
log.Warn("failed to load chain config from superchain-registry, skipping override", "err", err, "chain_id", config.ChainID)
protolambda marked this conversation as resolved.
Show resolved Hide resolved
} else {
*config = *conf
}
}
}

if config.IsOptimism() && config.ChainID != nil && config.ChainID.Cmp(big.NewInt(params.OPGoerliChainID)) == 0 {
// Apply Optimism Goerli regolith time
config.RegolithTime = &params.OptimismGoerliRegolithTime
Expand Down
37 changes: 37 additions & 0 deletions core/superchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"testing"

"github.com/ethereum-optimism/superchain-registry/superchain"

"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/trie"
)

func TestOPStackGenesis(t *testing.T) {
Expand All @@ -15,3 +18,37 @@ func TestOPStackGenesis(t *testing.T) {
t.Logf("chain: %d, genesis block hash: %s", id, gen.ToBlock().Hash())
}
}

func TestRegistryChainConfigOverride(t *testing.T) {
db := rawdb.NewMemoryDatabase()
genesis, err := LoadOPStackGenesis(10)
if err != nil {
t.Fatal(err)
}
if genesis.Config.RegolithTime == nil {
t.Fatal("expected non-nil regolith time")
}
expectedRegolithTime := *genesis.Config.RegolithTime
genesis.Config.RegolithTime = nil

// initialize the DB
tdb := trie.NewDatabase(db, newDbConfig(rawdb.PathScheme))
genesis.MustCommit(db, tdb)
bl := genesis.ToBlock()
rawdb.WriteCanonicalHash(db, bl.Hash(), 0)
rawdb.WriteBlock(db, bl)

// create chain config, even with incomplete genesis input: the chain config should be corrected
chainConfig, _, err := SetupGenesisBlockWithOverride(db, tdb, genesis, &ChainOverrides{
ApplySuperchainUpgrades: true,
})
if err != nil {
t.Fatal(err)
}
// check if we have a corrected chain config
if chainConfig.RegolithTime == nil {
protolambda marked this conversation as resolved.
Show resolved Hide resolved
t.Fatal("expected regolith time to be corrected, but time is still nil")
} else if *chainConfig.RegolithTime != expectedRegolithTime {
t.Fatalf("expected regolith time to be %d, but got %d", expectedRegolithTime, *chainConfig.RegolithTime)
}
}
1 change: 1 addition & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if config.OverrideOptimismCanyon != nil {
overrides.OverrideOptimismCanyon = config.OverrideOptimismCanyon
}
overrides.ApplySuperchainUpgrades = config.ApplySuperchainUpgrades
eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, config.Genesis, &overrides, eth.engine, vmConfig, eth.shouldPreserve, &config.TransactionHistory)
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ type Config struct {

OverrideOptimismCanyon *uint64 `toml:",omitempty"`

// ApplySuperchainUpgrades requests the node to load chain-configuration from the superchain-registry.
ApplySuperchainUpgrades bool `toml:",omitempty"`

RollupSequencerHTTP string
RollupHistoricalRPC string
RollupHistoricalRPCTimeout time.Duration
Expand Down
6 changes: 6 additions & 0 deletions eth/ethconfig/gen_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.