Remove log usages from stratum server

This commit is contained in:
DataHoarder 2024-04-06 04:51:45 +02:00
parent d474745baf
commit faa9f504b6
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
2 changed files with 19 additions and 19 deletions

View file

@ -16,7 +16,6 @@ import (
"git.gammaspectra.live/P2Pool/consensus/v3/utils"
gojson "github.com/goccy/go-json"
fasthex "github.com/tmthrgd/go-hex"
"log"
"math"
unsafeRandom "math/rand/v2"
"net"
@ -679,7 +678,7 @@ func (s *Server) HandleMempoolData(data mempool.Mempool) {
if time.Now().Sub(s.lastMempoolRefresh) >= time.Second*10 {
s.lastMempoolRefresh = time.Now()
if err := s.fillNewTemplateData(types.ZeroDifficulty); err != nil {
log.Printf("[Stratum] Error building new template data: %s", err)
utils.Errorf("Stratum", "Error building new template data: %s", err)
return false
}
return true
@ -698,7 +697,7 @@ func (s *Server) HandleMinerData(minerData *p2pooltypes.MinerData) {
s.mempool = minerData.TxBacklog
s.lastMempoolRefresh = time.Now()
if err := s.fillNewTemplateData(types.ZeroDifficulty); err != nil {
log.Printf("[Stratum] Error building new template data: %s", err)
utils.Errorf("Stratum", "Error building new template data: %s", err)
return false
}
return true
@ -717,7 +716,7 @@ func (s *Server) HandleTip(tip *sidechain.PoolBlock) {
s.tip = tip
s.lastMempoolRefresh = time.Now()
if err := s.fillNewTemplateData(currentDifficulty); err != nil {
log.Printf("[Stratum] Error building new template data: %s", err)
utils.Errorf("Stratum", "Error building new template data: %s", err)
return false
}
return true
@ -734,7 +733,7 @@ func (s *Server) HandleBroadcast(block *sidechain.PoolBlock) {
if s.tip != nil && block != s.tip && block.Side.Height <= s.tip.Side.Height {
//probably a new block was added as alternate
if err := s.fillNewTemplateData(types.ZeroDifficulty); err != nil {
log.Printf("[Stratum] Error building new template data: %s", err)
utils.Errorf("Stratum", "Error building new template data: %s", err)
return false
}
return true
@ -754,10 +753,10 @@ func (s *Server) Update() {
defer s.clientsLock.RUnlock()
if len(s.clients) > 0 {
log.Printf("[Stratum] Sending new job to %d connection(s)", len(s.clients))
utils.Logf("Stratum", "Sending new job to %d connection(s)", len(s.clients))
for _, c := range s.clients {
if err := s.SendTemplate(c); err != nil {
log.Printf("[Stratum] Closing connection %s: %s", c.Conn.RemoteAddr().String(), err)
utils.Noticef("Stratum", "Closing connection %s: %s", c.Conn.RemoteAddr().String(), err)
closeClients = append(closeClients, c)
}
}
@ -821,7 +820,7 @@ func (s *Server) Ban(ip netip.Addr, duration time.Duration, err error) {
return
}
log.Printf("[Stratum] Banned %s for %s: %s", ip.String(), duration.String(), err.Error())
utils.Noticef("Stratum", "Banned %s for %s: %s", ip.String(), duration.String(), err.Error())
if !ip.IsLoopback() {
ip = ip.Unmap()
var prefix netip.Prefix
@ -904,13 +903,13 @@ func (s *Server) Listen(listen string) error {
}(); err != nil {
go func() {
defer conn.Close()
log.Printf("[Stratum] Connection from %s rejected (%s)", conn.RemoteAddr().String(), err.Error())
utils.Noticef("Stratum", "Connection from %s rejected (%s)", conn.RemoteAddr().String(), err.Error())
}()
continue
}
func() {
log.Printf("[Stratum] Incoming connection from %s", conn.RemoteAddr().String())
utils.Noticef("Stratum", "Incoming connection from %s", conn.RemoteAddr().String())
var rpcId uint32
for rpcId == 0 {
@ -935,15 +934,16 @@ func (s *Server) Listen(listen string) error {
defer s.CloseClient(client)
defer func() {
if err != nil {
log.Printf("[Stratum] Connection %s closed with error: %s", client.Conn.RemoteAddr().String(), err)
utils.Noticef("Stratum", "Connection %s closed with error: %s", client.Conn.RemoteAddr().String(), err)
} else {
log.Printf("[Stratum] Connection %s closed", client.Conn.RemoteAddr().String())
utils.Noticef("Stratum", "Connection %s closed", client.Conn.RemoteAddr().String())
}
}()
defer func() {
if e := recover(); e != nil {
err = errors.New("panic called")
log.Print(e)
if err = e.(error); err == nil {
err = fmt.Errorf("panic called: %v", e)
}
s.CloseClient(client)
}
}()
@ -997,7 +997,7 @@ func (s *Server) Listen(listen string) error {
return errors.New("algo rx/0 not found")
}
log.Printf("[Stratum] Connection %s address = %s, agent = \"%s\", pass = \"%s\"", client.Conn.RemoteAddr().String(), client.Address.ToAddress(addressNetwork).ToBase58(), client.Agent, client.Password)
utils.Debugf("Stratum", "Connection %s address = %s, agent = \"%s\", pass = \"%s\"", client.Conn.RemoteAddr().String(), client.Address.ToAddress(addressNetwork).ToBase58(), client.Agent, client.Password)
client.Login = true
return nil

View file

@ -67,18 +67,18 @@ func Logf(prefix, format string, v ...any) {
innerPrint(prefix, "INFO", fmt.Sprintf(format, v...))
}
func Noticef(format string, v ...any) {
func Noticef(prefix, format string, v ...any) {
if GlobalLogLevel&LogLevelNotice == 0 {
return
}
innerPrint("", "NOTICE", fmt.Sprintf(format, v...))
innerPrint(prefix, "NOTICE", fmt.Sprintf(format, v...))
}
func Debugf(format string, v ...any) {
func Debugf(prefix, format string, v ...any) {
if GlobalLogLevel&LogLevelDebug == 0 {
return
}
innerPrint("", "DEBUG", fmt.Sprintf(format, v...))
innerPrint(prefix, "DEBUG", fmt.Sprintf(format, v...))
}
func innerPrint(prefix, class, v string) {