Skip to content

Commit

Permalink
rename ethstats to quaistats
Browse files Browse the repository at this point in the history
  • Loading branch information
skeptrunedev authored and wizeguyy committed Jan 25, 2023
1 parent 8825d64 commit a1717fe
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ run:
- core/state_processor_test.go
- core/bench_test.go
- core/chain_makers_test.go
- ethstats/ethstats_test.go
- quaistats/quaistats_test.go
- tests/transaction_test.go
- tests/init_test.go
- tests/block_test.go
Expand Down
10 changes: 5 additions & 5 deletions cmd/go-quai/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ var tomlSettings = toml.Config{
},
}

type ethstatsConfig struct {
type quaistatsConfig struct {
URL string `toml:",omitempty"`
}

type quaiConfig struct {
Eth ethconfig.Config
Node node.Config
Ethstats ethstatsConfig
Ethstats quaistatsConfig
Metrics metrics.Config
}

Expand Down Expand Up @@ -135,8 +135,8 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, quaiConfig) {
utils.Fatalf("Failed to create the protocol stack: %v", err)
}
utils.SetEthConfig(ctx, stack, &cfg.Eth)
if ctx.GlobalIsSet(utils.EthStatsURLFlag.Name) {
cfg.Ethstats.URL = ctx.GlobalString(utils.EthStatsURLFlag.Name)
if ctx.GlobalIsSet(utils.QuaiStatsURLFlag.Name) {
cfg.Ethstats.URL = ctx.GlobalString(utils.QuaiStatsURLFlag.Name)
}
applyMetricConfig(ctx, &cfg)

Expand All @@ -153,7 +153,7 @@ func makeFullNode(ctx *cli.Context) (*node.Node, quaiapi.Backend) {

// Add the Ethereum Stats daemon if requested.
if cfg.Ethstats.URL != "" {
utils.RegisterEthStatsService(stack, backend, cfg.Ethstats.URL)
utils.RegisterQuaiStatsService(stack, backend, cfg.Ethstats.URL)
}
return stack, backend
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/go-quai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ var (
utils.CalaverasFlag,
utils.VMEnableDebugFlag,
utils.NetworkIdFlag,
utils.EthStatsURLFlag,
utils.QuaiStatsURLFlag,
utils.FakePoWFlag,
utils.NoCompactionFlag,
utils.GpoBlocksFlag,
Expand Down
2 changes: 1 addition & 1 deletion cmd/go-quai/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.ExitWhenSyncedFlag,
utils.GCModeFlag,
utils.TxLookupLimitFlag,
utils.EthStatsURLFlag,
utils.QuaiStatsURLFlag,
utils.IdentityFlag,
utils.LightKDFFlag,
utils.WhitelistFlag,
Expand Down
14 changes: 7 additions & 7 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import (
"github.com/dominant-strategies/go-quai/eth/ethconfig"
"github.com/dominant-strategies/go-quai/eth/gasprice"
"github.com/dominant-strategies/go-quai/ethdb"
"github.com/dominant-strategies/go-quai/ethstats"
"github.com/dominant-strategies/go-quai/internal/flags"
"github.com/dominant-strategies/go-quai/internal/quaiapi"
"github.com/dominant-strategies/go-quai/log"
Expand All @@ -59,6 +58,7 @@ import (
"github.com/dominant-strategies/go-quai/p2p/nat"
"github.com/dominant-strategies/go-quai/p2p/netutil"
"github.com/dominant-strategies/go-quai/params"
"github.com/dominant-strategies/go-quai/quaistats"
gopsutil "github.com/shirou/gopsutil/mem"
"gopkg.in/urfave/cli.v1"
)
Expand Down Expand Up @@ -413,9 +413,9 @@ var (
Value: ethconfig.Defaults.RPCTxFeeCap,
}
// Logging and debug settings
EthStatsURLFlag = cli.StringFlag{
Name: "ethstats",
Usage: "Reporting URL of a ethstats service (nodename:secret@host:port)",
QuaiStatsURLFlag = cli.StringFlag{
Name: "quaistats",
Usage: "Reporting URL of a quaistats service (nodename:secret@host:port)",
}
FakePoWFlag = cli.BoolFlag{
Name: "fakepow",
Expand Down Expand Up @@ -1488,10 +1488,10 @@ func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) (quaiapi.Backen
return backend.APIBackend, backend
}

// RegisterEthStatsService configures the Ethereum Stats daemon and adds it to
// RegisterQuaiStatsService configures the Ethereum Stats daemon and adds it to
// the given node.
func RegisterEthStatsService(stack *node.Node, backend quaiapi.Backend, url string) {
if err := ethstats.New(stack, backend, backend.Engine(), url); err != nil {
func RegisterQuaiStatsService(stack *node.Node, backend quaiapi.Backend, url string) {
if err := quaistats.New(stack, backend, backend.Engine(), url); err != nil {
Fatalf("Failed to register the Ethereum Stats service: %v", err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion quaiclient/ethclient/ethclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"testing"
"time"

"github.com/dominant-strategies/go-quai"
ethereum "github.com/dominant-strategies/go-quai"
"github.com/dominant-strategies/go-quai/common"
"github.com/dominant-strategies/go-quai/consensus/blake3pow"
"github.com/dominant-strategies/go-quai/core"
Expand Down
48 changes: 29 additions & 19 deletions ethstats/ethstats.go → quaistats/quaistats.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

// Package ethstats implements the network stats reporting service.
package ethstats
// Package quaistats implements the network stats reporting service.
package quaistats

import (
"context"
Expand Down Expand Up @@ -57,7 +57,7 @@ const (
chainHeadChanSize = 10
)

// backend encompasses the bare-minimum functionality needed for ethstats reporting
// backend encompasses the bare-minimum functionality needed for quaistats reporting
type backend interface {
SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription
Expand All @@ -69,7 +69,7 @@ type backend interface {
}

// fullNodeBackend encompasses the functionality necessary for a full node
// reporting to ethstats
// reporting to quaistats
type fullNodeBackend interface {
backend
Miner() *core.Miner
Expand Down Expand Up @@ -172,7 +172,7 @@ func New(node *node.Node, backend backend, engine consensus.Engine, url string)
if err != nil {
return err
}
ethstats := &Service{
quaistats := &Service{
backend: backend,
engine: engine,
server: node.Server(),
Expand All @@ -183,7 +183,7 @@ func New(node *node.Node, backend backend, engine consensus.Engine, url string)
histCh: make(chan []uint64, 1),
}

node.RegisterLifecycle(ethstats)
node.RegisterLifecycle(quaistats)
return nil
}

Expand Down Expand Up @@ -521,10 +521,14 @@ func (s *Service) report(conn *connWrapper) error {
return nil
}

type latencyReport struct {
Latency int `json:"latency"`
}

// reportLatency sends a ping request to the server, measures the RTT time and
// finally sends a latency update.
func (s *Service) reportLatency(conn *connWrapper) error {
// Send the current time to the ethstats server
// Send the current time to the quaistats server
start := time.Now()

ping := map[string][]interface{}{
Expand All @@ -544,18 +548,24 @@ func (s *Service) reportLatency(conn *connWrapper) error {
// Ping timeout, abort
return errors.New("ping timed out")
}
latency := strconv.Itoa(int((time.Since(start) / time.Duration(2)).Nanoseconds() / 1000000))

latency := int((time.Since(start) / time.Duration(2)).Nanoseconds() / 1000000)

// Send back the measured latency
log.Trace("Sending measured latency to ethstats", "latency", latency)
log.Trace("Sending measured latency to ethstats", "latency", strconv.Itoa(latency))

stats := map[string][]interface{}{
"emit": {"latency", map[string]string{
"id": s.node,
"latency": latency,
}},
latencyReport := map[string]interface{}{
"id": s.node,
"latency": &latencyReport{
Latency: latency,
},
}
return conn.WriteJSON(stats)

report := map[string][]interface{}{
"emit": {"latency", latencyReport},
}

return conn.WriteJSON(report)
}

// blockStats is the information to report about individual blocks.
Expand Down Expand Up @@ -597,7 +607,7 @@ func (s *Service) reportBlock(conn *connWrapper, block *types.Block) error {
details := s.assembleBlockStats(block)

// Assemble the block report and send it to the server
log.Trace("Sending new block to ethstats", "number", details.Number, "hash", details.Hash)
log.Trace("Sending new block to quaistats", "number", details.Number, "hash", details.Hash)

stats := map[string]interface{}{
"id": s.node,
Expand Down Expand Up @@ -708,7 +718,7 @@ func (s *Service) reportHistory(conn *connWrapper, list []uint64) error {
}
// Assemble the history report and send it to the server
if len(history) > 0 {
log.Trace("Sending historical blocks to ethstats", "first", history[0].Number, "last", history[len(history)-1].Number)
log.Trace("Sending historical blocks to quaistats", "first", history[0].Number, "last", history[len(history)-1].Number)
} else {
log.Trace("No history to send to stats server")
}
Expand All @@ -733,7 +743,7 @@ func (s *Service) reportPending(conn *connWrapper) error {
// Retrieve the pending count from the local blockchain
pending, _ := s.backend.Stats()
// Assemble the transaction stats and send it to the server
log.Trace("Sending pending transactions to ethstats", "count", pending)
log.Trace("Sending pending transactions to quaistats", "count", pending)

stats := map[string]interface{}{
"id": s.node,
Expand Down Expand Up @@ -787,7 +797,7 @@ func (s *Service) reportStats(conn *connWrapper) error {
syncing = s.backend.CurrentHeader().Number().Uint64() >= sync.HighestBlock
}
// Assemble the node stats and send it to the server
log.Trace("Sending node details to ethstats")
log.Trace("Sending node details to quaistats")

stats := map[string]interface{}{
"id": s.node,
Expand Down
2 changes: 1 addition & 1 deletion ethstats/ethstats_test.go → quaistats/quaistats_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ethstats
package quaistats

import (
"strconv"
Expand Down

0 comments on commit a1717fe

Please sign in to comment.