"Nonce" switch added, minor changes

This commit is contained in:
8lecramm 2022-06-08 01:03:38 +02:00 committed by GitHub
parent cb580cde7d
commit fba01cc1ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 22 deletions

View File

@ -4,13 +4,14 @@ var command_line string = `derohe-proxy
Proxy to combine all miners and to reduce network load Proxy to combine all miners and to reduce network load
Usage: Usage:
derohe-proxy [--listen-address=<127.0.0.1:10100>] [--log-interval=<60>] [--minimal-jobs] --daemon-address=<1.2.3.4:10100> derohe-proxy [--listen-address=<127.0.0.1:10100>] [--log-interval=<60>] [--minimal] [--nonce] --daemon-address=<1.2.3.4:10100>
Options: Options:
--listen-address=<127.0.0.1:10100> bind to specific address:port, default is 0.0.0.0:10200 --listen-address=<127.0.0.1:10100> bind to specific address:port, default is 0.0.0.0:10200
--daemon-address=<1.2.3.4:10100> connect to this daemon --daemon-address=<1.2.3.4:10100> connect to this daemon
--log-interval=<60> set logging interval in seconds (range 60 - 3600), default is 60 seconds --log-interval=<60> set logging interval in seconds (range 60 - 3600), default is 60 seconds
--minimal-jobs forward only 2 jobs per block (1 for miniblocks and 1 for final miniblock), by default all jobs are forwarded --minimal forward only 2 jobs per block (1 for miniblocks and 1 for final miniblock), by default all jobs are forwarded
--nonce enable nonce editing, default is off
Example Mainnet: ./derohe-proxy --daemon-address=minernode1.dero.io:10100 Example Mainnet: ./derohe-proxy --daemon-address=minernode1.dero.io:10100
` `
@ -25,4 +26,7 @@ var daemon_address string = "minernode1.dero.io:10100"
var log_intervall int = 60 var log_intervall int = 60
// send only 2 jobs per block // send only 2 jobs per block
var minimal = false var minimal bool = false
// edit nonce
var nonce bool = false

View File

@ -51,12 +51,17 @@ func main() {
} }
} }
if Arguments["--minimal-jobs"].(bool) { if Arguments["--minimal"].(bool) {
minimal = true minimal = true
fmt.Printf("Forward 2 jobs per block\n") fmt.Printf("%v Forward only 2 jobs per block\n", time.Now().Format(time.Stamp))
} }
fmt.Printf("Logging every %d seconds\n", log_intervall) if Arguments["--nonce"].(bool) {
nonce = true
fmt.Printf("%v Nonce editing is enabled\n", time.Now().Format(time.Stamp))
}
fmt.Printf("%v Logging every %d seconds\n", time.Now().Format(time.Stamp), log_intervall)
go proxy.Start_server(listen_addr) go proxy.Start_server(listen_addr)
@ -64,13 +69,13 @@ func main() {
for proxy.CountMiners() < 1 { for proxy.CountMiners() < 1 {
time.Sleep(time.Second * 1) time.Sleep(time.Second * 1)
} }
go proxy.Start_client(daemon_address, proxy.Address, minimal) go proxy.Start_client(daemon_address, proxy.Address, minimal, nonce)
for { for {
time.Sleep(time.Second * time.Duration(log_intervall)) time.Sleep(time.Second * time.Duration(log_intervall))
fmt.Printf("%v %d miners connected, Bl: %d, Mbl: %d, Rej: %d\n", time.Now().Format(time.Stamp), proxy.CountMiners(), proxy.Blocks, proxy.Minis, proxy.Rejected) fmt.Printf("%v %d miners connected, Bl: %d, Mbl: %d, Rej: %d\n", time.Now().Format(time.Stamp), proxy.CountMiners(), proxy.Blocks, proxy.Minis, proxy.Rejected)
for i := range proxy.Wallet_count { for i := range proxy.Wallet_count {
if proxy.Wallet_count[i] > 0 { if proxy.Wallet_count[i] > 1 {
fmt.Printf("%v Wallet %v, %d miners\n", time.Now().Format(time.Stamp), i, proxy.Wallet_count[i]) fmt.Printf("%v Wallet %v, %d miners\n", time.Now().Format(time.Stamp), i, proxy.Wallet_count[i])
} }
} }

View File

@ -18,7 +18,7 @@ var Minis uint64
var Rejected uint64 var Rejected uint64
// proxy-client // proxy-client
func Start_client(v string, w string, min_jobs bool) { func Start_client(v string, w string, min_jobs bool, nonce bool) {
var err error var err error
var last_diff uint64 var last_diff uint64
var last_height uint64 var last_height uint64
@ -66,10 +66,10 @@ func Start_client(v string, w string, min_jobs bool) {
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
last_diff = params.Difficultyuint64 last_diff = params.Difficultyuint64
go SendTemplateToNodes(recv_data) go SendTemplateToNodes(recv_data, nonce)
} }
} else { } else {
go SendTemplateToNodes(recv_data) go SendTemplateToNodes(recv_data, nonce)
} }
} }
} }

View File

@ -11,7 +11,7 @@ import (
"github.com/deroproject/derohe/rpc" "github.com/deroproject/derohe/rpc"
) )
func edit_blob(input []byte, miner [32]byte) (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 rpc.GetBlockTemplate_Result
var mbl block.MiniBlock var mbl block.MiniBlock
@ -36,10 +36,13 @@ func edit_blob(input []byte, miner [32]byte) (output []byte) {
} }
// Insert random nonce // Insert random nonce
if nonce {
for i := range mbl.Nonce { for i := range mbl.Nonce {
mbl.Nonce[i] = rand.Uint32() mbl.Nonce[i] = rand.Uint32()
} }
mbl.Flags = rand.Uint32() }
mbl.Flags = 3735928559 // ;)
params.Blockhashing_blob = fmt.Sprintf("%x", mbl.Serialize()) params.Blockhashing_blob = fmt.Sprintf("%x", mbl.Serialize())
encoder := json.NewEncoder(&out) encoder := json.NewEncoder(&out)

View File

@ -97,8 +97,7 @@ func CountMiners() int {
} }
// forward all incoming templates from daemon to all miners // forward all incoming templates from daemon to all miners
func SendTemplateToNodes(input []byte) { func SendTemplateToNodes(data []byte, nonce bool) {
var data []byte
client_list_mutex.Lock() client_list_mutex.Lock()
defer client_list_mutex.Unlock() defer client_list_mutex.Unlock()
@ -111,11 +110,10 @@ func SendTemplateToNodes(input []byte) {
miner_address := rv.address_sum miner_address := rv.address_sum
if nonce := edit_blob(input, miner_address); nonce != nil { if result := edit_blob(data, miner_address, nonce); result != nil {
data = nonce data = result
} else { } else {
fmt.Println(time.Now().Format(time.Stamp), "Failed to change nonce") fmt.Println(time.Now().Format(time.Stamp), "Failed to change nonce / miner keyhash")
data = input
} }
go func(k *websocket.Conn, v *user_session) { go func(k *websocket.Conn, v *user_session) {
@ -185,7 +183,7 @@ func newUpgrader() *websocket.Upgrader {
client_list_mutex.Lock() client_list_mutex.Lock()
defer client_list_mutex.Unlock() defer client_list_mutex.Unlock()
Wallet_count[client_list[c].address.String()]-- Wallet_count[client_list[c].address.String()]--
fmt.Printf("%v Lost connection: %v, Wallet: %v\n", time.Now().Format(time.Stamp), c.RemoteAddr().String(), client_list[c].address.String()) fmt.Printf("%v Lost connection: %v\n", time.Now().Format(time.Stamp), c.RemoteAddr().String())
delete(client_list, c) delete(client_list, c)
}) })