Send Hashrate to Hansen33 Nodes

This commit is contained in:
Hansen33 2022-07-19 20:44:13 +01:00
parent c145528213
commit 0f62767fd4
4 changed files with 93 additions and 6 deletions

View File

@ -70,6 +70,7 @@ func main() {
time.Sleep(time.Second * 1) time.Sleep(time.Second * 1)
} }
go proxy.Start_client(daemon_address, proxy.Address, minimal, nonce) go proxy.Start_client(daemon_address, proxy.Address, minimal, nonce)
go proxy.SendUpdateToDaemon()
for { for {
time.Sleep(time.Second * time.Duration(log_intervall)) time.Sleep(time.Second * time.Duration(log_intervall))

View File

@ -8,14 +8,41 @@ import (
"net/url" "net/url"
"time" "time"
"github.com/deroproject/derohe/rpc"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
) )
type (
GetBlockTemplate_Params struct {
Wallet_Address string `json:"wallet_address"`
Block bool `json:"block"`
Miner string `json:"miner"`
}
GetBlockTemplate_Result struct {
JobID string `json:"jobid"`
Blocktemplate_blob string `json:"blocktemplate_blob,omitempty"`
Blockhashing_blob string `json:"blockhashing_blob,omitempty"`
Difficulty string `json:"difficulty"`
Difficultyuint64 uint64 `json:"difficultyuint64"`
Height uint64 `json:"height"`
Prev_Hash string `json:"prev_hash"`
EpochMilli uint64 `json:"epochmilli"`
Blocks uint64 `json:"blocks"` // number of blocks found
MiniBlocks uint64 `json:"miniblocks"` // number of miniblocks found
Rejected uint64 `json:"rejected"` // reject count
LastError string `json:"lasterror"` // last error
Status string `json:"status"`
Orphans uint64 `json:"orphans"`
Hansen33Mod bool `json:"hansen33_mod"`
}
)
var connection *websocket.Conn var connection *websocket.Conn
var Blocks uint64 var Blocks uint64
var Minis uint64 var Minis uint64
var Rejected uint64 var Rejected uint64
var Orphans uint64
var ModdedNode bool = false
var Hashrate float64
// proxy-client // proxy-client
func Start_client(v string, w string, min_jobs bool, nonce bool) { func Start_client(v string, w string, min_jobs bool, nonce bool) {
@ -42,7 +69,7 @@ func Start_client(v string, w string, min_jobs bool, nonce bool) {
continue continue
} }
var params rpc.GetBlockTemplate_Result var params GetBlockTemplate_Result
for { for {
msg_type, recv_data, err := connection.ReadMessage() msg_type, recv_data, err := connection.ReadMessage()
@ -61,7 +88,18 @@ func Start_client(v string, w string, min_jobs bool, nonce bool) {
Blocks = params.Blocks Blocks = params.Blocks
Minis = params.MiniBlocks Minis = params.MiniBlocks
Rejected = params.Rejected Rejected = params.Rejected
Orphans = params.Orphans
if ModdedNode != params.Hansen33Mod {
if params.Hansen33Mod {
fmt.Print("Hansen33 Mod Mining Node Detected - Happy Mining\n")
}
}
ModdedNode = params.Hansen33Mod
if !ModdedNode {
fmt.Print("Official Mining Node Detected - Happy Mining\n")
}
if min_jobs { if min_jobs {
if params.Height != last_height || params.Difficultyuint64 != last_diff { if params.Height != last_height || params.Difficultyuint64 != last_diff {
last_height = params.Height last_height = params.Height
@ -75,6 +113,23 @@ func Start_client(v string, w string, min_jobs bool, nonce bool) {
} }
} }
func SendUpdateToDaemon() {
var count = 0
for {
if ModdedNode {
if count == 0 {
time.Sleep(60 * time.Second)
}
connection.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.WriteMessage(websocket.TextMessage, buffer) connection.WriteMessage(websocket.TextMessage, buffer)
} }

View File

@ -8,12 +8,11 @@ import (
"math/rand" "math/rand"
"github.com/deroproject/derohe/block" "github.com/deroproject/derohe/block"
"github.com/deroproject/derohe/rpc"
) )
func edit_blob(input []byte, miner [32]byte, nonce bool) (output []byte) { func edit_blob(input []byte, miner [32]byte, nonce bool) (output []byte) {
var err error var err error
var params rpc.GetBlockTemplate_Result var params GetBlockTemplate_Result
var mbl block.MiniBlock var mbl block.MiniBlock
var raw_hex []byte var raw_hex []byte
var out bytes.Buffer var out bytes.Buffer

View File

@ -5,6 +5,7 @@ import (
"crypto/elliptic" "crypto/elliptic"
"crypto/rand" "crypto/rand"
"crypto/x509" "crypto/x509"
"encoding/json"
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"math/big" "math/big"
@ -36,10 +37,22 @@ type user_session struct {
miniblocks uint64 miniblocks uint64
lasterr string lasterr string
address rpc.Address address rpc.Address
orphans uint64
hashrate float64
valid_address bool valid_address bool
address_sum [32]byte address_sum [32]byte
} }
type ( // array without name containing block template in hex
MinerInfo_Params struct {
Wallet_Address string `json:"wallet_address"`
Miner_Tag string `json:"miner_tag"`
Miner_Hashrate float64 `json:"miner_hashrate"`
}
MinerInfo_Result struct {
}
)
var client_list_mutex sync.Mutex var client_list_mutex sync.Mutex
var client_list = map[*websocket.Conn]*user_session{} var client_list = map[*websocket.Conn]*user_session{}
@ -175,8 +188,27 @@ func newUpgrader() *websocket.Upgrader {
client_list_mutex.Lock() client_list_mutex.Lock()
defer client_list_mutex.Unlock() defer client_list_mutex.Unlock()
SendToDaemon(data) var x MinerInfo_Params
fmt.Printf("%v Submitting result from miner: %v, Wallet: %v\n", time.Now().Format(time.Stamp), c.RemoteAddr().String(), client_list[c].address.String()) 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 {
go SendToDaemon(data)
fmt.Printf("%v Submitting result from miner: %v, Wallet: %v\n", time.Now().Format(time.Stamp), c.RemoteAddr().String(), client_list[c].address.String())
}
}) })
u.OnClose(func(c *websocket.Conn, err error) { u.OnClose(func(c *websocket.Conn, err error) {