mirror of
https://github.com/status-im/op-geth.git
synced 2025-02-12 14:56:23 +00:00
Add bedrock fork block & overrides (#31)
This enables two overrides: the bedrock fork block & the optimism config being set. The optimism override uses the default EIP 1559 parameters. These make it easy to setup a node in optimism mode & have a configurable bedrock block. All of the rules accessors are also helpful for checking which mode the node is running in.
This commit is contained in:
parent
ca8bbd6cf5
commit
6b41815cb5
@ -162,6 +162,15 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
|
||||
v := ctx.Uint64(utils.OverrideShanghai.Name)
|
||||
cfg.Eth.OverrideShanghai = &v
|
||||
}
|
||||
|
||||
if ctx.IsSet(utils.OverrideOptimismBedrock.Name) {
|
||||
cfg.Eth.OverrideOptimismBedrock = flags.GlobalBig(ctx, utils.OverrideOptimismBedrock.Name)
|
||||
}
|
||||
if ctx.IsSet(utils.OverrideOptimism.Name) {
|
||||
override := ctx.Bool(utils.OverrideOptimism.Name)
|
||||
cfg.Eth.OverrideOptimism = &override
|
||||
}
|
||||
|
||||
backend, eth := utils.RegisterEthService(stack, &cfg.Eth)
|
||||
|
||||
// Configure log filter RPC API.
|
||||
|
@ -66,6 +66,8 @@ var (
|
||||
utils.SmartCardDaemonPathFlag,
|
||||
utils.OverrideShanghai,
|
||||
utils.EnablePersonal,
|
||||
utils.OverrideOptimismBedrock,
|
||||
utils.OverrideOptimism,
|
||||
utils.EthashCacheDirFlag,
|
||||
utils.EthashCachesInMemoryFlag,
|
||||
utils.EthashCachesOnDiskFlag,
|
||||
|
@ -274,6 +274,16 @@ var (
|
||||
Usage: "Manually specify the Shanghai fork timestamp, overriding the bundled setting",
|
||||
Category: flags.EthCategory,
|
||||
}
|
||||
OverrideOptimismBedrock = &flags.BigFlag{
|
||||
Name: "override.bedrock",
|
||||
Usage: "Manually specify OptimsimBedrock, overriding the bundled setting",
|
||||
Category: flags.EthCategory,
|
||||
}
|
||||
OverrideOptimism = &cli.BoolFlag{
|
||||
Name: "override.optimism",
|
||||
Usage: "Manually specify optimism",
|
||||
Category: flags.EthCategory,
|
||||
}
|
||||
// Light server and client settings
|
||||
LightServeFlag = &cli.IntFlag{
|
||||
Name: "light.serve",
|
||||
|
@ -268,6 +268,9 @@ func (e *GenesisMismatchError) Error() string {
|
||||
// ChainOverrides contains the changes to chain config.
|
||||
type ChainOverrides struct {
|
||||
OverrideShanghai *uint64
|
||||
// optimism
|
||||
OverrideOptimismBedrock *big.Int
|
||||
OverrideOptimism *bool
|
||||
}
|
||||
|
||||
// SetupGenesisBlock writes or updates the genesis block in db.
|
||||
@ -296,6 +299,17 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *trie.Database, gen
|
||||
if overrides != nil && overrides.OverrideShanghai != nil {
|
||||
config.ShanghaiTime = overrides.OverrideShanghai
|
||||
}
|
||||
if overrides != nil && overrides.OverrideOptimismBedrock != nil {
|
||||
config.BedrockBlock = overrides.OverrideOptimismBedrock
|
||||
}
|
||||
if overrides != nil && overrides.OverrideOptimism != nil {
|
||||
if *overrides.OverrideOptimism {
|
||||
config.Optimism = ¶ms.OptimismConfig{
|
||||
EIP1559Elasticity: 10,
|
||||
EIP1559Denominator: 50,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Just commit the new block if there is no stored genesis block.
|
||||
|
@ -203,6 +203,12 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
||||
if config.OverrideShanghai != nil {
|
||||
overrides.OverrideShanghai = config.OverrideShanghai
|
||||
}
|
||||
if config.OverrideOptimismBedrock != nil {
|
||||
overrides.OverrideOptimismBedrock = config.OverrideOptimismBedrock
|
||||
}
|
||||
if config.OverrideOptimism != nil {
|
||||
overrides.OverrideOptimism = config.OverrideOptimism
|
||||
}
|
||||
eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, config.Genesis, &overrides, eth.engine, vmConfig, eth.shouldPreserve, &config.TxLookupLimit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -18,6 +18,7 @@
|
||||
package ethconfig
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
@ -208,6 +209,9 @@ type Config struct {
|
||||
// OverrideShanghai (TODO: remove after the fork)
|
||||
OverrideShanghai *uint64 `toml:",omitempty"`
|
||||
|
||||
OverrideOptimismBedrock *big.Int
|
||||
OverrideOptimism *bool
|
||||
|
||||
RollupSequencerHTTP string
|
||||
RollupHistoricalRPC string
|
||||
RollupDisableTxPoolGossip bool
|
||||
|
@ -342,6 +342,15 @@ var (
|
||||
Clique: nil,
|
||||
}
|
||||
TestRules = TestChainConfig.Rules(new(big.Int), false, 0)
|
||||
|
||||
// This is an Optimism chain config with bedrock starting a block 5, introduced for historical endpoint testing, largely based on the clique config
|
||||
AllOptimismProtocolChanges = func() *ChainConfig {
|
||||
conf := *AllCliqueProtocolChanges // copy the config
|
||||
conf.Clique = nil
|
||||
conf.BedrockBlock = big.NewInt(5)
|
||||
conf.Optimism = &OptimismConfig{EIP1559Elasticity: 50, EIP1559Denominator: 10}
|
||||
return &conf
|
||||
}()
|
||||
)
|
||||
|
||||
// NetworkNames are user friendly names to use in the chain spec banner.
|
||||
@ -437,6 +446,8 @@ type ChainConfig struct {
|
||||
CancunTime *uint64 `json:"cancunTime,omitempty"` // Cancun switch time (nil = no fork, 0 = already on cancun)
|
||||
PragueTime *uint64 `json:"pragueTime,omitempty"` // Prague switch time (nil = no fork, 0 = already on prague)
|
||||
|
||||
BedrockBlock *big.Int `json:"bedrockBlock,omitempty"` // Bedrock switch block (nil = no fork, 0 = already on optimism bedrock)
|
||||
|
||||
// TerminalTotalDifficulty is the amount of total difficulty reached by
|
||||
// the network that triggers the consensus upgrade.
|
||||
TerminalTotalDifficulty *big.Int `json:"terminalTotalDifficulty,omitempty"`
|
||||
@ -670,6 +681,26 @@ func (c *ChainConfig) IsPrague(time uint64) bool {
|
||||
return isTimestampForked(c.PragueTime, time)
|
||||
}
|
||||
|
||||
// IsBedrock returns whether num is either equal to the Bedrock fork block or greater.
|
||||
func (c *ChainConfig) IsBedrock(num *big.Int) bool {
|
||||
return isBlockForked(c.BedrockBlock, num)
|
||||
}
|
||||
|
||||
// IsOptimism returns whether the node is an optimism node or not.
|
||||
func (c *ChainConfig) IsOptimism() bool {
|
||||
return c.Optimism != nil
|
||||
}
|
||||
|
||||
// IsOptimismBedrock returns true iff this is an optimism node & bedrock is active
|
||||
func (c *ChainConfig) IsOptimismBedrock(num *big.Int) bool {
|
||||
return c.IsOptimism() && c.IsBedrock(num)
|
||||
}
|
||||
|
||||
// IsOptimismPreBedrock returns true iff this is an optimism node & bedrock is not yet active
|
||||
func (c *ChainConfig) IsOptimismPreBedrock(num *big.Int) bool {
|
||||
return c.IsOptimism() && !c.IsBedrock(num)
|
||||
}
|
||||
|
||||
// CheckCompatible checks whether scheduled fork transitions have been imported
|
||||
// with a mismatching chain configuration.
|
||||
func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64, time uint64) *ConfigCompatError {
|
||||
@ -978,6 +1009,7 @@ type Rules struct {
|
||||
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
|
||||
IsBerlin, IsLondon bool
|
||||
IsMerge, IsShanghai, isCancun, isPrague bool
|
||||
IsOptimismBedrock bool
|
||||
}
|
||||
|
||||
// Rules ensures c's ChainID is not nil.
|
||||
@ -1002,5 +1034,7 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
|
||||
IsShanghai: c.IsShanghai(timestamp),
|
||||
isCancun: c.IsCancun(timestamp),
|
||||
isPrague: c.IsPrague(timestamp),
|
||||
// Optimism
|
||||
IsOptimismBedrock: c.IsOptimismBedrock(num),
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user