From cb9d8e2560304647a6ef16fb26af600ee0c93b25 Mon Sep 17 00:00:00 2001 From: Kien Dang Date: Tue, 18 Jul 2023 14:55:16 +0700 Subject: [PATCH] ethstats: add coinbase to nodeInfo (#313) --- cmd/faucet/faucet.go | 2 +- cmd/ronin/config.go | 9 ++++++++- cmd/utils/flags.go | 4 ++-- ethstats/ethstats.go | 28 ++++++++++++++++------------ 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index 2d9d7a1e99..5ec4960080 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -260,7 +260,7 @@ func newFaucet(genesis *core.Genesis, port int, enodes []*enode.Node, network ui // Assemble the ethstats monitoring and reporting service' if stats != "" { - if err := ethstats.New(stack, lesBackend.ApiBackend, lesBackend.Engine(), stats); err != nil { + if err := ethstats.New(stack, lesBackend.ApiBackend, lesBackend.Engine(), stats, common.Address{}); err != nil { return nil, err } } diff --git a/cmd/ronin/config.go b/cmd/ronin/config.go index 9105fee103..8b0e524900 100644 --- a/cmd/ronin/config.go +++ b/cmd/ronin/config.go @@ -20,6 +20,7 @@ import ( "bufio" "errors" "fmt" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/rawdb" "math/big" "os" @@ -186,7 +187,13 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { } // Add the Ethereum Stats daemon if requested. if cfg.Ethstats.URL != "" { - utils.RegisterEthStatsService(stack, backend, cfg.Ethstats.URL) + coinbase, err := eth.Etherbase() + if err != nil { + log.Warn("Failed to get etherbase", "err", err) + utils.RegisterEthStatsService(stack, backend, cfg.Ethstats.URL, common.Address{}) + } else { + utils.RegisterEthStatsService(stack, backend, cfg.Ethstats.URL, coinbase) + } } return stack, backend } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 284dd78268..438a3c9678 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1832,8 +1832,8 @@ func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) (ethapi.Backend // RegisterEthStatsService configures the Ethereum Stats daemon and adds it to // the given node. -func RegisterEthStatsService(stack *node.Node, backend ethapi.Backend, url string) { - if err := ethstats.New(stack, backend, backend.Engine(), url); err != nil { +func RegisterEthStatsService(stack *node.Node, backend ethapi.Backend, url string, coinbase common.Address) { + if err := ethstats.New(stack, backend, backend.Engine(), url, coinbase); err != nil { Fatalf("Failed to register the Ethereum Stats service: %v", err) } } diff --git a/ethstats/ethstats.go b/ethstats/ethstats.go index 55c0c880f3..d56b053a8d 100644 --- a/ethstats/ethstats.go +++ b/ethstats/ethstats.go @@ -87,9 +87,10 @@ type Service struct { backend backend engine consensus.Engine // Consensus engine to retrieve variadic block fields - node string // Name of the node to display on the monitoring page - pass string // Password to authorize access to the monitoring page - host string // Remote address of the monitoring service + coinbase string + node string // Name of the node to display on the monitoring page + pass string // Password to authorize access to the monitoring page + host string // Remote address of the monitoring service pongCh chan struct{} // Pong notifications are fed into this channel histCh chan []uint64 // History request block numbers are fed into this channel @@ -168,20 +169,21 @@ func parseEthstatsURL(url string) (parts []string, err error) { } // New returns a monitoring service ready for stats reporting. -func New(node *node.Node, backend backend, engine consensus.Engine, url string) error { +func New(node *node.Node, backend backend, engine consensus.Engine, url string, coinbase common.Address) error { parts, err := parseEthstatsURL(url) if err != nil { return err } ethstats := &Service{ - backend: backend, - engine: engine, - server: node.Server(), - node: parts[0], - pass: parts[1], - host: parts[2], - pongCh: make(chan struct{}), - histCh: make(chan []uint64, 1), + backend: backend, + engine: engine, + server: node.Server(), + node: parts[0], + pass: parts[1], + host: parts[2], + pongCh: make(chan struct{}), + histCh: make(chan []uint64, 1), + coinbase: coinbase.Hex(), } node.RegisterLifecycle(ethstats) @@ -441,6 +443,7 @@ func (s *Service) readLoop(conn *connWrapper) { // nodeInfo is the collection of meta information about a node that is displayed // on the monitoring page. type nodeInfo struct { + Coinbase string `json:"coinbase"` Name string `json:"name"` Node string `json:"node"` Port int `json:"port"` @@ -478,6 +481,7 @@ func (s *Service) login(conn *connWrapper) error { auth := &authMsg{ ID: s.node, Info: nodeInfo{ + Coinbase: s.coinbase, Name: s.node, Node: infos.Name, Port: infos.Ports.Listener,