Skip to content

Commit 1f64f84

Browse files
Add bedrock fork block & overrides (ethereum#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.
1 parent 92c0e4e commit 1f64f84

File tree

7 files changed

+85
-18
lines changed

7 files changed

+85
-18
lines changed

cmd/geth/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
161161
if ctx.IsSet(utils.OverrideTerminalTotalDifficulty.Name) {
162162
cfg.Eth.OverrideTerminalTotalDifficulty = flags.GlobalBig(ctx, utils.OverrideTerminalTotalDifficulty.Name)
163163
}
164+
if ctx.IsSet(utils.OverrideOptimismBedrock.Name) {
165+
cfg.Eth.OverrideOptimismBedrock = flags.GlobalBig(ctx, utils.OverrideOptimismBedrock.Name)
166+
}
167+
if ctx.IsSet(utils.OverrideOptimism.Name) {
168+
override := ctx.Bool(utils.OverrideOptimism.Name)
169+
cfg.Eth.OverrideOptimism = &override
170+
}
164171
if ctx.IsSet(utils.OverrideTerminalTotalDifficultyPassed.Name) {
165172
override := ctx.Bool(utils.OverrideTerminalTotalDifficultyPassed.Name)
166173
cfg.Eth.OverrideTerminalTotalDifficultyPassed = &override

cmd/geth/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ var (
6666
utils.SmartCardDaemonPathFlag,
6767
utils.OverrideTerminalTotalDifficulty,
6868
utils.OverrideTerminalTotalDifficultyPassed,
69+
utils.OverrideOptimismBedrock,
70+
utils.OverrideOptimism,
6971
utils.EthashCacheDirFlag,
7072
utils.EthashCachesInMemoryFlag,
7173
utils.EthashCachesOnDiskFlag,

cmd/utils/flags.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,16 @@ var (
282282
Usage: "Manually specify TerminalTotalDifficultyPassed, overriding the bundled setting",
283283
Category: flags.EthCategory,
284284
}
285+
OverrideOptimismBedrock = &flags.BigFlag{
286+
Name: "override.bedrock",
287+
Usage: "Manually specify OptimsimBedrock, overriding the bundled setting",
288+
Category: flags.EthCategory,
289+
}
290+
OverrideOptimism = &cli.BoolFlag{
291+
Name: "override.optimism",
292+
Usage: "Manually specify optimism",
293+
Category: flags.EthCategory,
294+
}
285295
// Light server and client settings
286296
LightServeFlag = &cli.IntFlag{
287297
Name: "light.serve",

core/genesis.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ func (e *GenesisMismatchError) Error() string {
269269
type ChainOverrides struct {
270270
OverrideTerminalTotalDifficulty *big.Int
271271
OverrideTerminalTotalDifficultyPassed *bool
272+
OverrideOptimismBedrock *big.Int
273+
OverrideOptimism *bool
272274
}
273275

274276
// SetupGenesisBlock writes or updates the genesis block in db.
@@ -301,6 +303,17 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
301303
if overrides != nil && overrides.OverrideTerminalTotalDifficultyPassed != nil {
302304
config.TerminalTotalDifficultyPassed = *overrides.OverrideTerminalTotalDifficultyPassed
303305
}
306+
if overrides != nil && overrides.OverrideOptimismBedrock != nil {
307+
config.BedrockBlock = overrides.OverrideOptimismBedrock
308+
}
309+
if overrides != nil && overrides.OverrideOptimism != nil {
310+
if *overrides.OverrideOptimism {
311+
config.Optimism = &params.OptimismConfig{
312+
EIP1559Elasticity: 10,
313+
EIP1559Denominator: 50,
314+
}
315+
}
316+
}
304317
}
305318
}
306319

eth/backend.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
203203
if config.OverrideTerminalTotalDifficulty != nil {
204204
overrides.OverrideTerminalTotalDifficulty = config.OverrideTerminalTotalDifficulty
205205
}
206+
if config.OverrideOptimismBedrock != nil {
207+
overrides.OverrideOptimismBedrock = config.OverrideOptimismBedrock
208+
}
209+
if config.OverrideOptimism != nil {
210+
overrides.OverrideOptimism = config.OverrideOptimism
211+
}
206212
if config.OverrideTerminalTotalDifficultyPassed != nil {
207213
overrides.OverrideTerminalTotalDifficultyPassed = config.OverrideTerminalTotalDifficultyPassed
208214
}

eth/ethconfig/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ type Config struct {
213213
// OverrideTerminalTotalDifficultyPassed (TODO: remove after the fork)
214214
OverrideTerminalTotalDifficultyPassed *bool `toml:",omitempty"`
215215

216+
OverrideOptimismBedrock *big.Int
217+
OverrideOptimism *bool
218+
216219
// SyncTarget defines the target block of sync. It's only used for
217220
// development purposes.
218221
SyncTarget *types.Block

params/config.go

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,20 @@ var (
271271
//
272272
// This configuration is intentionally not using keyed fields to force anyone
273273
// adding flags to the config to also have to set these fields.
274-
AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, false, new(EthashConfig), nil, nil}
274+
AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, big.NewInt(0), nil, false, new(EthashConfig), nil, nil}
275275

276276
// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
277277
// and accepted by the Ethereum core developers into the Clique consensus.
278278
//
279279
// This configuration is intentionally not using keyed fields to force anyone
280280
// adding flags to the config to also have to set these fields.
281-
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, nil, nil, false, nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil}
281+
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, nil, big.NewInt(0), nil, false, nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil}
282282

283-
TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, false, new(EthashConfig), nil, nil}
284-
NonActivatedConfig = &ChainConfig{big.NewInt(1), nil, nil, false, nil, common.Hash{}, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, false, new(EthashConfig), nil, nil}
283+
// This is a optimism config with bedrock starting a block 5
284+
AllOptimismProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, big.NewInt(5), nil, false, nil, nil, &OptimismConfig{EIP1559Elasticity: 50, EIP1559Denominator: 10}}
285+
286+
TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, big.NewInt(0), nil, false, new(EthashConfig), nil, nil}
287+
NonActivatedConfig = &ChainConfig{big.NewInt(1), nil, nil, false, nil, common.Hash{}, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, big.NewInt(0), nil, false, new(EthashConfig), nil, nil}
285288
TestRules = TestChainConfig.Rules(new(big.Int), false)
286289
)
287290

@@ -374,6 +377,7 @@ type ChainConfig struct {
374377
MergeNetsplitBlock *big.Int `json:"mergeNetsplitBlock,omitempty"` // Virtual fork after The Merge to use as a network splitter
375378
ShanghaiBlock *big.Int `json:"shanghaiBlock,omitempty"` // Shanghai switch block (nil = no fork, 0 = already on shanghai)
376379
CancunBlock *big.Int `json:"cancunBlock,omitempty"` // Cancun switch block (nil = no fork, 0 = already on cancun)
380+
BedrockBlock *big.Int `json:"bedrockBlock,omitempty"` // Bedrock switch block (nil = no fork, 0 = already on optimism bedrock)
377381

378382
// TerminalTotalDifficulty is the amount of total difficulty reached by
379383
// the network that triggers the consensus upgrade.
@@ -594,6 +598,26 @@ func (c *ChainConfig) IsCancun(num *big.Int) bool {
594598
return isForked(c.CancunBlock, num)
595599
}
596600

601+
// IsBedrock returns whether num is either equal to the Bedrock fork block or greater.
602+
func (c *ChainConfig) IsBedrock(num *big.Int) bool {
603+
return isForked(c.BedrockBlock, num)
604+
}
605+
606+
// IsOptimism returns whether the node is an optimism node or not.
607+
func (c *ChainConfig) IsOptimism() bool {
608+
return c.Optimism != nil
609+
}
610+
611+
// IsOptimismBedrock returns true iff this is an optimism node & bedrock is active
612+
func (c *ChainConfig) IsOptimismBedrock(num *big.Int) bool {
613+
return c.IsOptimism() && c.IsBedrock(num)
614+
}
615+
616+
// IsOptimismPreBedrock returns true iff this is an optimism node & bedrock is not yet active
617+
func (c *ChainConfig) IsOptimismPreBedrock(num *big.Int) bool {
618+
return c.IsOptimism() && !c.IsBedrock(num)
619+
}
620+
597621
// CheckCompatible checks whether scheduled fork transitions have been imported
598622
// with a mismatching chain configuration.
599623
func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64) *ConfigCompatError {
@@ -808,6 +832,7 @@ type Rules struct {
808832
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
809833
IsBerlin, IsLondon bool
810834
IsMerge, IsShanghai, isCancun bool
835+
IsOptimismBedrock bool
811836
}
812837

813838
// Rules ensures c's ChainID is not nil.
@@ -817,19 +842,20 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool) Rules {
817842
chainID = new(big.Int)
818843
}
819844
return Rules{
820-
ChainID: new(big.Int).Set(chainID),
821-
IsHomestead: c.IsHomestead(num),
822-
IsEIP150: c.IsEIP150(num),
823-
IsEIP155: c.IsEIP155(num),
824-
IsEIP158: c.IsEIP158(num),
825-
IsByzantium: c.IsByzantium(num),
826-
IsConstantinople: c.IsConstantinople(num),
827-
IsPetersburg: c.IsPetersburg(num),
828-
IsIstanbul: c.IsIstanbul(num),
829-
IsBerlin: c.IsBerlin(num),
830-
IsLondon: c.IsLondon(num),
831-
IsMerge: isMerge,
832-
IsShanghai: c.IsShanghai(num),
833-
isCancun: c.IsCancun(num),
845+
ChainID: new(big.Int).Set(chainID),
846+
IsHomestead: c.IsHomestead(num),
847+
IsEIP150: c.IsEIP150(num),
848+
IsEIP155: c.IsEIP155(num),
849+
IsEIP158: c.IsEIP158(num),
850+
IsByzantium: c.IsByzantium(num),
851+
IsConstantinople: c.IsConstantinople(num),
852+
IsPetersburg: c.IsPetersburg(num),
853+
IsIstanbul: c.IsIstanbul(num),
854+
IsBerlin: c.IsBerlin(num),
855+
IsLondon: c.IsLondon(num),
856+
IsMerge: isMerge,
857+
IsShanghai: c.IsShanghai(num),
858+
isCancun: c.IsCancun(num),
859+
IsOptimismBedrock: c.IsOptimismBedrock(num),
834860
}
835861
}

0 commit comments

Comments
 (0)