Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Add metrics to Libp2p networking processes #116

Draft
wants to merge 70 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
a8fbeda
Bugfix: InternalToExternal tx estimate gas returns valid gas limit an…
jdowning100 Mar 5, 2024
d8b254b
Added base fee enforcement and sorting by fee to Qi txs
jdowning100 Mar 6, 2024
160d01f
bugfix: modify msg payload to include length prefix
wizeguyy Mar 6, 2024
7944225
Implement custom propagation hooks to prevent bad data from spreading
Djadih Mar 4, 2024
b2ce90d
Refactor getRunningSlices and getRunningRegions for clarity
Djadih Mar 8, 2024
5d242bd
No need to initialize peers in the peerdb
Djadih Mar 8, 2024
a8d21d7
Add mutex lock to peerDb counter
Djadih Mar 8, 2024
8fbfec8
Create new peerDb for each location
Djadih Mar 8, 2024
9cb62a8
Create getDoms helper method to add peers to all dom locations
Djadih Mar 8, 2024
3506c49
Rearchitect the PeerManager and DBs to support peer bucketing by topic
Djadih Mar 8, 2024
c654e99
Establish timeout for stale requests
Djadih Mar 11, 2024
729313c
Refactored ETX Set to be an ordered list, added header commitment, ET…
jdowning100 Mar 11, 2024
a618b69
Optimization: Store all ETXs, only store ETX hashes for each block
jdowning100 Mar 13, 2024
a3ef7dc
Create APIs for Qi and Quai rate by number+hash
Djadih Mar 13, 2024
4557106
add genesis utxos
alanorwick Mar 5, 2024
600fe05
Miscellaneous error handling and print fixes
Djadih Mar 12, 2024
7ef2113
Send result to resultCh for processing even when nil
Djadih Mar 12, 2024
78f3a1d
Correctly clean up old streams from the streamCache
Djadih Mar 12, 2024
2eda1d9
Parallelize message handling from main read loop
Djadih Mar 12, 2024
8b541ee
Bugfix: Worker should commit to EtxSetHash
jdowning100 Mar 15, 2024
3437f20
Maps are reference types
Djadih Mar 18, 2024
53b5891
Abstract peer manager as interface
Djadih Mar 18, 2024
a2f4583
Separate stream manager and peer manager
Djadih Mar 18, 2024
f8f2375
Protect threads
Djadih Mar 18, 2024
0d4e0af
FIX: request block by number
alejoacosta74 Mar 20, 2024
d98a2b9
FIX: handle request block by number
alejoacosta74 Mar 20, 2024
8d62981
Bugfix: Worker should still fill ETXs even if fill is false
jdowning100 Mar 18, 2024
0fa0bb4
Helper functions to enable location based caching
Djadih Mar 15, 2024
ee2a637
Rework caching layer to separate context based viewpoints
Djadih Mar 15, 2024
64d5be5
Implement Pprof
Djadih Mar 21, 2024
402dda4
bugfix: Not including mixhash in the SealHash generation
gameofpointers Mar 25, 2024
a611a9e
fix: carried pointer on delete utxo array
alanorwick Mar 23, 2024
0c953cc
Expose functions for WS and HTTP ports
Djadih Mar 27, 2024
5b0d0b3
Removed Encode/Decode RLP for header
gameofpointers Mar 1, 2024
b9ada0c
Added new fields to the header for dynamic expansion
gameofpointers Mar 19, 2024
785b8a2
Computing the UncledS and ParentSubDeltaS
gameofpointers Mar 19, 2024
8cab583
Computing the Efficiency score, Threshold Count and Expansion Number
gameofpointers Mar 19, 2024
d80a494
GasLimit update for new chains
gameofpointers Mar 18, 2024
b3bcd1a
Hierarchical expansion using Hierarchical coordinator
gameofpointers Mar 19, 2024
5ec95b7
Computing the prime terminus in the header
gameofpointers Mar 20, 2024
47ba3fa
Computing the EtxEligible slices, disallow etx to non eligible slices
gameofpointers Mar 20, 2024
2124916
Added a flag to start from a custom starting expansion number
gameofpointers Mar 21, 2024
4fa6eb5
bugfix: Have to store the body with evm and utxo root for uniqueness
gameofpointers Mar 22, 2024
6ba42b1
Updated the genesis hash after all the header changes
gameofpointers Mar 28, 2024
99b00d4
Remove the encode and decode rlp for block
gameofpointers Mar 23, 2024
4701419
Added interlink hashs to body and header
gameofpointers Mar 23, 2024
5263257
Prefix topic with prime genesis hash
wizeguyy Mar 20, 2024
8cb2d1d
cherrypick cicd from main
robertlincecum Mar 12, 2024
7a7b9a6
bugfix: Only set consensus backend once
wizeguyy Apr 3, 2024
98980ce
Renamed InternalTx to QuaiTx
jdowning100 Mar 13, 2024
fa9da0d
Removed InternalToExternalTx and replaced functionality with QuaiTx
jdowning100 Mar 14, 2024
ec361ae
QIP10: Txhash has location encoded in bytes 0 and 1
jdowning100 Mar 14, 2024
21a326e
Removed ValidateETXGasPriceAndTip as ETX no longer has GasPrice or Tip
jdowning100 Apr 2, 2024
be58c7d
Fix BlocksPerDay calc for development
Djadih Apr 2, 2024
389bf97
Genesis hash print mistamtch
Djadih Apr 2, 2024
3b365a1
Bugfix: addUtxoTx should only RLock mempool if necessary
jdowning100 Apr 4, 2024
9f0958b
Removing the Sync Target logic as the downloader process is completel…
gameofpointers Apr 5, 2024
4e61c2a
Introduction of the Work Object type to facilitate MMTX
kiltsonfire Mar 6, 2024
0030887
bugfix: Only send chain head feed in zone preventing the lock
gameofpointers Mar 26, 2024
1ce39f1
bugfix: Using etx eligible slices in prime terminus and removed the u…
gameofpointers Apr 11, 2024
35ab6f2
Added Quai coinbase tx and coinbase signature, removed accumulateRewards
jdowning100 Apr 2, 2024
0b41b63
Replace existing bootnodes
Djadih Apr 15, 2024
e797694
Deleted unused asm folder and files
kiltsonfire Apr 18, 2024
9e1b715
Update gitignore
Djadih Apr 15, 2024
6346ebe
Add Counter metric types and change registration process
Djadih Apr 18, 2024
ed5a392
Add metrics for blocks, headers, and transactions
Djadih Apr 18, 2024
fbbd45c
Add metrics for streams, peers
Djadih Apr 18, 2024
f2e0f63
Add metrics for requests/responses
Djadih Apr 18, 2024
fc701fc
Add TxPool metrics
Djadih Apr 18, 2024
28b4571
New Grafana to display all the new metrics
Djadih Apr 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Patch Release Branch Workflow
on:
pull_request:
types: [closed]
branches:
- 'v?[0-9]+.[0-9]+'
jobs:
call-common-workflow:
uses: dominant-strategies/quai-cicd/.github/workflows/deploy-sandbox-common.yml@main
with:
needs_build: true
build_command: "make go-quai"
needs_docker: false
include_chart: false
cloud_deploy: false
skip_deploy: true
update_version: false
secrets:
GH_PAT: ${{ secrets.GH_PAT }}
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY2 }}
GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }}
1 change: 1 addition & 0 deletions .github/workflows/cut-minor-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
include_chart: false
cloud_deploy: false
skip_deploy: true
update_version: true
secrets:
GH_PAT: ${{ secrets.GH_PAT }}
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY2 }}
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
cloud_deploy: false
skip_deploy: true
update_version: false

secrets:
GH_PAT: ${{ secrets.GH_PAT }}
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY2 }}
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/patch.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
name: Patch Release Branch Workflow
on:
pull_request:
types: [closed]
branches:
- 'v?[0-9]+.[0-9]+'
on: workflow_dispatch
jobs:
call-common-workflow:
uses: dominant-strategies/quai-cicd/.github/workflows/deploy-sandbox-common.yml@main
Expand All @@ -14,6 +10,7 @@ jobs:
include_chart: false
cloud_deploy: false
skip_deploy: true
update_version: true
secrets:
GH_PAT: ${{ secrets.GH_PAT }}
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY2 }}
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
build/bin/
nodelogs/
traces/
/data/
*/config.toml
*/private.key
.vscode/
.idea*
.idea*
*.env
*.sh
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ debug:
go-quai:
$(GORUN) build/ci.go build ./cmd/go-quai
@echo "Done building."
@echo "Run \"$(GOBIN)/go-quai\" to launch go-quai."
@echo "Run \"$(GOBIN)/go-quai\" to launch go-quai."
22 changes: 16 additions & 6 deletions cmd/go-quai/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,31 @@ func runStart(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

if viper.IsSet(utils.PprofFlag.Name) {
utils.EnablePprof()
}

// create a new p2p node
node, err := node.NewNode(ctx)
if err != nil {
log.Global.WithField("error", err).Fatal("error creating node")
}

logLevel := cmd.Flag(utils.LogLevelFlag.Name).Value.String()
// create instance of consensus backend
var nodeWG sync.WaitGroup
consensus, err := utils.StartQuaiBackend(ctx, node, logLevel, &nodeWG)

var startingExpansionNumber uint64
if viper.IsSet(utils.StartingExpansionNumberFlag.Name) {
startingExpansionNumber = viper.GetUint64(utils.StartingExpansionNumberFlag.Name)
}
// Start the hierarchical co-ordinator
var nodeWg sync.WaitGroup
hc := utils.NewHierarchicalCoordinator(node, logLevel, &nodeWg, startingExpansionNumber)
err = hc.StartHierarchicalCoordinator()
if err != nil {
log.Global.WithField("error", err).Fatal("error creating consensus backend")
log.Global.WithField("error", err).Fatal("error starting hierarchical coordinator")
}

// start the p2p node
node.SetConsensusBackend(consensus)
if err := node.Start(); err != nil {
log.Global.WithField("error", err).Fatal("error starting node")
}
Expand All @@ -106,7 +115,8 @@ func runStart(cmd *cobra.Command, args []string) error {
<-ch
log.Global.Warn("Received 'stop' signal, shutting down gracefully...")
cancel()
nodeWG.Wait()
// stop the hierarchical co-ordinator
hc.Stop()
if err := node.Stop(); err != nil {
panic(err)
}
Expand Down
108 changes: 38 additions & 70 deletions cmd/utils/cmd.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package utils

import (
"context"
"fmt"
"io"
"os"
"runtime"
"slices"
"strings"
"sync"

"github.com/spf13/viper"

"github.com/dominant-strategies/go-quai/common"
"github.com/dominant-strategies/go-quai/core/types"
"github.com/dominant-strategies/go-quai/internal/quaiapi"
"github.com/dominant-strategies/go-quai/log"
"github.com/dominant-strategies/go-quai/metrics_config"
Expand All @@ -21,87 +20,55 @@ import (
"github.com/dominant-strategies/go-quai/quai"
"github.com/dominant-strategies/go-quai/quai/quaiconfig"
"github.com/dominant-strategies/go-quai/quaistats"
"github.com/syndtr/goleveldb/leveldb"
)

// Create a new instance of the QuaiBackend consensus service
func StartQuaiBackend(ctx context.Context, p2p quai.NetworkingAPI, logLevel string, nodeWG *sync.WaitGroup) (*quai.QuaiBackend, error) {
quaiBackend, _ := quai.NewQuaiBackend()
startNode := func(logPath string, location common.Location, slicesRunning []common.Location) {
nodeWG.Add(1)
go func() {
defer nodeWG.Done()
logger := log.NewLogger(logPath, logLevel)
logger.Info("Starting Node at location", "location", location)
stack, apiBackend := makeFullNode(p2p, location, slicesRunning, logger)
quaiBackend.SetApiBackend(apiBackend, location)
StartNode(stack)
// Create a channel to signal when stack.Wait() is done
done := make(chan struct{})
go func() {
stack.Wait()
close(done)
}()

select {
case <-done:
logger.Info("Node stopped normally")
stack.Close()
return
case <-ctx.Done():
logger.Info("Context cancelled, shutting down node")
stack.Close()
return
}
}()
func OpenBackendDB() (*leveldb.DB, error) {
dataDir := viper.GetString(DataDirFlag.Name)
if _, err := os.Stat(dataDir); os.IsNotExist(err) {
err := os.MkdirAll(dataDir, 0755)
if err != nil {
log.Global.Errorf("error creating data directory: %s", err)
return nil, err
}
}
dbPath := dataDir + "quaibackend"

// Set the p2p backend inside the quaiBackend
quaiBackend.SetP2PApiBackend(p2p)

slicesRunning := getSlicesRunning()
regionsRunning := getRegionsRunning(slicesRunning)

// Start nodes in separate goroutines
startNode("nodelogs/prime.log", nil, slicesRunning)
for _, region := range regionsRunning {
nodelogsFileName := "nodelogs/region-" + fmt.Sprintf("%d", region) + ".log"
startNode(nodelogsFileName, common.Location{region}, slicesRunning)
}
for _, slice := range slicesRunning {
nodelogsFileName := "nodelogs/zone-" + fmt.Sprintf("%d", slice[0]) + "-" + fmt.Sprintf("%d", slice[1]) + ".log"
startNode(nodelogsFileName, slice, slicesRunning)
db, err := leveldb.OpenFile(dbPath, nil)
if err != nil {
return nil, err
}

return quaiBackend, nil
return db, err
}

// setSlicesRunning sets the slices running flag
func getSlicesRunning() []common.Location {
// GetRunningZones returns the slices that are processing state (which are only zones)
func GetRunningZones() []common.Location {
slices := strings.Split(viper.GetString(SlicesRunningFlag.Name), ",")

// Sanity checks
if slices[0] == "" {
Fatalf("no slices are specified")
}
if len(slices) > common.NumRegionsInPrime*common.NumZonesInRegion {
Fatalf("number of slices exceed the current ontology")
}
slicesRunning := []common.Location{}
runningSlices := []common.Location{}
for _, slice := range slices {
slicesRunning = append(slicesRunning, common.Location{slice[1] - 48, slice[3] - 48})
location := common.Location{slice[1] - 48, slice[3] - 48}
if location.Region() > common.MaxRegions || location.Zone() > common.MaxZones {
Fatalf("invalid slice: %s", location)
}
runningSlices = append(runningSlices, location)
}
return slicesRunning
return runningSlices
}

// getRegionsRunning returns the regions running
func getRegionsRunning(slicesRunning []common.Location) []byte {
regionsRunning := []byte{}
for _, slice := range slicesRunning {
if !slices.Contains(regionsRunning, slice[0]) {
regionsRunning = append(regionsRunning, slice[0])
func GetRunningRegions(runningSlices []common.Location) []byte {
runningRegions := []byte{}
for _, slice := range runningSlices {
if !slices.Contains(runningRegions, slice[0]) {
runningRegions = append(runningRegions, slice[0])
}
}
return regionsRunning
return runningRegions
}

func StartNode(stack *node.Node) {
Expand All @@ -112,7 +79,7 @@ func StartNode(stack *node.Node) {
}

// makeConfigNode loads quai configuration and creates a blank node instance.
func makeConfigNode(slicesRunning []common.Location, nodeLocation common.Location, logger *log.Logger) (*node.Node, quaiconfig.QuaiConfig) {
func makeConfigNode(slicesRunning []common.Location, nodeLocation common.Location, currentExpansionNumber uint8, logger *log.Logger) (*node.Node, quaiconfig.QuaiConfig) {
// Load defaults.
cfg := quaiconfig.QuaiConfig{
Quai: quaiconfig.Defaults,
Expand All @@ -130,7 +97,7 @@ func makeConfigNode(slicesRunning []common.Location, nodeLocation common.Locatio
if err != nil {
Fatalf("Failed to create the protocol stack: %v", err)
}
SetQuaiConfig(stack, &cfg.Quai, slicesRunning, nodeLocation, logger)
SetQuaiConfig(stack, &cfg.Quai, slicesRunning, nodeLocation, currentExpansionNumber, logger)

// TODO: Apply stats
if viper.IsSet(QuaiStatsURLFlag.Name) {
Expand All @@ -150,9 +117,10 @@ func defaultNodeConfig() node.Config {
}

// makeFullNode loads quai configuration and creates the Quai backend.
func makeFullNode(p2p quai.NetworkingAPI, nodeLocation common.Location, slicesRunning []common.Location, logger *log.Logger) (*node.Node, quaiapi.Backend) {
stack, cfg := makeConfigNode(slicesRunning, nodeLocation, logger)
backend, _ := RegisterQuaiService(stack, p2p, cfg.Quai, cfg.Node.NodeLocation.Context(), logger)
func makeFullNode(p2p quai.NetworkingAPI, nodeLocation common.Location, slicesRunning []common.Location, currentExpansionNumber uint8, genesisBlock *types.WorkObject, logger *log.Logger) (*node.Node, quaiapi.Backend) {
stack, cfg := makeConfigNode(slicesRunning, nodeLocation, currentExpansionNumber, logger)
startingExpansionNumber := viper.GetUint64(StartingExpansionNumberFlag.Name)
backend, _ := RegisterQuaiService(stack, p2p, cfg.Quai, cfg.Node.NodeLocation.Context(), currentExpansionNumber, startingExpansionNumber, genesisBlock, logger)
sendfullstats := viper.GetBool(SendFullStatsFlag.Name)
// Add the Quai Stats daemon if requested.
if cfg.Quaistats.URL != "" {
Expand All @@ -164,8 +132,8 @@ func makeFullNode(p2p quai.NetworkingAPI, nodeLocation common.Location, slicesRu
// RegisterQuaiService adds a Quai client to the stack.
// The second return value is the full node instance, which may be nil if the
// node is running as a light client.
func RegisterQuaiService(stack *node.Node, p2p quai.NetworkingAPI, cfg quaiconfig.Config, nodeCtx int, logger *log.Logger) (quaiapi.Backend, error) {
backend, err := quai.New(stack, p2p, &cfg, nodeCtx, logger)
func RegisterQuaiService(stack *node.Node, p2p quai.NetworkingAPI, cfg quaiconfig.Config, nodeCtx int, currentExpansionNumber uint8, startingExpansionNumber uint64, genesisBlock *types.WorkObject, logger *log.Logger) (quaiapi.Backend, error) {
backend, err := quai.New(stack, p2p, &cfg, nodeCtx, currentExpansionNumber, startingExpansionNumber, genesisBlock, logger)
if err != nil {
Fatalf("Failed to register the Quai service: %v", err)
}
Expand Down
Loading