Skip to content

Commit

Permalink
eth, les, params: log chain config a bit saner (ethereum#24904)
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe authored and jagdeep sidhu committed Jun 13, 2022
1 parent a8fd220 commit bd62fb8
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/forkid/forkid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"math/big"
"runtime"
"strings"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -157,7 +158,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(strings.Repeat("-", 153))
for _, line := range strings.Split(chainConfig.String(), "\n") {
log.Info(line)
}
log.Info(strings.Repeat("-", 153))
log.Info("")

if err := pruner.RecoverPruning(stack.ResolvePath(""), chainDb, stack.ResolvePath(config.TrieCleanCacheJournal)); err != nil {
log.Error("Failed to recover state", "error", err)
Expand Down
9 changes: 8 additions & 1 deletion les/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"sync"
"strings"
"time"

"github.com/ethereum/go-ethereum/accounts"
Expand Down Expand Up @@ -115,7 +116,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(strings.Repeat("-", 153))
for _, line := range strings.Split(chainConfig.String(), "\n") {
log.Info(line)
}
log.Info(strings.Repeat("-", 153))
log.Info("")

peers := newServerPeerSet()
merger := consensus.NewMerger(chainDb)
Expand Down
41 changes: 34 additions & 7 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,17 @@ 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",
SyscoinChainConfig.ChainID.String(): "syscoin",
TanenbaumChainConfig.ChainID.String(): "tanenbaum",
}

// 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
Expand Down Expand Up @@ -394,7 +405,7 @@ type ChainConfig struct {
SyscoinBlock *big.Int `json:"syscoinBlock,omitempty"` // Syscoin switch block (nil = no fork, 0 = already on syscoin)
LondonBlock *big.Int `json:"londonBlock,omitempty"` // London switch block (nil = no fork, 1 = 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.
Expand Down Expand Up @@ -427,11 +438,27 @@ 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 += "Consensus: Ethash (proof-of-work)\n"
} else {
banner += "Consensus: Beacon (proof-of-stake), merged from Ethash (proof-of-work)\n"
}
case c.Clique != nil:
engine = c.Clique
if c.TerminalTotalDifficulty == nil {
banner += "Consensus: Clique (proof-of-authority)\n"
} else {
banner += "Consensus: Beacon (proof-of-stake), merged from Clique (proof-of-authority)\n"
}
default:
engine = "unknown"
}
Expand All @@ -452,7 +479,7 @@ func (c *ChainConfig) String() string {
c.SyscoinBlock,
c.LondonBlock,
c.ArrowGlacierBlock,
c.MergeForkBlock,
c.MergeNetsplitBlock,
c.TerminalTotalDifficulty,
engine,
)
Expand Down Expand Up @@ -579,7 +606,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: "mergeNetsplitBlock", block: c.MergeNetsplitBlock, optional: true},
} {
if lastFork.name != "" {
// Next one must be higher number
Expand Down Expand Up @@ -652,8 +679,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
}
Expand Down
2 changes: 1 addition & 1 deletion tests/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
}
Expand Down

0 comments on commit bd62fb8

Please sign in to comment.