Skip to content

Commit

Permalink
ethstats: add coinbase to nodeInfo (axieinfinity#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
DNK90 authored and minh-bq committed Jul 27, 2023
1 parent 1b63ba2 commit cb9d8e2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmd/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
9 changes: 8 additions & 1 deletion cmd/ronin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bufio"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"math/big"
"os"
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
28 changes: 16 additions & 12 deletions ethstats/ethstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit cb9d8e2

Please sign in to comment.