From 306d295615f67130f86689f9a6dc8738fed3cf02 Mon Sep 17 00:00:00 2001 From: j-rafique Date: Wed, 24 Sep 2025 15:06:58 +0500 Subject: [PATCH 1/2] Enable Pprof --- supernode/cmd/start.go | 37 +++++++++++++++++++++++++++++++++++++ supernode/config/config.go | 7 +++++++ 2 files changed, 44 insertions(+) diff --git a/supernode/cmd/start.go b/supernode/cmd/start.go index befaf85d..c8914270 100644 --- a/supernode/cmd/start.go +++ b/supernode/cmd/start.go @@ -3,9 +3,12 @@ package cmd import ( "context" "fmt" + "net/http" + _ "net/http/pprof" "os" "os/signal" "path/filepath" + "strings" "syscall" "github.com/LumeraProtocol/supernode/v2/p2p" @@ -139,6 +142,40 @@ The supernode will connect to the Lumera network and begin participating in the return fmt.Errorf("failed to create gateway server: %w", err) } + // Start profiling server if enabled or on testnet + isTestnet := strings.Contains(strings.ToLower(appConfig.LumeraClientConfig.ChainID), "testnet") + shouldEnableProfiling := appConfig.ProfilingConfig.Enabled || isTestnet + + if shouldEnableProfiling { + bindAddr := appConfig.ProfilingConfig.BindAddress + if bindAddr == "" { + if isTestnet { + bindAddr = "0.0.0.0" // Allow external access on testnet + } else { + bindAddr = "127.0.0.1" // Default to localhost + } + } + port := appConfig.ProfilingConfig.Port + if port == 0 { + port = 6060 // Default pprof port + } + + profilingAddr := fmt.Sprintf("%s:%d", bindAddr, port) + + logtrace.Info(ctx, "Starting profiling server", logtrace.Fields{ + "address": profilingAddr, + "chain_id": appConfig.LumeraClientConfig.ChainID, + "is_testnet": isTestnet, + "auto_enabled": isTestnet && !appConfig.ProfilingConfig.Enabled, + }) + + go func() { + if err := http.ListenAndServe(profilingAddr, nil); err != nil { + logtrace.Error(ctx, "Profiling server error", logtrace.Fields{"error": err.Error()}) + } + }() + } + // Start the services go func() { if err := RunServices(ctx, grpcServer, cService, *p2pService, gatewayServer); err != nil { diff --git a/supernode/config/config.go b/supernode/config/config.go index e3910ac2..a09190ce 100644 --- a/supernode/config/config.go +++ b/supernode/config/config.go @@ -44,12 +44,19 @@ type LogConfig struct { Level string `yaml:"level"` } +type ProfilingConfig struct { + Enabled bool `yaml:"enabled"` + Port uint16 `yaml:"port"` + BindAddress string `yaml:"bind_address,omitempty"` +} + type Config struct { SupernodeConfig `yaml:"supernode"` KeyringConfig `yaml:"keyring"` P2PConfig `yaml:"p2p"` LumeraClientConfig `yaml:"lumera"` RaptorQConfig `yaml:"raptorq"` + ProfilingConfig `yaml:"profiling"` // Store base directory (not from YAML) BaseDir string `yaml:"-"` From bca91a118ad642a84414407d55cfd65d6988e3f7 Mon Sep 17 00:00:00 2001 From: j-rafique Date: Wed, 24 Sep 2025 15:17:05 +0500 Subject: [PATCH 2/2] Remove config --- supernode/cmd/start.go | 27 ++++++--------------------- supernode/config/config.go | 7 ------- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/supernode/cmd/start.go b/supernode/cmd/start.go index c8914270..31c19b2a 100644 --- a/supernode/cmd/start.go +++ b/supernode/cmd/start.go @@ -142,31 +142,16 @@ The supernode will connect to the Lumera network and begin participating in the return fmt.Errorf("failed to create gateway server: %w", err) } - // Start profiling server if enabled or on testnet + // Start profiling server on testnet only isTestnet := strings.Contains(strings.ToLower(appConfig.LumeraClientConfig.ChainID), "testnet") - shouldEnableProfiling := appConfig.ProfilingConfig.Enabled || isTestnet - - if shouldEnableProfiling { - bindAddr := appConfig.ProfilingConfig.BindAddress - if bindAddr == "" { - if isTestnet { - bindAddr = "0.0.0.0" // Allow external access on testnet - } else { - bindAddr = "127.0.0.1" // Default to localhost - } - } - port := appConfig.ProfilingConfig.Port - if port == 0 { - port = 6060 // Default pprof port - } - profilingAddr := fmt.Sprintf("%s:%d", bindAddr, port) + if isTestnet { + profilingAddr := "0.0.0.0:6060" logtrace.Info(ctx, "Starting profiling server", logtrace.Fields{ - "address": profilingAddr, - "chain_id": appConfig.LumeraClientConfig.ChainID, - "is_testnet": isTestnet, - "auto_enabled": isTestnet && !appConfig.ProfilingConfig.Enabled, + "address": profilingAddr, + "chain_id": appConfig.LumeraClientConfig.ChainID, + "is_testnet": isTestnet, }) go func() { diff --git a/supernode/config/config.go b/supernode/config/config.go index a09190ce..e3910ac2 100644 --- a/supernode/config/config.go +++ b/supernode/config/config.go @@ -44,19 +44,12 @@ type LogConfig struct { Level string `yaml:"level"` } -type ProfilingConfig struct { - Enabled bool `yaml:"enabled"` - Port uint16 `yaml:"port"` - BindAddress string `yaml:"bind_address,omitempty"` -} - type Config struct { SupernodeConfig `yaml:"supernode"` KeyringConfig `yaml:"keyring"` P2PConfig `yaml:"p2p"` LumeraClientConfig `yaml:"lumera"` RaptorQConfig `yaml:"raptorq"` - ProfilingConfig `yaml:"profiling"` // Store base directory (not from YAML) BaseDir string `yaml:"-"`