From fba01cc1ecd4ae037c501ed68e47cdfe8b0fdd57 Mon Sep 17 00:00:00 2001 From: 8lecramm <89603217+8lecramm@users.noreply.github.com> Date: Wed, 8 Jun 2022 01:03:38 +0200 Subject: [PATCH] "Nonce" switch added, minor changes --- config.go | 10 +++++++--- derohe-proxy.go | 15 ++++++++++----- proxy/client.go | 6 +++--- proxy/feature.go | 11 +++++++---- proxy/server.go | 12 +++++------- 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/config.go b/config.go index ddd6aff..14b32b4 100644 --- a/config.go +++ b/config.go @@ -4,13 +4,14 @@ var command_line string = `derohe-proxy Proxy to combine all miners and to reduce network load 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: --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 --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 ` @@ -25,4 +26,7 @@ var daemon_address string = "minernode1.dero.io:10100" var log_intervall int = 60 // send only 2 jobs per block -var minimal = false +var minimal bool = false + +// edit nonce +var nonce bool = false diff --git a/derohe-proxy.go b/derohe-proxy.go index 3a828a3..504e9b8 100644 --- a/derohe-proxy.go +++ b/derohe-proxy.go @@ -51,12 +51,17 @@ func main() { } } - if Arguments["--minimal-jobs"].(bool) { + if Arguments["--minimal"].(bool) { 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) @@ -64,13 +69,13 @@ func main() { for proxy.CountMiners() < 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 { 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) 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]) } } diff --git a/proxy/client.go b/proxy/client.go index 9e37e7e..7b76550 100644 --- a/proxy/client.go +++ b/proxy/client.go @@ -18,7 +18,7 @@ var Minis uint64 var Rejected uint64 // 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 last_diff 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 { last_height = params.Height last_diff = params.Difficultyuint64 - go SendTemplateToNodes(recv_data) + go SendTemplateToNodes(recv_data, nonce) } } else { - go SendTemplateToNodes(recv_data) + go SendTemplateToNodes(recv_data, nonce) } } } diff --git a/proxy/feature.go b/proxy/feature.go index cdddbd2..fd0c2de 100644 --- a/proxy/feature.go +++ b/proxy/feature.go @@ -11,7 +11,7 @@ import ( "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 params rpc.GetBlockTemplate_Result var mbl block.MiniBlock @@ -36,10 +36,13 @@ func edit_blob(input []byte, miner [32]byte) (output []byte) { } // Insert random nonce - for i := range mbl.Nonce { - mbl.Nonce[i] = rand.Uint32() + if nonce { + for i := range mbl.Nonce { + mbl.Nonce[i] = rand.Uint32() + } } - mbl.Flags = rand.Uint32() + + mbl.Flags = 3735928559 // ;) params.Blockhashing_blob = fmt.Sprintf("%x", mbl.Serialize()) encoder := json.NewEncoder(&out) diff --git a/proxy/server.go b/proxy/server.go index 5ed3d89..ab5e494 100644 --- a/proxy/server.go +++ b/proxy/server.go @@ -97,8 +97,7 @@ func CountMiners() int { } // forward all incoming templates from daemon to all miners -func SendTemplateToNodes(input []byte) { - var data []byte +func SendTemplateToNodes(data []byte, nonce bool) { client_list_mutex.Lock() defer client_list_mutex.Unlock() @@ -111,11 +110,10 @@ func SendTemplateToNodes(input []byte) { miner_address := rv.address_sum - if nonce := edit_blob(input, miner_address); nonce != nil { - data = nonce + if result := edit_blob(data, miner_address, nonce); result != nil { + data = result } else { - fmt.Println(time.Now().Format(time.Stamp), "Failed to change nonce") - data = input + fmt.Println(time.Now().Format(time.Stamp), "Failed to change nonce / miner keyhash") } go func(k *websocket.Conn, v *user_session) { @@ -185,7 +183,7 @@ func newUpgrader() *websocket.Upgrader { client_list_mutex.Lock() defer client_list_mutex.Unlock() 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) })