Hashrate support for --pool mode

This commit is contained in:
8lecramm 2023-03-27 23:13:50 +02:00 committed by GitHub
parent 735376ef60
commit 698736108e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 74 deletions

View File

@ -7,7 +7,6 @@ import (
"net" "net"
"strconv" "strconv"
"strings" "strings"
"sync"
"time" "time"
"github.com/deroproject/derohe/globals" "github.com/deroproject/derohe/globals"
@ -16,7 +15,6 @@ import (
func main() { func main() {
var err error var err error
var rwmutex sync.RWMutex
config.Arguments, err = docopt.Parse(config.Command_line, nil, true, "pre-alpha", false) config.Arguments, err = docopt.Parse(config.Command_line, nil, true, "pre-alpha", false)
@ -111,38 +109,35 @@ func main() {
} else { } else {
go proxy.Start_client(proxy.Address + "." + config.Worker) go proxy.Start_client(proxy.Address + "." + config.Worker)
} }
//go proxy.SendUpdateToDaemon()
for { for {
time.Sleep(time.Second * time.Duration(config.Log_intervall)) time.Sleep(time.Second * time.Duration(config.Log_intervall))
miners := proxy.CountMiners()
hash_rate_string := "" hash_rate_string := ""
switch { if miners > 0 {
case proxy.Hashrate > 1000000000000: switch {
hash_rate_string = fmt.Sprintf("%.3f TH/s", float64(proxy.Hashrate)/1000000000000.0) case proxy.Hashrate > 1000000000000:
case proxy.Hashrate > 1000000000: hash_rate_string = fmt.Sprintf("%.3f TH/s", float64(proxy.Hashrate)/1000000000000.0)
hash_rate_string = fmt.Sprintf("%.3f GH/s", float64(proxy.Hashrate)/1000000000.0) case proxy.Hashrate > 1000000000:
case proxy.Hashrate > 1000000: hash_rate_string = fmt.Sprintf("%.3f GH/s", float64(proxy.Hashrate)/1000000000.0)
hash_rate_string = fmt.Sprintf("%.3f MH/s", float64(proxy.Hashrate)/1000000.0) case proxy.Hashrate > 1000000:
case proxy.Hashrate > 1000: hash_rate_string = fmt.Sprintf("%.3f MH/s", float64(proxy.Hashrate)/1000000.0)
hash_rate_string = fmt.Sprintf("%.3f KH/s", float64(proxy.Hashrate)/1000.0) case proxy.Hashrate > 1000:
case proxy.Hashrate > 0: hash_rate_string = fmt.Sprintf("%.3f KH/s", float64(proxy.Hashrate)/1000.0)
hash_rate_string = fmt.Sprintf("%d H/s", int(proxy.Hashrate)) case proxy.Hashrate > 0:
hash_rate_string = fmt.Sprintf("%d H/s", int(proxy.Hashrate))
}
} }
if !config.Pool_mode { if !config.Pool_mode {
fmt.Printf("%v %d miners connected, IB:%d MB:%d MBR:%d MBO:%d - MINING @ %s\n", time.Now().Format(time.Stamp), proxy.CountMiners(), proxy.Blocks, proxy.Minis, proxy.Rejected, proxy.Orphans, hash_rate_string) fmt.Printf("%v %d miners connected, IB:%d MB:%d MBR:%d MBO:%d\n", time.Now().Format(time.Stamp), miners, proxy.Blocks, proxy.Minis, proxy.Rejected, proxy.Orphans)
} else { } else {
fmt.Printf("%v %d miners connected, Pool stats: IB:%d MB:%d MBR:%d MBO:%d - MINING @ %s\n", time.Now().Format(time.Stamp), proxy.CountMiners(), proxy.Blocks, proxy.Minis, proxy.Rejected, proxy.Orphans, hash_rate_string) fmt.Printf("%v %d miners connected, Pool stats: IB:%d MB:%d MBR:%d MBO:%d\n", time.Now().Format(time.Stamp), miners, proxy.Blocks, proxy.Minis, proxy.Rejected, proxy.Orphans)
fmt.Printf("%v Shares submitted: %d\n", time.Now().Format(time.Stamp), proxy.Shares) fmt.Printf("%v Shares submitted: %d, Hashrate: %s\n", time.Now().Format(time.Stamp), proxy.Shares, hash_rate_string)
} }
rwmutex.RLock() proxy.CountWallets()
for i := range proxy.Wallet_count {
if proxy.Wallet_count[i] > 1 {
fmt.Printf("%v Wallet %v, %d miners\n", time.Now().Format(time.Stamp), i, proxy.Wallet_count[i])
}
}
rwmutex.RUnlock()
} }
} }

View File

@ -49,9 +49,10 @@ var Blocks uint64
var Minis uint64 var Minis uint64
var Rejected uint64 var Rejected uint64
var Orphans uint64 var Orphans uint64
var ModdedNode bool = false
var noRepeat bool var Hashrate uint64
var Hashrate float64 var Connected int64
var difficulty uint64
// proxy-client // proxy-client
func Start_client(w string) { func Start_client(w string) {
@ -103,17 +104,9 @@ func Start_client(w string) {
Rejected = params.Rejected Rejected = params.Rejected
Orphans = params.Orphans Orphans = params.Orphans
if ModdedNode != params.Hansen33Mod { if config.Pool_mode {
if params.Hansen33Mod { difficulty = params.Difficultyuint64
fmt.Printf("%v Hansen33 Mod Mining Node Detected - Happy Mining\n", time.Now().Format(time.Stamp))
}
} else {
if !noRepeat {
noRepeat = true
fmt.Printf("%v Official Mining Node Detected - Happy Mining\n", time.Now().Format(time.Stamp))
}
} }
ModdedNode = params.Hansen33Mod
if config.Minimal { if config.Minimal {
if params.Height != last_height || params.Difficultyuint64 != last_diff { if params.Height != last_height || params.Difficultyuint64 != last_diff {
@ -128,23 +121,6 @@ func Start_client(w string) {
} }
} }
func SendUpdateToDaemon() {
var count = 0
for {
if ModdedNode {
if count == 0 {
time.Sleep(60 * time.Second)
}
connection.conn.WriteJSON(MinerInfo_Params{Wallet_Address: Address, Miner_Tag: "", Miner_Hashrate: Hashrate})
count++
}
time.Sleep(10 * time.Second)
}
}
func SendToDaemon(buffer []byte) { func SendToDaemon(buffer []byte) {
connection.Lock() connection.Lock()
defer connection.Unlock() defer connection.Unlock()

View File

@ -60,9 +60,12 @@ var client_list = map[*websocket.Conn]*user_session{}
var miners_count int var miners_count int
var Shares uint64 var Shares uint64
var shareValue uint64
var Wallet_count map[string]uint var Wallet_count map[string]uint
var Address string var Address string
var rwmutex sync.RWMutex
func Start_server() { func Start_server() {
var err error var err error
@ -198,6 +201,10 @@ func onWebsocket(w http.ResponseWriter, r *http.Request) {
fmt.Printf("%v Incoming connection: %v (%v), Wallet: %v\n", time.Now().Format(time.Stamp), wsConn.RemoteAddr().String(), worker, address) fmt.Printf("%v Incoming connection: %v (%v), Wallet: %v\n", time.Now().Format(time.Stamp), wsConn.RemoteAddr().String(), worker, address)
} else { } else {
fmt.Printf("%v Incoming connection: %v (%v)\n", time.Now().Format(time.Stamp), wsConn.RemoteAddr().String(), worker) fmt.Printf("%v Incoming connection: %v (%v)\n", time.Now().Format(time.Stamp), wsConn.RemoteAddr().String(), worker)
if len(client_list) == 1 {
Connected = time.Now().UnixMilli()
shareValue = 0
}
} }
} }
@ -214,31 +221,15 @@ func newUpgrader() *websocket.Upgrader {
client_list_mutex.Lock() client_list_mutex.Lock()
defer client_list_mutex.Unlock() defer client_list_mutex.Unlock()
/*
var x MinerInfo_Params
if json.Unmarshal(data, &x); len(x.Wallet_Address) > 0 {
if x.Miner_Hashrate > 0 {
sess := client_list[c]
sess.hashrate = x.Miner_Hashrate
client_list[c] = sess
}
var NewHashRate float64
for _, s := range client_list {
NewHashRate += s.hashrate
}
Hashrate = NewHashRate
// Update miners information
return
} else {
*/
SendToDaemon(data) SendToDaemon(data)
if !config.Pool_mode { if !config.Pool_mode {
fmt.Printf("%v Submitting result from miner: %v (%v), Wallet: %v\n", time.Now().Format(time.Stamp), c.RemoteAddr().String(), client_list[c].worker, client_list[c].address.String()) fmt.Printf("%v Submitting result from miner: %v (%v), Wallet: %v\n", time.Now().Format(time.Stamp), c.RemoteAddr().String(), client_list[c].worker, client_list[c].address.String())
} else { } else {
Shares++ Shares++
shareValue += difficulty
if Connected > 0 {
Hashrate = shareValue / (uint64(time.Now().UnixMilli()-Connected) / 1000)
}
} }
//} //}
}) })
@ -254,6 +245,18 @@ func newUpgrader() *websocket.Upgrader {
return u return u
} }
func CountWallets() {
rwmutex.RLock()
defer rwmutex.RUnlock()
for i := range Wallet_count {
if Wallet_count[i] > 1 {
fmt.Printf("%v Wallet %v, %d miners\n", time.Now().Format(time.Stamp), i, Wallet_count[i])
}
}
}
// taken unmodified from derohe repo // taken unmodified from derohe repo
// cert handling // cert handling
func generate_random_tls_cert() tls.Certificate { func generate_random_tls_cert() tls.Certificate {