From 0d1b63067ff41afd72a7808b587926aa088df5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Wed, 18 May 2022 19:02:03 +0300 Subject: [PATCH 1/5] eth, les, params: log chain config a bit saner --- eth/backend.go | 9 ++++- les/client.go | 9 ++++- params/config.go | 90 ++++++++++++++++++++++++++++++++++-------------- 3 files changed, 81 insertions(+), 27 deletions(-) diff --git a/eth/backend.go b/eth/backend.go index 8e70723b5b16..fc0a8b587c2f 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -22,6 +22,7 @@ import ( "fmt" "math/big" "runtime" + "strings" "sync" "sync/atomic" "time" @@ -140,7 +141,13 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { if _, ok := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !ok { return nil, genesisErr } - log.Info("Initialised chain configuration", "config", chainConfig) + log.Info("") + log.Info("---------------------------------------------------------------------------------------------") + for _, line := range strings.Split(chainConfig.String(), "\n") { + log.Info(line) + } + log.Info("---------------------------------------------------------------------------------------------") + log.Info("") if err := pruner.RecoverPruning(stack.ResolvePath(""), chainDb, stack.ResolvePath(config.TrieCleanCacheJournal)); err != nil { log.Error("Failed to recover state", "error", err) diff --git a/les/client.go b/les/client.go index 43207f3443ec..ec2e1885ff66 100644 --- a/les/client.go +++ b/les/client.go @@ -19,6 +19,7 @@ package les import ( "fmt" + "strings" "time" "github.com/ethereum/go-ethereum/accounts" @@ -96,7 +97,13 @@ func New(stack *node.Node, config *ethconfig.Config) (*LightEthereum, error) { if _, isCompat := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !isCompat { return nil, genesisErr } - log.Info("Initialised chain configuration", "config", chainConfig) + log.Info("") + log.Info("---------------------------------------------------------------------------------------------") + for _, line := range strings.Split(chainConfig.String(), "\n") { + log.Info(line) + } + log.Info("---------------------------------------------------------------------------------------------") + log.Info("") peers := newServerPeerSet() merger := consensus.NewMerger(chainDb) diff --git a/params/config.go b/params/config.go index 0733bade39b3..a4d40b947530 100644 --- a/params/config.go +++ b/params/config.go @@ -272,6 +272,15 @@ var ( TestRules = TestChainConfig.Rules(new(big.Int), false) ) +// NetworkNames are user friendly names to use in the chain spec banner. +var NetworkNames = map[string]string{ + MainnetChainConfig.ChainID.String(): "mainnet", + RopstenChainConfig.ChainID.String(): "ropsten", + RinkebyChainConfig.ChainID.String(): "rinkeby", + GoerliChainConfig.ChainID.String(): "goerli", + SepoliaChainConfig.ChainID.String(): "sepolia", +} + // TrustedCheckpoint represents a set of post-processed trie roots (CHT and // BloomTrie) associated with the appropriate section index and head hash. It is // used to start light syncing from this checkpoint and avoid downloading the @@ -380,35 +389,66 @@ func (c *CliqueConfig) String() string { // String implements the fmt.Stringer interface. func (c *ChainConfig) String() string { - var engine interface{} + var banner string + + // Create some basinc network config output + network := NetworkNames[c.ChainID.String()] + if network == "" { + network = "unknown" + } + banner += fmt.Sprintf("Chain ID: %v (%s)\n", c.ChainID, network) switch { case c.Ethash != nil: - engine = c.Ethash + if c.TerminalTotalDifficulty == nil { + banner += fmt.Sprintf("Consensus: Ethash (proof-of-work)\n") + } else { + banner += fmt.Sprintf("Consensus: Beacon (proof-of-stake), merged from Ethash (proof-of-work)\n") + } case c.Clique != nil: - engine = c.Clique + if c.TerminalTotalDifficulty == nil { + banner += fmt.Sprintf("Consensus: Clique (proof-of-authority)\n") + } else { + banner += fmt.Sprintf("Consensus: Beacon (proof-of-stake), merged from Clique (proof-of-authority)\n") + } default: - engine = "unknown" - } - 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}", - c.ChainID, - c.HomesteadBlock, - c.DAOForkBlock, - c.DAOForkSupport, - c.EIP150Block, - c.EIP155Block, - c.EIP158Block, - c.ByzantiumBlock, - c.ConstantinopleBlock, - c.PetersburgBlock, - c.IstanbulBlock, - c.MuirGlacierBlock, - c.BerlinBlock, - c.LondonBlock, - c.ArrowGlacierBlock, - c.MergeForkBlock, - c.TerminalTotalDifficulty, - engine, - ) + banner += fmt.Sprintf("Consensus: unknown\n") + } + banner += "\n" + + // Create a list of forks with a short description of them. Forks that only + // makes sense for mainnet should be optional at printing to avoid bloating + // the output for testnets and private networks. + banner += "Pre-Merge hard forks:\n" + banner += fmt.Sprintf(" - Homestead: %-8v (delegatecall)\n", c.HomesteadBlock) + if c.DAOForkBlock != nil { + banner += fmt.Sprintf(" - DAO Fork: %-8v (TheDAO attack neutralization)\n", c.DAOForkBlock) + } + banner += fmt.Sprintf(" - Tangerine Whistle (EIP 150): %-8v (Shanghai attack neutralization)\n", c.EIP150Block) + banner += fmt.Sprintf(" - Spurious Dragon/1 (EIP 155): %-8v (replay protection)\n", c.EIP155Block) + banner += fmt.Sprintf(" - Spurious Dragon/2 (EIP 158): %-8v (Shanghai attack cleanup)\n", c.EIP155Block) + banner += fmt.Sprintf(" - Byzantium: %-8v (revert, bn256, returndata, staticcall, status code)\n", c.ByzantiumBlock) + banner += fmt.Sprintf(" - Constantinople: %-8v (bitshifts, create2, extcodehash, net metering)\n", c.ConstantinopleBlock) + banner += fmt.Sprintf(" - Petersburg: %-8v (undo faulty net metering)\n", c.PetersburgBlock) + banner += fmt.Sprintf(" - Istanbul: %-8v (blake2, chainid, fixed net metering)\n", c.IstanbulBlock) + if c.MuirGlacierBlock != nil { + banner += fmt.Sprintf(" - Muir Glacier: %-8v (ice age delay)\n", c.MuirGlacierBlock) + } + banner += fmt.Sprintf(" - Berlin: %-8v (typed transaction, access lists)\n", c.BerlinBlock) + banner += fmt.Sprintf(" - London: %-8v (fee burn, basefee)\n", c.LondonBlock) + if c.ArrowGlacierBlock != nil { + banner += fmt.Sprintf(" - Arrow Glacier: %-8v (ice age delay)\n", c.ArrowGlacierBlock) + } + banner += "\n" + + // Add a special section for the merge as it's non-obvious + if c.TerminalTotalDifficulty == nil { + banner += "Merge not configured!" + } else { + banner += "Merge configured:\n" + banner += fmt.Sprintf(" - Total terminal difficulty: %v (proof-of-stake switchover threshold)\n", c.TerminalTotalDifficulty) + banner += fmt.Sprintf(" - Merge fork block: %-8v (network partitioning point)", c.MergeForkBlock) + } + return banner } // IsHomestead returns whether num is either equal to the homestead block or greater. From a771d23f445d62bdf5fbc194c9d882254f50d9ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Fri, 20 May 2022 14:21:10 +0300 Subject: [PATCH 2/5] core, params, tests: use URLs in fork listing, rename merde net splitter --- core/forkid/forkid_test.go | 2 +- params/config.go | 44 ++++++++++++++++++++------------------ tests/init.go | 2 +- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/core/forkid/forkid_test.go b/core/forkid/forkid_test.go index b0ee59b9eb7b..42adc0019d02 100644 --- a/core/forkid/forkid_test.go +++ b/core/forkid/forkid_test.go @@ -31,7 +31,7 @@ import ( // the correct fork ID. func TestCreation(t *testing.T) { mergeConfig := *params.MainnetChainConfig - mergeConfig.MergeForkBlock = big.NewInt(15000000) + mergeConfig.MergeNetsplitBlock = big.NewInt(15000000) type testcase struct { head uint64 want ID diff --git a/params/config.go b/params/config.go index a4d40b947530..019867bb7c67 100644 --- a/params/config.go +++ b/params/config.go @@ -357,7 +357,7 @@ type ChainConfig struct { BerlinBlock *big.Int `json:"berlinBlock,omitempty"` // Berlin switch block (nil = no fork, 0 = already on berlin) LondonBlock *big.Int `json:"londonBlock,omitempty"` // London switch block (nil = no fork, 0 = already on london) ArrowGlacierBlock *big.Int `json:"arrowGlacierBlock,omitempty"` // Eip-4345 (bomb delay) switch block (nil = no fork, 0 = already activated) - MergeForkBlock *big.Int `json:"mergeForkBlock,omitempty"` // EIP-3675 (TheMerge) switch block (nil = no fork, 0 = already in merge proceedings) + MergeNetsplitBlock *big.Int `json:"mergeNetsplitBlock,omitempty"` // Virtual fork after The Merge to use as a network splitter // TerminalTotalDifficulty is the amount of total difficulty reached by // the network that triggers the consensus upgrade. @@ -419,34 +419,36 @@ func (c *ChainConfig) String() string { // makes sense for mainnet should be optional at printing to avoid bloating // the output for testnets and private networks. banner += "Pre-Merge hard forks:\n" - banner += fmt.Sprintf(" - Homestead: %-8v (delegatecall)\n", c.HomesteadBlock) + banner += fmt.Sprintf(" - Homestead: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/homestead.md)\n", c.HomesteadBlock) if c.DAOForkBlock != nil { - banner += fmt.Sprintf(" - DAO Fork: %-8v (TheDAO attack neutralization)\n", c.DAOForkBlock) - } - banner += fmt.Sprintf(" - Tangerine Whistle (EIP 150): %-8v (Shanghai attack neutralization)\n", c.EIP150Block) - banner += fmt.Sprintf(" - Spurious Dragon/1 (EIP 155): %-8v (replay protection)\n", c.EIP155Block) - banner += fmt.Sprintf(" - Spurious Dragon/2 (EIP 158): %-8v (Shanghai attack cleanup)\n", c.EIP155Block) - banner += fmt.Sprintf(" - Byzantium: %-8v (revert, bn256, returndata, staticcall, status code)\n", c.ByzantiumBlock) - banner += fmt.Sprintf(" - Constantinople: %-8v (bitshifts, create2, extcodehash, net metering)\n", c.ConstantinopleBlock) - banner += fmt.Sprintf(" - Petersburg: %-8v (undo faulty net metering)\n", c.PetersburgBlock) - banner += fmt.Sprintf(" - Istanbul: %-8v (blake2, chainid, fixed net metering)\n", c.IstanbulBlock) + banner += fmt.Sprintf(" - DAO Fork: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/dao-fork.md)\n", c.DAOForkBlock) + } + 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) + 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) + 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) + banner += fmt.Sprintf(" - Byzantium: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/byzantium.md)\n", c.ByzantiumBlock) + banner += fmt.Sprintf(" - Constantinople: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/constantinople.md)\n", c.ConstantinopleBlock) + banner += fmt.Sprintf(" - Petersburg: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/petersburg.md)\n", c.PetersburgBlock) + banner += fmt.Sprintf(" - Istanbul: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/istanbul.md)\n", c.IstanbulBlock) if c.MuirGlacierBlock != nil { - banner += fmt.Sprintf(" - Muir Glacier: %-8v (ice age delay)\n", c.MuirGlacierBlock) + banner += fmt.Sprintf(" - Muir Glacier: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/muir-glacier.md)\n", c.MuirGlacierBlock) } - banner += fmt.Sprintf(" - Berlin: %-8v (typed transaction, access lists)\n", c.BerlinBlock) - banner += fmt.Sprintf(" - London: %-8v (fee burn, basefee)\n", c.LondonBlock) + banner += fmt.Sprintf(" - Berlin: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/berlin.md)\n", c.BerlinBlock) + banner += fmt.Sprintf(" - London: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/london.md)\n", c.LondonBlock) if c.ArrowGlacierBlock != nil { - banner += fmt.Sprintf(" - Arrow Glacier: %-8v (ice age delay)\n", c.ArrowGlacierBlock) + banner += fmt.Sprintf(" - Arrow Glacier: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/arrow-glacier.md)\n", c.ArrowGlacierBlock) } banner += "\n" // Add a special section for the merge as it's non-obvious if c.TerminalTotalDifficulty == nil { - banner += "Merge not configured!" + banner += "Merge not configured!\n" + banner += " - Hard-fork specification: https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/paris.md)" } else { banner += "Merge configured:\n" - banner += fmt.Sprintf(" - Total terminal difficulty: %v (proof-of-stake switchover threshold)\n", c.TerminalTotalDifficulty) - banner += fmt.Sprintf(" - Merge fork block: %-8v (network partitioning point)", c.MergeForkBlock) + banner += " - Hard-fork specification: https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/paris.md)\n" + banner += fmt.Sprintf(" - Total terminal difficulty: %v\n", c.TerminalTotalDifficulty) + banner += fmt.Sprintf(" - Merge netsplit block: %-8v", c.MergeNetsplitBlock) } return banner } @@ -567,7 +569,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error { {name: "berlinBlock", block: c.BerlinBlock}, {name: "londonBlock", block: c.LondonBlock}, {name: "arrowGlacierBlock", block: c.ArrowGlacierBlock, optional: true}, - {name: "mergeStartBlock", block: c.MergeForkBlock, optional: true}, + {name: "mergeNetwplitBlock", block: c.MergeNetsplitBlock, optional: true}, } { if lastFork.name != "" { // Next one must be higher number @@ -640,8 +642,8 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi if isForkIncompatible(c.ArrowGlacierBlock, newcfg.ArrowGlacierBlock, head) { return newCompatError("Arrow Glacier fork block", c.ArrowGlacierBlock, newcfg.ArrowGlacierBlock) } - if isForkIncompatible(c.MergeForkBlock, newcfg.MergeForkBlock, head) { - return newCompatError("Merge Start fork block", c.MergeForkBlock, newcfg.MergeForkBlock) + if isForkIncompatible(c.MergeNetsplitBlock, newcfg.MergeNetsplitBlock, head) { + return newCompatError("Merge netsplit fork block", c.MergeNetsplitBlock, newcfg.MergeNetsplitBlock) } return nil } diff --git a/tests/init.go b/tests/init.go index 52277e841642..acf3790bf7ce 100644 --- a/tests/init.go +++ b/tests/init.go @@ -211,7 +211,7 @@ var Forks = map[string]*params.ChainConfig{ BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), ArrowGlacierBlock: big.NewInt(0), - MergeForkBlock: big.NewInt(0), + MergeNetsplitBlock: big.NewInt(0), TerminalTotalDifficulty: big.NewInt(0), }, } From 217c93a3d3a3ffaabefa0f576848d7c18f3252e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Fri, 20 May 2022 14:30:02 +0300 Subject: [PATCH 3/5] params: oops --- params/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/params/config.go b/params/config.go index 019867bb7c67..5a0600576b59 100644 --- a/params/config.go +++ b/params/config.go @@ -569,7 +569,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error { {name: "berlinBlock", block: c.BerlinBlock}, {name: "londonBlock", block: c.LondonBlock}, {name: "arrowGlacierBlock", block: c.ArrowGlacierBlock, optional: true}, - {name: "mergeNetwplitBlock", block: c.MergeNetsplitBlock, optional: true}, + {name: "mergeNetsplitBlock", block: c.MergeNetsplitBlock, optional: true}, } { if lastFork.name != "" { // Next one must be higher number From 48c1da3712b361f93d1a69117c254a93c6d8cbd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Fri, 20 May 2022 14:37:33 +0300 Subject: [PATCH 4/5] eth, les: make banner separators proper length --- eth/backend.go | 4 ++-- les/client.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/eth/backend.go b/eth/backend.go index fc0a8b587c2f..b7b670c9dbf5 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -142,11 +142,11 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { return nil, genesisErr } log.Info("") - log.Info("---------------------------------------------------------------------------------------------") + log.Info(strings.Repeat("-", 153)) for _, line := range strings.Split(chainConfig.String(), "\n") { log.Info(line) } - log.Info("---------------------------------------------------------------------------------------------") + log.Info(strings.Repeat("-", 153)) log.Info("") if err := pruner.RecoverPruning(stack.ResolvePath(""), chainDb, stack.ResolvePath(config.TrieCleanCacheJournal)); err != nil { diff --git a/les/client.go b/les/client.go index ec2e1885ff66..df60d37f3489 100644 --- a/les/client.go +++ b/les/client.go @@ -98,11 +98,11 @@ func New(stack *node.Node, config *ethconfig.Config) (*LightEthereum, error) { return nil, genesisErr } log.Info("") - log.Info("---------------------------------------------------------------------------------------------") + log.Info(strings.Repeat("-", 153)) for _, line := range strings.Split(chainConfig.String(), "\n") { log.Info(line) } - log.Info("---------------------------------------------------------------------------------------------") + log.Info(strings.Repeat("-", 153)) log.Info("") peers := newServerPeerSet() From 8e0b8b3eefac69eb5f0d2ae4f68597af9fac9462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Fri, 20 May 2022 16:54:25 +0300 Subject: [PATCH 5/5] params: remove pointless sprintf calls --- params/config.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/params/config.go b/params/config.go index 5a0600576b59..335ef1a59af8 100644 --- a/params/config.go +++ b/params/config.go @@ -400,18 +400,18 @@ func (c *ChainConfig) String() string { switch { case c.Ethash != nil: if c.TerminalTotalDifficulty == nil { - banner += fmt.Sprintf("Consensus: Ethash (proof-of-work)\n") + banner += "Consensus: Ethash (proof-of-work)\n" } else { - banner += fmt.Sprintf("Consensus: Beacon (proof-of-stake), merged from Ethash (proof-of-work)\n") + banner += "Consensus: Beacon (proof-of-stake), merged from Ethash (proof-of-work)\n" } case c.Clique != nil: if c.TerminalTotalDifficulty == nil { - banner += fmt.Sprintf("Consensus: Clique (proof-of-authority)\n") + banner += "Consensus: Clique (proof-of-authority)\n" } else { - banner += fmt.Sprintf("Consensus: Beacon (proof-of-stake), merged from Clique (proof-of-authority)\n") + banner += "Consensus: Beacon (proof-of-stake), merged from Clique (proof-of-authority)\n" } default: - banner += fmt.Sprintf("Consensus: unknown\n") + banner += "Consensus: unknown\n" } banner += "\n"