From 5340ce712cd6cc189e9b44c7a8939834b8727c38 Mon Sep 17 00:00:00 2001 From: Wanwiset Peerapatanapokin Date: Thu, 5 Feb 2026 18:59:00 +0700 Subject: [PATCH] all: make nodes publish coinbase address to stats server (#1967) * allow customizable stats server parameters * pass coinbase address to stats server --- cicd/local/start.sh | 26 +++++++++++++++++++++++--- cicd/mainnet/start.sh | 27 +++++++++++++++++++++++---- cicd/testnet/start.sh | 28 ++++++++++++++++++++++++---- ethstats/ethstats.go | 40 +++++++++++++++++++++++++++------------- 4 files changed, 97 insertions(+), 24 deletions(-) diff --git a/cicd/local/start.sh b/cicd/local/start.sh index 18fa4c6ebc..8be3f5bca5 100755 --- a/cicd/local/start.sh +++ b/cicd/local/start.sh @@ -73,7 +73,7 @@ fi sync_mode=full if test -z "$SYNC_MODE" then - echo "SYNC_MODE not set, default to full" #full or fast + echo "SYNC_MODE not set, default to $sync_mode" #full or fast else echo "SYNC_MODE found, set to $SYNC_MODE" sync_mode=$SYNC_MODE @@ -82,14 +82,33 @@ fi gc_mode=archive if test -z "$GC_MODE" then - echo "GC_MODE not set, default to archive" #full or archive + echo "GC_MODE not set, default to $gc_mode" #full or archive else echo "GC_MODE found, set to $GC_MODE" gc_mode=$GC_MODE fi +ethstats_address=localhost:2000 +if test -z "$STATS_ADDRESS" +then + echo "STATS_ADDRESS not set, default to $ethstats_address" +else + echo "STATS_ADDRESS found, set to $STATS_ADDRESS" + ethstats_address=$STATS_ADDRESS +fi -echo "Running a node with wallet: ${wallet} at IP: ${instance_ip}" +ethstats_secret=xinfin_xdpos_hybrid_local_stats +if test -z "$STATS_SECRET" +then + echo "STATS_SECRET not set, default to $ethstats_secret" +else + echo "STATS_SECRET found, set to $STATS_SECRET" + ethstats_secret=$STATS_SECRET +fi + +netstats="${NODE_NAME}-${wallet}:$ethstats_secret@$ethstats_address" + +echo "Running a node with wallet: ${wallet}" echo "Starting nodes with $bootnodes ..." # Note: --gcmode=archive means node will store all historical data. This will lead to high memory usage. But sync mode require archive to sync @@ -97,6 +116,7 @@ echo "Starting nodes with $bootnodes ..." XDC \ --gcmode ${gc_mode} --syncmode ${sync_mode} \ +--ethstats ${netstats} \ --nat extip:${instance_ip} \ --bootnodes ${bootnodes} \ --datadir /work/xdcchain \ diff --git a/cicd/mainnet/start.sh b/cicd/mainnet/start.sh index 101354b805..9b73842cd1 100755 --- a/cicd/mainnet/start.sh +++ b/cicd/mainnet/start.sh @@ -61,22 +61,41 @@ fi sync_mode=full if test -z "$SYNC_MODE"; then - echo "SYNC_MODE not set, default to full" #full or fast + echo "SYNC_MODE not set, default to $sync_mode" #full or fast else echo "SYNC_MODE found, set to $SYNC_MODE" sync_mode=$SYNC_MODE fi -gc_mode=archive +gc_mode=full if test -z "$GC_MODE"; then - echo "GC_MODE not set, default to archive" #full or archive + echo "GC_MODE not set, default to $gc_mode" #full or archive else echo "GC_MODE found, set to $GC_MODE" gc_mode=$GC_MODE fi +ethstats_address=stats.xinfin.network:3000 +if test -z "$STATS_ADDRESS" +then + echo "STATS_ADDRESS not set, default to $ethstats_address" +else + echo "STATS_ADDRESS found, set to $STATS_ADDRESS" + ethstats_address=$STATS_ADDRESS +fi + +ethstats_secret=xinfin_xdpos_hybrid_network_stats +if test -z "$STATS_SECRET" +then + echo "STATS_SECRET not set, default to $ethstats_secret" +else + echo "STATS_SECRET found, set to $STATS_SECRET" + ethstats_secret=$STATS_SECRET +fi + +netstats="${NODE_NAME}-${wallet}:$ethstats_secret@$ethstats_address" + INSTANCE_IP=$(curl https://checkip.amazonaws.com) -netstats="${NODE_NAME}-${wallet}-${INSTANCE_IP}:xinfin_xdpos_hybrid_network_stats@stats.xinfin.network:3000" echo "Running a node with wallet: ${wallet} at IP: ${INSTANCE_IP}" echo "Starting nodes with $bootnodes ..." diff --git a/cicd/testnet/start.sh b/cicd/testnet/start.sh index bb28b24a8e..cda4dc6c50 100755 --- a/cicd/testnet/start.sh +++ b/cicd/testnet/start.sh @@ -25,6 +25,7 @@ do bootnodes="${bootnodes},$line" fi done < "$input" + #check last line since it's not included in "read" command https://stackoverflow.com/questions/12916352/shell-script-read-missing-last-line if [ -z "${bootnodes}" ] then @@ -72,23 +73,42 @@ fi sync_mode=full if test -z "$SYNC_MODE" then - echo "SYNC_MODE not set, default to full" #full or fast + echo "SYNC_MODE not set, default to $sync_mode" #full or fast else echo "SYNC_MODE found, set to $SYNC_MODE" sync_mode=$SYNC_MODE fi -gc_mode=archive +gc_mode=full if test -z "$GC_MODE" then - echo "GC_MODE not set, default to archive" #full or archive + echo "GC_MODE not set, default to $gc_mode" #full or archive else echo "GC_MODE found, set to $GC_MODE" gc_mode=$GC_MODE fi +ethstats_address=stats.apothem.network:2000 +if test -z "$STATS_ADDRESS" +then + echo "STATS_ADDRESS not set, default to $ethstats_address" +else + echo "STATS_ADDRESS found, set to $STATS_ADDRESS" + ethstats_address=$STATS_ADDRESS +fi + +ethstats_secret=xdc_xinfin_apothem_network_stats +if test -z "$STATS_SECRET" +then + echo "STATS_SECRET not set, default to $ethstats_secret" +else + echo "STATS_SECRET found, set to $STATS_SECRET" + ethstats_secret=$STATS_SECRET +fi + +netstats="${NODE_NAME}-${wallet}:$ethstats_secret@$ethstats_address" + INSTANCE_IP=$(curl https://checkip.amazonaws.com) -netstats="${NODE_NAME}-${wallet}-${INSTANCE_IP}:xdc_xinfin_apothem_network_stats@stats.apothem.network:2000" echo "Running a node with wallet: ${wallet} at IP: ${INSTANCE_IP}" diff --git a/ethstats/ethstats.go b/ethstats/ethstats.go index 3b20d561c0..fdc4ab24be 100644 --- a/ethstats/ethstats.go +++ b/ethstats/ethstats.go @@ -30,6 +30,7 @@ import ( "sync" "time" + "github.com/XinFinOrg/XDPoSChain/accounts" "github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common/mclock" "github.com/XinFinOrg/XDPoSChain/consensus" @@ -78,6 +79,7 @@ type backend interface { Downloader() *downloader.Downloader Engine() consensus.Engine SuggestGasTipCap(ctx context.Context) (*big.Int, error) + AccountManager() *accounts.Manager } // fullNodeBackend encompasses the functionality necessary for a full node @@ -103,9 +105,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 + node string // Name of the node to display on the monitoring page + coinbase string // Coinbase address of the node + 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 @@ -195,14 +198,23 @@ func New(node *node.Node, backend backend, engine consensus.Engine, url string) 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], + coinbase: "", // will be set below + pass: parts[1], + host: parts[2], + pongCh: make(chan struct{}), + histCh: make(chan []uint64, 1), + } + + if am := backend.AccountManager(); am != nil { + accounts := am.Accounts() + if len(accounts) > 0 { + coinbase := accounts[0] + ethstats.coinbase = coinbase.String0x() + } } node.RegisterLifecycle(ethstats) @@ -480,6 +492,7 @@ func (s *Service) readLoop(conn *connWrapper) { type nodeInfo struct { Name string `json:"name"` Node string `json:"node"` + Coinbase string `json:"coinbase"` Port int `json:"port"` Network string `json:"net"` Protocol string `json:"protocol"` @@ -512,8 +525,9 @@ func (s *Service) login(conn *connWrapper) error { auth := &authMsg{ ID: s.node, Info: nodeInfo{ - Name: s.node, - Node: infos.Name, + Name: s.node, + Node: infos.Name, + Coinbase: s.coinbase, Port: infos.Ports.Listener, Network: network, Protocol: protocol,