Skip to content

Commit 41e7548

Browse files
authored
eth, les, params: log chain config a bit saner (ethereum#24904)
Previously on Geth startup we just logged the chain config is a semi-json-y format. Whilst that worked while we had a handful of hard-forks defined, currently it's kind of unwieldy. This PR converts that original data dump and converts it into a user friendly - alas multiline - log output.
1 parent 450f5da commit 41e7548

File tree

5 files changed

+89
-33
lines changed

5 files changed

+89
-33
lines changed

core/forkid/forkid_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
// the correct fork ID.
3232
func TestCreation(t *testing.T) {
3333
mergeConfig := *params.MainnetChainConfig
34-
mergeConfig.MergeForkBlock = big.NewInt(15000000)
34+
mergeConfig.MergeNetsplitBlock = big.NewInt(15000000)
3535
type testcase struct {
3636
head uint64
3737
want ID

eth/backend.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"fmt"
2323
"math/big"
2424
"runtime"
25+
"strings"
2526
"sync"
2627
"sync/atomic"
2728
"time"
@@ -140,7 +141,13 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
140141
if _, ok := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !ok {
141142
return nil, genesisErr
142143
}
143-
log.Info("Initialised chain configuration", "config", chainConfig)
144+
log.Info("")
145+
log.Info(strings.Repeat("-", 153))
146+
for _, line := range strings.Split(chainConfig.String(), "\n") {
147+
log.Info(line)
148+
}
149+
log.Info(strings.Repeat("-", 153))
150+
log.Info("")
144151

145152
if err := pruner.RecoverPruning(stack.ResolvePath(""), chainDb, stack.ResolvePath(config.TrieCleanCacheJournal)); err != nil {
146153
log.Error("Failed to recover state", "error", err)

les/client.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package les
1919

2020
import (
2121
"fmt"
22+
"strings"
2223
"time"
2324

2425
"github.com/ethereum/go-ethereum/accounts"
@@ -96,7 +97,13 @@ func New(stack *node.Node, config *ethconfig.Config) (*LightEthereum, error) {
9697
if _, isCompat := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !isCompat {
9798
return nil, genesisErr
9899
}
99-
log.Info("Initialised chain configuration", "config", chainConfig)
100+
log.Info("")
101+
log.Info(strings.Repeat("-", 153))
102+
for _, line := range strings.Split(chainConfig.String(), "\n") {
103+
log.Info(line)
104+
}
105+
log.Info(strings.Repeat("-", 153))
106+
log.Info("")
100107

101108
peers := newServerPeerSet()
102109
merger := consensus.NewMerger(chainDb)

params/config.go

Lines changed: 71 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,15 @@ var (
272272
TestRules = TestChainConfig.Rules(new(big.Int), false)
273273
)
274274

275+
// NetworkNames are user friendly names to use in the chain spec banner.
276+
var NetworkNames = map[string]string{
277+
MainnetChainConfig.ChainID.String(): "mainnet",
278+
RopstenChainConfig.ChainID.String(): "ropsten",
279+
RinkebyChainConfig.ChainID.String(): "rinkeby",
280+
GoerliChainConfig.ChainID.String(): "goerli",
281+
SepoliaChainConfig.ChainID.String(): "sepolia",
282+
}
283+
275284
// TrustedCheckpoint represents a set of post-processed trie roots (CHT and
276285
// BloomTrie) associated with the appropriate section index and head hash. It is
277286
// used to start light syncing from this checkpoint and avoid downloading the
@@ -348,7 +357,7 @@ type ChainConfig struct {
348357
BerlinBlock *big.Int `json:"berlinBlock,omitempty"` // Berlin switch block (nil = no fork, 0 = already on berlin)
349358
LondonBlock *big.Int `json:"londonBlock,omitempty"` // London switch block (nil = no fork, 0 = already on london)
350359
ArrowGlacierBlock *big.Int `json:"arrowGlacierBlock,omitempty"` // Eip-4345 (bomb delay) switch block (nil = no fork, 0 = already activated)
351-
MergeForkBlock *big.Int `json:"mergeForkBlock,omitempty"` // EIP-3675 (TheMerge) switch block (nil = no fork, 0 = already in merge proceedings)
360+
MergeNetsplitBlock *big.Int `json:"mergeNetsplitBlock,omitempty"` // Virtual fork after The Merge to use as a network splitter
352361

353362
// TerminalTotalDifficulty is the amount of total difficulty reached by
354363
// the network that triggers the consensus upgrade.
@@ -380,35 +389,68 @@ func (c *CliqueConfig) String() string {
380389

381390
// String implements the fmt.Stringer interface.
382391
func (c *ChainConfig) String() string {
383-
var engine interface{}
392+
var banner string
393+
394+
// Create some basinc network config output
395+
network := NetworkNames[c.ChainID.String()]
396+
if network == "" {
397+
network = "unknown"
398+
}
399+
banner += fmt.Sprintf("Chain ID: %v (%s)\n", c.ChainID, network)
384400
switch {
385401
case c.Ethash != nil:
386-
engine = c.Ethash
402+
if c.TerminalTotalDifficulty == nil {
403+
banner += "Consensus: Ethash (proof-of-work)\n"
404+
} else {
405+
banner += "Consensus: Beacon (proof-of-stake), merged from Ethash (proof-of-work)\n"
406+
}
387407
case c.Clique != nil:
388-
engine = c.Clique
408+
if c.TerminalTotalDifficulty == nil {
409+
banner += "Consensus: Clique (proof-of-authority)\n"
410+
} else {
411+
banner += "Consensus: Beacon (proof-of-stake), merged from Clique (proof-of-authority)\n"
412+
}
389413
default:
390-
engine = "unknown"
391-
}
392-
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Berlin: %v, London: %v, Arrow Glacier: %v, MergeFork: %v, Terminal TD: %v, Engine: %v}",
393-
c.ChainID,
394-
c.HomesteadBlock,
395-
c.DAOForkBlock,
396-
c.DAOForkSupport,
397-
c.EIP150Block,
398-
c.EIP155Block,
399-
c.EIP158Block,
400-
c.ByzantiumBlock,
401-
c.ConstantinopleBlock,
402-
c.PetersburgBlock,
403-
c.IstanbulBlock,
404-
c.MuirGlacierBlock,
405-
c.BerlinBlock,
406-
c.LondonBlock,
407-
c.ArrowGlacierBlock,
408-
c.MergeForkBlock,
409-
c.TerminalTotalDifficulty,
410-
engine,
411-
)
414+
banner += "Consensus: unknown\n"
415+
}
416+
banner += "\n"
417+
418+
// Create a list of forks with a short description of them. Forks that only
419+
// makes sense for mainnet should be optional at printing to avoid bloating
420+
// the output for testnets and private networks.
421+
banner += "Pre-Merge hard forks:\n"
422+
banner += fmt.Sprintf(" - Homestead: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/homestead.md)\n", c.HomesteadBlock)
423+
if c.DAOForkBlock != nil {
424+
banner += fmt.Sprintf(" - DAO Fork: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/dao-fork.md)\n", c.DAOForkBlock)
425+
}
426+
banner += fmt.Sprintf(" - Tangerine Whistle (EIP 150): %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/tangerine-whistle.md)\n", c.EIP150Block)
427+
banner += fmt.Sprintf(" - Spurious Dragon/1 (EIP 155): %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/spurious-dragon.md)\n", c.EIP155Block)
428+
banner += fmt.Sprintf(" - Spurious Dragon/2 (EIP 158): %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/spurious-dragon.md)\n", c.EIP155Block)
429+
banner += fmt.Sprintf(" - Byzantium: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/byzantium.md)\n", c.ByzantiumBlock)
430+
banner += fmt.Sprintf(" - Constantinople: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/constantinople.md)\n", c.ConstantinopleBlock)
431+
banner += fmt.Sprintf(" - Petersburg: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/petersburg.md)\n", c.PetersburgBlock)
432+
banner += fmt.Sprintf(" - Istanbul: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/istanbul.md)\n", c.IstanbulBlock)
433+
if c.MuirGlacierBlock != nil {
434+
banner += fmt.Sprintf(" - Muir Glacier: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/muir-glacier.md)\n", c.MuirGlacierBlock)
435+
}
436+
banner += fmt.Sprintf(" - Berlin: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/berlin.md)\n", c.BerlinBlock)
437+
banner += fmt.Sprintf(" - London: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/london.md)\n", c.LondonBlock)
438+
if c.ArrowGlacierBlock != nil {
439+
banner += fmt.Sprintf(" - Arrow Glacier: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/arrow-glacier.md)\n", c.ArrowGlacierBlock)
440+
}
441+
banner += "\n"
442+
443+
// Add a special section for the merge as it's non-obvious
444+
if c.TerminalTotalDifficulty == nil {
445+
banner += "Merge not configured!\n"
446+
banner += " - Hard-fork specification: https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/paris.md)"
447+
} else {
448+
banner += "Merge configured:\n"
449+
banner += " - Hard-fork specification: https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/paris.md)\n"
450+
banner += fmt.Sprintf(" - Total terminal difficulty: %v\n", c.TerminalTotalDifficulty)
451+
banner += fmt.Sprintf(" - Merge netsplit block: %-8v", c.MergeNetsplitBlock)
452+
}
453+
return banner
412454
}
413455

414456
// IsHomestead returns whether num is either equal to the homestead block or greater.
@@ -527,7 +569,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
527569
{name: "berlinBlock", block: c.BerlinBlock},
528570
{name: "londonBlock", block: c.LondonBlock},
529571
{name: "arrowGlacierBlock", block: c.ArrowGlacierBlock, optional: true},
530-
{name: "mergeStartBlock", block: c.MergeForkBlock, optional: true},
572+
{name: "mergeNetsplitBlock", block: c.MergeNetsplitBlock, optional: true},
531573
} {
532574
if lastFork.name != "" {
533575
// Next one must be higher number
@@ -600,8 +642,8 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi
600642
if isForkIncompatible(c.ArrowGlacierBlock, newcfg.ArrowGlacierBlock, head) {
601643
return newCompatError("Arrow Glacier fork block", c.ArrowGlacierBlock, newcfg.ArrowGlacierBlock)
602644
}
603-
if isForkIncompatible(c.MergeForkBlock, newcfg.MergeForkBlock, head) {
604-
return newCompatError("Merge Start fork block", c.MergeForkBlock, newcfg.MergeForkBlock)
645+
if isForkIncompatible(c.MergeNetsplitBlock, newcfg.MergeNetsplitBlock, head) {
646+
return newCompatError("Merge netsplit fork block", c.MergeNetsplitBlock, newcfg.MergeNetsplitBlock)
605647
}
606648
return nil
607649
}

tests/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ var Forks = map[string]*params.ChainConfig{
211211
BerlinBlock: big.NewInt(0),
212212
LondonBlock: big.NewInt(0),
213213
ArrowGlacierBlock: big.NewInt(0),
214-
MergeForkBlock: big.NewInt(0),
214+
MergeNetsplitBlock: big.NewInt(0),
215215
TerminalTotalDifficulty: big.NewInt(0),
216216
},
217217
}

0 commit comments

Comments
 (0)