diff --git a/api.json b/api.json index 4dbbf84..66ed7fa 100644 --- a/api.json +++ b/api.json @@ -4,7 +4,6 @@ "name": "main", "pplns": 9000, "network": "classic", - "algo": "etchash", "coin-name": "ETC", "proxy": { "enabled": true, @@ -135,4 +134,4 @@ "newrelicName": "MyEtherProxy", "newrelicKey": "SECRET_KEY", "newrelicVerbose": false -} +} \ No newline at end of file diff --git a/go.mod b/go.mod index 24e421c..fa77a34 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/gorilla/mux v1.8.1 github.com/robfig/cron v1.2.0 github.com/yuriy0803/core-geth1 v0.0.0-20231122180645-3601ffad87c7 - github.com/yuriy0803/etchash v0.0.0-20231130222458-45df99d996c1 + github.com/yuriy0803/etchash v0.0.0-20231201134926-6d603b2478fb github.com/yvasiyarov/gorelic v0.0.7 gopkg.in/redis.v3 v3.6.4 ) @@ -15,8 +15,11 @@ require ( github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/edsrzf/mmap-go v1.1.0 // indirect + github.com/garyburd/redigo v1.6.4 // indirect github.com/go-stack/stack v1.8.1 // indirect github.com/holiman/uint256 v1.2.4 // indirect + github.com/onsi/ginkgo v1.16.5 // indirect + github.com/onsi/gomega v1.30.0 // indirect github.com/yvasiyarov/go-metrics v0.0.0-20150112132944-c25f46c4b940 // indirect github.com/yvasiyarov/newrelic_platform_go v0.0.0-20160601141957-9c099fbc30e9 // indirect golang.org/x/crypto v0.16.0 // indirect diff --git a/go.sum b/go.sum index 6793c98..7f0bf4c 100644 --- a/go.sum +++ b/go.sum @@ -1,34 +1,118 @@ github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= +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/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/edsrzf/mmap-go v1.1.0 h1:6EUwBLQ/Mcr1EYLE4Tn1VdW1A4ckqCQWZBw8Hr0kjpQ= github.com/edsrzf/mmap-go v1.1.0/go.mod h1:19H/e8pUPLicwkyNgOykDXkJ9F0MHE+Z52B8EIth78Q= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= +github.com/garyburd/redigo v1.6.4 h1:LFu2R3+ZOPgSMWMOL+saa/zXRjw0ID2G8FepO53BGlg= +github.com/garyburd/redigo v1.6.4/go.mod h1:rTb6epsqigu3kYKBnaF028A7Tf/Aw5s0cqA47doKKqw= github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/holiman/uint256 v1.2.4 h1:jUc4Nk8fm9jZabQuqr2JzednajVmBpC+oiTiXZJEApU= github.com/holiman/uint256 v1.2.4/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= +github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ= github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuriy0803/core-geth1 v0.0.0-20231122180645-3601ffad87c7 h1:Qh1lF49wclbdRRypBz9ZhQ9NRmHAxPLwTwS/Lsc8CjY= github.com/yuriy0803/core-geth1 v0.0.0-20231122180645-3601ffad87c7/go.mod h1:yf10EqBwKdsy8nnhlSvJFXwzhBh0/btBez47+g+faY8= -github.com/yuriy0803/etchash v0.0.0-20231130215908-1c85b419b225 h1:naCkX3OjoRt59+vMjDfIR+2s5TMsxq0O62Ism5Il3m8= -github.com/yuriy0803/etchash v0.0.0-20231130215908-1c85b419b225/go.mod h1:9q4LZ8KkbmmyS8FUEdCnTeA+sWohK70OyJlzewfcLMk= github.com/yuriy0803/etchash v0.0.0-20231130222458-45df99d996c1 h1:LUP0HiOgIP6ERgwp/flyMfPnhApIJwqsKzFG26ewP/U= github.com/yuriy0803/etchash v0.0.0-20231130222458-45df99d996c1/go.mod h1:9q4LZ8KkbmmyS8FUEdCnTeA+sWohK70OyJlzewfcLMk= +github.com/yuriy0803/etchash v0.0.0-20231201134926-6d603b2478fb h1:feHkNXLPkbVYgfZ683qmsNOjjn+G9pGhjDCDkl/jAEc= +github.com/yuriy0803/etchash v0.0.0-20231201134926-6d603b2478fb/go.mod h1:9q4LZ8KkbmmyS8FUEdCnTeA+sWohK70OyJlzewfcLMk= github.com/yvasiyarov/go-metrics v0.0.0-20150112132944-c25f46c4b940 h1:p7OofyZ509h8DmPLh8Hn+EIIZm/xYhdZHJ9GnXHdr6U= github.com/yvasiyarov/go-metrics v0.0.0-20150112132944-c25f46c4b940/go.mod h1:aX5oPXxHm3bOH+xeAttToC8pqch2ScQN/JoXYupl6xs= github.com/yvasiyarov/gorelic v0.0.7 h1:4DTF1WOM2ZZS/xMOkTFBOcb6XiHu/PKn3rVo6dbewQE= github.com/yvasiyarov/gorelic v0.0.7/go.mod h1:NUSPSUX/bi6SeDMUh6brw0nXpxHnc96TguQh0+r/ssA= github.com/yvasiyarov/newrelic_platform_go v0.0.0-20160601141957-9c099fbc30e9 h1:AsFN8kXcCVkUFHyuzp1FtYbzp1nCO/H6+1uPSGEyPzM= github.com/yvasiyarov/newrelic_platform_go v0.0.0-20160601141957-9c099fbc30e9/go.mod h1:GlGEuHIJweS1mbCqG+7vt2nvWLzLLnRHbXz5JKd/Qbg= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= gopkg.in/bsm/ratelimit.v1 v1.0.0-20170922094635-f56db5e73a5e h1:7iCTd7kl1AsKU3dJk/Y/z4WSVRe9OXA7A0tk0CBEfMA= gopkg.in/bsm/ratelimit.v1 v1.0.0-20170922094635-f56db5e73a5e/go.mod h1:KF9sEfUPAXdG8Oev9e99iLGnl2uJMjc5B+4y3O7x610= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/redis.v3 v3.6.4 h1:u7XgPH1rWwsdZnR+azldXC6x9qDU2luydOIeU/l52fE= gopkg.in/redis.v3 v3.6.4/go.mod h1:6XeGv/CrsUFDU9aVbUdNykN7k1zVmoeg83KC9RbQfiU= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/open-etc-pool-friends.exe b/open-etc-pool-friends.exe new file mode 100644 index 0000000..21eac16 Binary files /dev/null and b/open-etc-pool-friends.exe differ diff --git a/proxy/miner.go b/proxy/miner.go index 8a59c20..bd07ddc 100644 --- a/proxy/miner.go +++ b/proxy/miner.go @@ -16,22 +16,25 @@ var ( ecip1099FBlockClassic uint64 = 11700000 // classic mainnet ecip1099FBlockMordor uint64 = 2520000 // mordor uip1FEpoch uint64 = 22 // ubiq mainnet + xip5Block uint64 = 0 // expanse rebirth network hasher *etchash.Etchash = nil ) func (s *ProxyServer) processShare(login, id, ip string, t *BlockTemplate, params []string, stratum bool) (bool, bool) { if hasher == nil { - switch s.config.Network { - case "classic": - hasher = etchash.New(&ecip1099FBlockClassic, nil) // classic mainnet - case "mordor": - hasher = etchash.New(&ecip1099FBlockMordor, nil) // mordor - case "ubiq": - hasher = etchash.New(nil, &uip1FEpoch) // ubiq mainnet - case "ethereum", "ropsten", "ethereumPow", "ethereumFair", "callisto", "etica", "expanse", "octaspace", "universal", "canxium": - hasher = etchash.New(nil, nil) //ethash - default: + if s.config.Network == "expanse" || s.config.Network == "rebirth" { + hasher = etchash.New(nil, nil, &xip5Block) + } else if s.config.Network == "classic" { + hasher = etchash.New(&ecip1099FBlockClassic, nil, nil) + } else if s.config.Network == "mordor" { + hasher = etchash.New(&ecip1099FBlockMordor, nil, nil) + } else if s.config.Network == "ubiq" { + hasher = etchash.New(nil, &uip1FEpoch, nil) + } else if s.config.Network == "ethereum" || s.config.Network == "ropsten" || s.config.Network == "ethereumPow" || s.config.Network == "ethereumFair" || s.config.Network == "callisto" || s.config.Network == "etica" || s.config.Network == "octaspace" || s.config.Network == "universal" { + hasher = etchash.New(nil, nil, nil) + } else { + // unknown network log.Printf("Unknown network configuration %s", s.config.Network) return false, false } diff --git a/proxy/proto.go b/proxy/proto.go index f6d0751..ec84b7e 100644 --- a/proxy/proto.go +++ b/proxy/proto.go @@ -12,8 +12,6 @@ type JSONStratumReq struct { Id interface{} `json:"id"` Method string `json:"method"` Params interface{} `json:"params"` - Height string `json:"height"` - Algo string `json:"algo"` } type StratumReq struct { diff --git a/proxy/stratum.go b/proxy/stratum.go index 5ef07fb..f7e2425 100644 --- a/proxy/stratum.go +++ b/proxy/stratum.go @@ -26,13 +26,11 @@ const ( ) func (s *ProxyServer) ListenTCP() { - // Parse timeout duration from configuration s.timeout = util.MustParseDuration(s.config.Proxy.Stratum.Timeout) var err error var server net.Listener - - // If TLS is enabled, load certificate and key file and create a TLS listener + setKeepAlive := func(net.Conn) {} if s.config.Proxy.Stratum.TLS { var cert tls.Certificate cert, err = tls.LoadX509KeyPair(s.config.Proxy.Stratum.CertFile, s.config.Proxy.Stratum.KeyFile) @@ -42,8 +40,10 @@ func (s *ProxyServer) ListenTCP() { tlsCfg := &tls.Config{Certificates: []tls.Certificate{cert}} server, err = tls.Listen("tcp", s.config.Proxy.Stratum.Listen, tlsCfg) } else { - // Otherwise, create a regular TCP listener server, err = net.Listen("tcp", s.config.Proxy.Stratum.Listen) + setKeepAlive = func(conn net.Conn) { + conn.(*net.TCPConn).SetKeepAlive(true) + } } if err != nil { log.Fatalf("Error: %v", err) @@ -55,27 +55,26 @@ func (s *ProxyServer) ListenTCP() { n := 0 for { - // Accept new incoming connections conn, err := server.Accept() if err != nil { continue } + setKeepAlive(conn) + ip, _, _ := net.SplitHostPort(conn.RemoteAddr().String()) - // Apply IP banning and connection limiting policies if s.policy.IsBanned(ip) || !s.policy.ApplyLimitPolicy(ip) { conn.Close() continue } n += 1 - // Generate a unique extranonce value for this session + // make unique extranonce extranonce := s.uniqExtranonce() cs := &Session{conn: conn, ip: ip, Extranonce: extranonce, ExtranonceSub: false, stratum: -1} - // Allocate a stale jobs cache for this session + // allocate stales cache cs.staleJobs = make(map[string]staleJob) accept <- n - // Start a new goroutine to handle the session go func(cs *Session) { err = s.handleTCPClient(cs) if err != nil { @@ -87,130 +86,82 @@ func (s *ProxyServer) ListenTCP() { } } -// handleTCPClient reads incoming data from a client and handles it appropriately. func (s *ProxyServer) handleTCPClient(cs *Session) error { - // Create an encoder to send data to the client cs.enc = json.NewEncoder(cs.conn) - - // Create a buffer to read incoming data from the client connbuff := bufio.NewReaderSize(cs.conn, MaxReqSize) - - // Set a deadline for the connection s.setDeadline(cs.conn) - for { - // Read a line of data from the client data, isPrefix, err := connbuff.ReadLine() - - // If the data is too large for the buffer, ban the client and return an error if isPrefix { log.Printf("Socket flood detected from %s", cs.ip) s.policy.BanClient(cs.ip) return err - } - - // If the client disconnects, remove their session and break the loop - if err == io.EOF { + } else if err == io.EOF { log.Printf("Client %s disconnected", cs.ip) s.removeSession(cs) break - } - - // If there was an error reading from the client, log the error and return it - if err != nil { + } else if err != nil { log.Printf("Error reading from socket: %v", err) return err } - // If the data is not empty, attempt to unmarshal it as a Stratum request if len(data) > 1 { var req StratumReq err = json.Unmarshal(data, &req) - - // If the data is malformed, apply the malformed policy, log the error, and return it if err != nil { s.policy.ApplyMalformedPolicy(cs.ip) log.Printf("Malformed stratum request from %s: %v", cs.ip, err) return err } - - // Set a new deadline for the connection s.setDeadline(cs.conn) - - // Handle the incoming message from the client err = cs.handleTCPMessage(s, &req) - - // If there was an error handling the message, return it if err != nil { return err } } } - - // Return nil when finished handling the client return nil } -// setStratumMode sets the stratum mode of the session based on the provided string. -// If the string is "EthereumStratum/1.0.0", the stratum mode will be set to NiceHash. -// Otherwise, the stratum mode will be set to EthProxy. -// Returns an error if the string is empty or if an invalid stratum mode is provided. func (cs *Session) setStratumMode(str string) error { switch str { case "EthereumStratum/1.0.0": cs.stratum = NiceHash + break default: cs.stratum = EthProxy + break } return nil } -// stratumMode returns the current stratum mode of the session. -// The returned value is an integer representing the current stratum mode, -// where 0 represents EthProxy and 1 represents NiceHash. func (cs *Session) stratumMode() int { - // Returns the current stratum mode of the session. return cs.stratum } func (cs *Session) handleTCPMessage(s *ProxyServer, req *StratumReq) error { // Handle RPC/Stratum methods switch req.Method { - // claymore -esm 1 - case "eth_login": - // Unmarshal request parameters + case "eth_submitLogin": var params []string err := json.Unmarshal(req.Params, ¶ms) - if err != nil { + if err != nil || len(params) < 1 { log.Println("Malformed stratum request params from", cs.ip) return err } - // Process "eth_login" method and return response reply, errReply := s.handleLoginRPC(cs, params, req.Worker) if errReply != nil { return cs.sendTCPError(req.Id, errReply) } - return cs.sendTCPResult(req.Id, reply) - // claymore -esm 0 - case "eth_submitLogin": - var params []string - if err := json.Unmarshal(req.Params, ¶ms); err != nil || len(params) < 1 { - log.Printf("Malformed stratum request params from %s: %v", cs.ip, err) - return err - } - reply, err := s.handleLoginRPC(cs, params, req.Worker) - if err != nil { - log.Printf("Error handling login RPC from %s: %v", cs.ip, err) - return cs.sendTCPError(req.Id, err) - } cs.setStratumMode("EthProxy") - log.Printf("EthProxy login from %s: %v", cs.ip, params[0]) + log.Println("EthProxy login", cs.ip) return cs.sendTCPResult(req.Id, reply) case "mining.subscribe": - params := []string{} - if err := json.Unmarshal(req.Params, ¶ms); err != nil || len(params) < 2 { - log.Println("Malformed stratum request params from", cs.ip, err) + var params []string + err := json.Unmarshal(req.Params, ¶ms) + if err != nil || len(params) < 2 { + log.Println("Malformed stratum request params from", cs.ip) return err } @@ -218,18 +169,11 @@ func (cs *Session) handleTCPMessage(s *ProxyServer, req *StratumReq) error { log.Println("Unsupported stratum version from", cs.ip) return cs.sendStratumError(req.Id, "unsupported stratum version") } - cs.ExtranonceSub = true cs.setStratumMode("EthereumStratum/1.0.0") log.Println("Nicehash subscribe", cs.ip) - result := cs.getNotificationResponse(s) - if err := cs.sendStratumResult(req.Id, result); err != nil { - log.Println("Failed to send stratum result:", err) - return err - } - - return nil + return cs.sendStratumResult(req.Id, result) default: switch cs.stratumMode() { @@ -256,7 +200,7 @@ func (cs *Session) handleTCPMessage(s *ProxyServer, req *StratumReq) error { reply, errReply := s.handleLoginRPC(cs, params, req.Worker) if errReply != nil { return cs.sendStratumError(req.Id, []string{ - string(rune(errReply.Code)), + string(errReply.Code), errReply.Message, }) } @@ -320,8 +264,6 @@ func (cs *Session) handleTCPMessage(s *ProxyServer, req *StratumReq) error { id = splitData[1] } - cs.worker = id - // check Extranonce subscription. extranonce := cs.Extranonce if !cs.ExtranonceSub { @@ -386,27 +328,18 @@ func (cs *Session) handleTCPMessage(s *ProxyServer, req *StratumReq) error { return cs.sendTCPError(req.Id, errReply) } return cs.sendTCPResult(req.Id, &reply) - // Handle requests of type "eth_submitWork" case "eth_submitWork": - // Unmarshal the parameters from the request into a slice of strings var params []string err := json.Unmarshal(req.Params, ¶ms) - // Check if there was an error unmarshaling the parameters or if they don't meet the required length and format criteria - if err != nil || len(params) < 3 || len(params[0]) != 18 || len(params[1]) != 66 || len(params[2]) != 66 { - // If there was an error, log the issue and return it + if err != nil || len(params) < 3 { log.Println("Malformed stratum request params from", cs.ip) return err } - // If the parameters are valid, call the handler function for submitting work reply, errReply := s.handleTCPSubmitRPC(cs, req.Worker, params) - // Check if there was an error handling the request if errReply != nil { - // If there was, return the error return cs.sendTCPError(req.Id, errReply) } - // If the request was handled successfully, return the result return cs.sendTCPResult(req.Id, &reply) - case "eth_submitHashrate": var params []string err := json.Unmarshal(req.Params, ¶ms) @@ -418,7 +351,7 @@ func (cs *Session) handleTCPMessage(s *ProxyServer, req *StratumReq) error { hashrateStr := params[0] if !strings.HasPrefix(hashrateStr, "0x") { log.Println("Malformed hashrate value in eth_submitHashrate request from", cs.ip) - return errors.New("malformed hashrate value") + return errors.New("Malformed hashrate value") } hashrate, err := strconv.ParseInt(hashrateStr[2:], 16, 64) @@ -436,19 +369,6 @@ func (cs *Session) handleTCPMessage(s *ProxyServer, req *StratumReq) error { } } -func formatEthHashrate(shareDiffCalc int64) string { - units := []string{"H/s", "KH/s", "MH/s", "GH/s", "TH/s", "PH/s"} - var i int - diff := float64(shareDiffCalc) - - for i = 0; i < len(units)-1 && diff >= 1000.0; i++ { - diff /= 1000.0 - } - - formatted := strconv.FormatFloat(diff, 'f', 2, 64) - return formatted + " " + units[i] -} - func (cs *Session) sendTCPResult(id json.RawMessage, result interface{}) error { cs.Lock() defer cs.Unlock() @@ -498,8 +418,6 @@ func (cs *Session) pushNewJob(s *ProxyServer, result interface{}) error { cs.JobDetails.HeaderHash = cs.JobDetails.HeaderHash[2:] } - a := s.currentBlockTemplate() - resp := JSONStratumReq{ Method: "mining.notify", Params: []interface{}{ @@ -516,9 +434,6 @@ func (cs *Session) pushNewJob(s *ProxyServer, result interface{}) error { // It's undetermined what's more cost-effective false, }, - - Height: util.ToHex1(int64(a.Height)), - Algo: s.config.Algo, } return cs.enc.Encode(&resp) } @@ -563,8 +478,8 @@ func (cs *Session) sendTCPReq(resp JSONStratumReq) error { return cs.enc.Encode(&resp) } -func (s *ProxyServer) setDeadline(conn net.Conn) { - conn.SetDeadline(time.Now().Add(s.timeout)) +func (self *ProxyServer) setDeadline(conn net.Conn) { + conn.SetDeadline(time.Now().Add(self.timeout)) } func (s *ProxyServer) registerSession(cs *Session) { @@ -586,7 +501,7 @@ func (cs *Session) sendJob(s *ProxyServer, id json.RawMessage, newjob bool) erro reply, errReply := s.handleGetWorkRPC(cs) if errReply != nil { return cs.sendStratumError(id, []string{ - string(rune(errReply.Code)), + string(errReply.Code), errReply.Message, }) } @@ -606,8 +521,6 @@ func (cs *Session) sendJob(s *ProxyServer, id json.RawMessage, newjob bool) erro } } - t := s.currentBlockTemplate() - resp := JSONStratumReq{ Method: "mining.notify", Params: []interface{}{ @@ -616,9 +529,6 @@ func (cs *Session) sendJob(s *ProxyServer, id json.RawMessage, newjob bool) erro cs.JobDetails.HeaderHash, true, }, - - Height: util.ToHex1(int64(t.Height)), - Algo: s.config.Algo, } return cs.sendTCPReq(resp) @@ -641,10 +551,9 @@ func (s *ProxyServer) broadcastNewJobs() { bcast := make(chan int, 1024) n := 0 - for m := range s.sessions { + for m, _ := range s.sessions { n++ bcast <- n - cs := m // Assign the value to a variable cs to capture the correct Session. go func(cs *Session) { err := cs.pushNewJob(s, &reply) @@ -655,7 +564,7 @@ func (s *ProxyServer) broadcastNewJobs() { } else { s.setDeadline(cs.conn) } - }(cs) + }(m) } log.Printf("Jobs broadcast finished %s", time.Since(start)) } @@ -691,26 +600,17 @@ func (cs *Session) getNotificationResponse(s *ProxyServer) interface{} { result[0] = []string{"mining.notify", randomHex(16), "EthereumStratum/1.0.0"} result[1] = cs.Extranonce - // Additional response data for NiceHash stratum mode - if cs.stratumMode() == NiceHash { - t := s.currentBlockTemplate() - if t != nil { - // Construct the response for NiceHash "mining.notify" - jobID := randomHex(8) - seedHash := t.Seed - headerHash := t.Header - height := util.ToHex1(int64(t.Height)) - // TO DO: Clean up the response structure based on actual data in "t" - - result = []interface{}{ - "mining.notify", - jobID, - seedHash, - headerHash, - height, - } - } + return result +} +func formatEthHashrate(shareDiffCalc int64) string { + units := []string{"H/s", "KH/s", "MH/s", "GH/s", "TH/s", "PH/s"} + var i int + diff := float64(shareDiffCalc) + + for i = 0; i < len(units)-1 && diff >= 1000.0; i++ { + diff /= 1000.0 } - return result + formatted := strconv.FormatFloat(diff, 'f', 2, 64) + return formatted + " " + units[i] }