mirror of
https://github.com/8lecramm/derohe-proxy.git
synced 2025-01-10 13:57:56 +00:00
"Nonce" switch added, minor changes
This commit is contained in:
parent
cb580cde7d
commit
fba01cc1ec
10
config.go
10
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
|
||||
|
@ -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])
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
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)
|
||||
|
@ -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)
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user