Preparation for testing branch

This commit is contained in:
8lecramm 2022-06-19 21:28:53 +02:00 committed by GitHub
parent c145528213
commit 6f69341227
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 20 deletions

View File

@ -51,14 +51,16 @@ func main() {
} }
} }
if Arguments["--minimal"].(bool) {
minimal = true
fmt.Printf("%v Forward only 2 jobs per block\n", time.Now().Format(time.Stamp))
}
if Arguments["--nonce"].(bool) { if Arguments["--nonce"].(bool) {
nonce = true nonce = true
minimal = true
fmt.Printf("%v Nonce editing is enabled\n", time.Now().Format(time.Stamp)) fmt.Printf("%v Nonce editing is enabled\n", time.Now().Format(time.Stamp))
fmt.Printf("%v Switch to >minimal< mode\n", time.Now().Format(time.Stamp))
}
if Arguments["--minimal"].(bool) && !Arguments["--nonce"].(bool) {
minimal = true
fmt.Printf("%v Forward only 2 jobs per block\n", time.Now().Format(time.Stamp))
} }
fmt.Printf("%v Logging every %d seconds\n", time.Now().Format(time.Stamp), log_intervall) fmt.Printf("%v Logging every %d seconds\n", time.Now().Format(time.Stamp), log_intervall)

2
go.mod
View File

@ -3,7 +3,7 @@ module derohe-proxy
go 1.18 go 1.18
require ( require (
github.com/chzyer/readline v1.5.0 github.com/bitfield/qrand v0.2.1
github.com/deroproject/derohe v0.0.0-20220502125456-607af6dfdc9a github.com/deroproject/derohe v0.0.0-20220502125456-607af6dfdc9a
github.com/deroproject/graviton v0.0.0-20220130070622-2c248a53b2e1 github.com/deroproject/graviton v0.0.0-20220130070622-2c248a53b2e1
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815

10
go.sum
View File

@ -1,17 +1,13 @@
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/bitfield/qrand v0.2.1 h1:Fwp3GkWlr8Y/tfjB2GrXqYeR3nl/SEjFMnCDxVdVUGo=
github.com/bitfield/qrand v0.2.1/go.mod h1:D3AK1+Wqay/g3Z0tBM5OiO2YjR5MK2XYgDkmx8eec2w=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/caarlos0/env/v6 v6.9.1 h1:zOkkjM0F6ltnQ5eBX6IPI41UP/KDGEK7rRPwGCNos8k= github.com/caarlos0/env/v6 v6.9.1 h1:zOkkjM0F6ltnQ5eBX6IPI41UP/KDGEK7rRPwGCNos8k=
github.com/caarlos0/env/v6 v6.9.1/go.mod h1:hvp/ryKXKipEkcuYjs9mI4bBCg+UI0Yhgm5Zu0ddvwc= github.com/caarlos0/env/v6 v6.9.1/go.mod h1:hvp/ryKXKipEkcuYjs9mI4bBCg+UI0Yhgm5Zu0ddvwc=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/chzyer/logex v1.2.0 h1:+eqR0HfOetur4tgnC8ftU5imRnhi4te+BadWS95c5AM=
github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY=
github.com/chzyer/readline v1.5.0 h1:lSwwFrbNviGePhkewF1az4oLmcwqCZijQ2/Wi3BGHAI=
github.com/chzyer/readline v1.5.0/go.mod h1:x22KAscuvRqlLoK9CsoYsmxoXZMMFVyOl86cAH8qUic=
github.com/chzyer/test v0.0.0-20210722231415-061457976a23 h1:dZ0/VyGgQdVGAss6Ju0dt5P0QltE0SFY5Woh6hbIfiQ=
github.com/chzyer/test v0.0.0-20210722231415-061457976a23/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -28,6 +24,8 @@ github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/zapr v1.2.3 h1:a9vnzlIBPQBBkeaR9IuMUfmVOrQlkoC4YfPoFkX3T7A= github.com/go-logr/zapr v1.2.3 h1:a9vnzlIBPQBBkeaR9IuMUfmVOrQlkoC4YfPoFkX3T7A=
github.com/go-logr/zapr v1.2.3/go.mod h1:eIauM6P8qSvTw5o2ez6UEAfGjQKrxQTl5EoK+Qa2oG4= github.com/go-logr/zapr v1.2.3/go.mod h1:eIauM6P8qSvTw5o2ez6UEAfGjQKrxQTl5EoK+Qa2oG4=
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=

View File

@ -4,7 +4,6 @@ import (
"crypto/tls" "crypto/tls"
"encoding/json" "encoding/json"
"fmt" "fmt"
"math/rand"
"net/url" "net/url"
"time" "time"
@ -23,8 +22,6 @@ func Start_client(v string, w string, min_jobs bool, nonce bool) {
var last_diff uint64 var last_diff uint64
var last_height uint64 var last_height uint64
rand.Seed(time.Now().UnixMilli())
for { for {
u := url.URL{Scheme: "wss", Host: v, Path: "/ws/" + w} u := url.URL{Scheme: "wss", Host: v, Path: "/ws/" + w}

View File

@ -2,15 +2,24 @@ package proxy
import ( import (
"bytes" "bytes"
"encoding/binary"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"fmt" "fmt"
"math/rand" "sync"
"time"
"github.com/bitfield/qrand"
"github.com/deroproject/derohe/block" "github.com/deroproject/derohe/block"
"github.com/deroproject/derohe/rpc" "github.com/deroproject/derohe/rpc"
) )
type nonce_store struct {
nonce [8]byte
timestamp time.Time
sync.RWMutex
}
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 rpc.GetBlockTemplate_Result
@ -37,13 +46,23 @@ func edit_blob(input []byte, miner [32]byte, nonce bool) (output []byte) {
// Insert random nonce // Insert random nonce
if nonce { if nonce {
for i := range mbl.Nonce { var qnonce [8]byte
mbl.Nonce[i] = rand.Uint32() Found.Lock()
// send nonce pattern to all nodes, lasts for 2 hours or until another nonce has been found
// TODO: add command argument
if binary.BigEndian.Uint64(Found.nonce[:]) > 0 && time.Now().Sub(Found.timestamp) < time.Hour*2 {
copy(qnonce[:], Found.nonce[:])
qrand.Read(qnonce[0:2])
mbl.Nonce[1] = binary.BigEndian.Uint32(qnonce[0:4])
mbl.Nonce[2] = binary.BigEndian.Uint32(qnonce[4:8])
} else {
qrand.Read(qnonce[:])
mbl.Nonce[1] = binary.BigEndian.Uint32(qnonce[0:4])
mbl.Nonce[2] = binary.BigEndian.Uint32(qnonce[4:8])
} }
Found.Unlock()
} }
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

@ -5,6 +5,8 @@ import (
"crypto/elliptic" "crypto/elliptic"
"crypto/rand" "crypto/rand"
"crypto/x509" "crypto/x509"
"encoding/hex"
"encoding/json"
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"math/big" "math/big"
@ -14,6 +16,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/deroproject/derohe/block"
"github.com/deroproject/derohe/globals" "github.com/deroproject/derohe/globals"
"github.com/deroproject/derohe/rpc" "github.com/deroproject/derohe/rpc"
"github.com/deroproject/graviton" "github.com/deroproject/graviton"
@ -46,6 +49,7 @@ var client_list = map[*websocket.Conn]*user_session{}
var miners_count int var miners_count int
var Wallet_count map[string]uint var Wallet_count map[string]uint
var Address string var Address string
var Found nonce_store
func Start_server(listen string) { func Start_server(listen string) {
var err error var err error
@ -168,6 +172,8 @@ func newUpgrader() *websocket.Upgrader {
u.OnMessage(func(c *websocket.Conn, messageType websocket.MessageType, data []byte) { u.OnMessage(func(c *websocket.Conn, messageType websocket.MessageType, data []byte) {
var params rpc.SubmitBlock_Params
if messageType != websocket.TextMessage { if messageType != websocket.TextMessage {
return return
} }
@ -177,6 +183,16 @@ func newUpgrader() *websocket.Upgrader {
SendToDaemon(data) 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()) fmt.Printf("%v Submitting result from miner: %v, Wallet: %v\n", time.Now().Format(time.Stamp), c.RemoteAddr().String(), client_list[c].address.String())
// Store nonce
if err := json.Unmarshal(data, &params); err == nil {
Found.RLock()
var mbl []byte
mbl, _ = hex.DecodeString(params.MiniBlockhashing_blob)
Found.timestamp = time.Now()
copy(Found.nonce[:], mbl[block.MINIBLOCK_SIZE-8:block.MINIBLOCK_SIZE])
fmt.Printf("%v Nonce %x, timestamp %v\n", time.Now().Format(time.Stamp), Found.nonce, Found.timestamp.Format(time.Stamp))
Found.RUnlock()
}
}) })
u.OnClose(func(c *websocket.Conn, err error) { u.OnClose(func(c *websocket.Conn, err error) {