From 25a85c54e7c8659e3510b91b993d5f0ff795a7fd Mon Sep 17 00:00:00 2001 From: galaio Date: Fri, 23 Aug 2024 15:48:21 +0800 Subject: [PATCH 1/6] metrics: add some extra feature flags in node info; --- cmd/geth/config.go | 2 +- cmd/utils/flags.go | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 5c829a2f76..6e412f1d11 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -246,7 +246,7 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { utils.SetupMetrics(ctx, utils.EnableBuildInfo(git.Commit, git.Date), utils.EnableMinerInfo(ctx, &cfg.Eth.Miner), - utils.EnableNodeInfo(&cfg.Eth.TxPool, stack.Server().NodeInfo()), + utils.EnableNodeInfo(ctx, &cfg.Eth, stack), ) return stack, backend } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 049908857f..4bd00dd711 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -2279,7 +2279,9 @@ func RegisterFilterAPI(stack *node.Node, backend ethapi.Backend, ethcfg *ethconf return filterSystem } -func EnableNodeInfo(poolConfig *legacypool.Config, nodeInfo *p2p.NodeInfo) SetupMetricsOption { +func EnableNodeInfo(ctx *cli.Context, cfg *ethconfig.Config, stack *node.Node) SetupMetricsOption { + poolConfig := cfg.TxPool + nodeInfo := stack.Server().NodeInfo() return func() { // register node info into metrics metrics.NewRegisteredLabel("node-info", nil).Mark(map[string]interface{}{ @@ -2293,6 +2295,11 @@ func EnableNodeInfo(poolConfig *legacypool.Config, nodeInfo *p2p.NodeInfo) Setup "AccountQueue": poolConfig.AccountQueue, "GlobalQueue": poolConfig.GlobalQueue, "Lifetime": poolConfig.Lifetime, + "Miner": ctx.Bool(MiningEnabledFlag.Name), + "Mev": cfg.Miner.Mev.Enabled, + "FFVoter": cfg.Miner.VoteEnable, + "PBSS": cfg.StateScheme == rawdb.PathScheme, + "MultiDB": stack.CheckIfMultiDataBase(), }) } } From 75f566e2e79f97aabdd71a02f2d21f679a0ffc5c Mon Sep 17 00:00:00 2001 From: galaio Date: Tue, 27 Aug 2024 21:13:54 +0800 Subject: [PATCH 2/6] metrics: add insert block time diff metric; --- core/blockchain.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/blockchain.go b/core/blockchain.go index c50520b203..b2a56d74bf 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -100,6 +100,8 @@ var ( blockReorgAddMeter = metrics.NewRegisteredMeter("chain/reorg/add", nil) blockReorgDropMeter = metrics.NewRegisteredMeter("chain/reorg/drop", nil) + blockRecvTimeDiffGauge = metrics.NewRegisteredGauge("chain/block/recvtimediff", nil) + errStateRootVerificationFailed = errors.New("state root verification failed") errInsertionInterrupted = errors.New("insertion is interrupted") errChainStopped = errors.New("blockchain is stopped") @@ -2055,6 +2057,9 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) return 0, nil } + if len(chain) > 0 { + blockRecvTimeDiffGauge.Update(time.Now().Unix() - int64(chain[0].Time())) + } // Start a parallel signature recovery (signer will fluke on fork transition, minimal perf loss) signer := types.MakeSigner(bc.chainConfig, chain[0].Number(), chain[0].Time()) go SenderCacher.RecoverFromBlocks(signer, chain) From ed3bea9e0c3dacd6f61cd3572a563cad542e6ae4 Mon Sep 17 00:00:00 2001 From: galaio Date: Tue, 27 Aug 2024 22:13:33 +0800 Subject: [PATCH 3/6] metrics: add insert block time diff metric; --- cmd/geth/config.go | 3 ++- cmd/utils/flags.go | 66 ++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 60 insertions(+), 9 deletions(-) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 6e412f1d11..a7e09a8d1a 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -246,7 +246,8 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { utils.SetupMetrics(ctx, utils.EnableBuildInfo(git.Commit, git.Date), utils.EnableMinerInfo(ctx, &cfg.Eth.Miner), - utils.EnableNodeInfo(ctx, &cfg.Eth, stack), + utils.EnableNodeInfo(&cfg.Eth.TxPool, stack.Server().NodeInfo()), + utils.EnableNodeTrack(ctx, &cfg.Eth, stack), ) return stack, backend } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 4bd00dd711..c324d87070 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -35,6 +35,8 @@ import ( "strings" "time" + "github.com/ethereum/go-ethereum/internal/version" + "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/common" @@ -2279,9 +2281,7 @@ func RegisterFilterAPI(stack *node.Node, backend ethapi.Backend, ethcfg *ethconf return filterSystem } -func EnableNodeInfo(ctx *cli.Context, cfg *ethconfig.Config, stack *node.Node) SetupMetricsOption { - poolConfig := cfg.TxPool - nodeInfo := stack.Server().NodeInfo() +func EnableNodeInfo(poolConfig *legacypool.Config, nodeInfo *p2p.NodeInfo) SetupMetricsOption { return func() { // register node info into metrics metrics.NewRegisteredLabel("node-info", nil).Mark(map[string]interface{}{ @@ -2295,15 +2295,65 @@ func EnableNodeInfo(ctx *cli.Context, cfg *ethconfig.Config, stack *node.Node) S "AccountQueue": poolConfig.AccountQueue, "GlobalQueue": poolConfig.GlobalQueue, "Lifetime": poolConfig.Lifetime, - "Miner": ctx.Bool(MiningEnabledFlag.Name), - "Mev": cfg.Miner.Mev.Enabled, - "FFVoter": cfg.Miner.VoteEnable, - "PBSS": cfg.StateScheme == rawdb.PathScheme, - "MultiDB": stack.CheckIfMultiDataBase(), }) } } +func EnableNodeTrack(ctx *cli.Context, cfg *ethconfig.Config, stack *node.Node) SetupMetricsOption { + nodeInfo := stack.Server().NodeInfo() + return func() { + // register node info into metrics + metrics.NewRegisteredLabel("node-track", nil).Mark(map[string]interface{}{ + "NodeType": parseNodeType(), + "ENR": nodeInfo.ENR, + "ID": nodeInfo.ID, + "Mining": ctx.Bool(MiningEnabledFlag.Name), + "Etherbase": cfg.Miner.Etherbase, + "MiningFeatures": parseMiningFeatures(ctx, cfg), + "DBFeatures": parseDBFeatures(cfg, stack), + }) + } +} + +func parseNodeType() string { + git, _ := version.VCS() + version := []string{params.VersionWithMeta} + if git.Commit != "" { + version = append(version, git.Commit) + } + if git.Date != "" { + version = append(version, git.Date) + } + arch := []string{runtime.GOOS, runtime.GOARCH} + infos := []string{"BSC", strings.Join(version, "-"), strings.Join(arch, "-"), runtime.Version()} + return strings.Join(infos, "/") +} + +func parseDBFeatures(cfg *ethconfig.Config, stack *node.Node) string { + var features []string + if cfg.StateScheme == rawdb.PathScheme { + features = append(features, "PBSS") + } + if stack.CheckIfMultiDataBase() { + features = append(features, "MultiDB") + } + return strings.Join(features, "/") +} + +func parseMiningFeatures(ctx *cli.Context, cfg *ethconfig.Config) string { + if !ctx.Bool(MiningEnabledFlag.Name) { + return "" + } + var features []string + if cfg.Miner.Mev.Enabled { + features = append(features, "MEV") + } + if cfg.Miner.VoteEnable { + features = append(features, "FFVoting") + } + return strings.Join(features, "/") +} + func SetupMetrics(ctx *cli.Context, options ...SetupMetricsOption) { if metrics.Enabled { log.Info("Enabling metrics collection") From 28e7a2a230e20bc9815761e69b68a4e02966bf85 Mon Sep 17 00:00:00 2001 From: galaio Date: Tue, 27 Aug 2024 22:35:35 +0800 Subject: [PATCH 4/6] metrics: add insert block time diff metric; --- cmd/utils/flags.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index c324d87070..8daa929999 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -2306,20 +2306,26 @@ func EnableNodeTrack(ctx *cli.Context, cfg *ethconfig.Config, stack *node.Node) metrics.NewRegisteredLabel("node-track", nil).Mark(map[string]interface{}{ "NodeType": parseNodeType(), "ENR": nodeInfo.ENR, - "ID": nodeInfo.ID, "Mining": ctx.Bool(MiningEnabledFlag.Name), - "Etherbase": cfg.Miner.Etherbase, + "Etherbase": parseEtherbase(cfg), "MiningFeatures": parseMiningFeatures(ctx, cfg), "DBFeatures": parseDBFeatures(cfg, stack), }) } } +func parseEtherbase(cfg *ethconfig.Config) string { + if cfg.Miner.Etherbase == (common.Address{}) { + return "" + } + return cfg.Miner.Etherbase.String() +} + func parseNodeType() string { git, _ := version.VCS() version := []string{params.VersionWithMeta} - if git.Commit != "" { - version = append(version, git.Commit) + if len(git.Commit) >= 7 { + version = append(version, git.Commit[:7]) } if git.Date != "" { version = append(version, git.Date) From eafa4f5fc5baaf88ae745e7da3483c21eb2a4332 Mon Sep 17 00:00:00 2001 From: galaio Date: Wed, 28 Aug 2024 10:48:10 +0800 Subject: [PATCH 5/6] metrics: add insert block time diff metric; --- cmd/utils/flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 8daa929999..4542d97cef 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -2303,7 +2303,7 @@ func EnableNodeTrack(ctx *cli.Context, cfg *ethconfig.Config, stack *node.Node) nodeInfo := stack.Server().NodeInfo() return func() { // register node info into metrics - metrics.NewRegisteredLabel("node-track", nil).Mark(map[string]interface{}{ + metrics.NewRegisteredLabel("node-stats", nil).Mark(map[string]interface{}{ "NodeType": parseNodeType(), "ENR": nodeInfo.ENR, "Mining": ctx.Bool(MiningEnabledFlag.Name), From 5a1f245ee136d5c521ee57e4fc9b2af80cc64331 Mon Sep 17 00:00:00 2001 From: galaio Date: Wed, 28 Aug 2024 16:04:27 +0800 Subject: [PATCH 6/6] metrics: add insert block time diff metric; --- cmd/utils/flags.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 4542d97cef..1dbe0bf1e2 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -2343,7 +2343,7 @@ func parseDBFeatures(cfg *ethconfig.Config, stack *node.Node) string { if stack.CheckIfMultiDataBase() { features = append(features, "MultiDB") } - return strings.Join(features, "/") + return strings.Join(features, "|") } func parseMiningFeatures(ctx *cli.Context, cfg *ethconfig.Config) string { @@ -2357,7 +2357,7 @@ func parseMiningFeatures(ctx *cli.Context, cfg *ethconfig.Config) string { if cfg.Miner.VoteEnable { features = append(features, "FFVoting") } - return strings.Join(features, "/") + return strings.Join(features, "|") } func SetupMetrics(ctx *cli.Context, options ...SetupMetricsOption) {