Complete sources for a monero webminer.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

234 lines
11 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. # webminerpool
  2. **Complete sources** for a Monero (cryptonight and variants) webminer. **Hard fork ready**.
  3. ###
  4. _The server_ is written in **C#**, **optionally calling C**-routines to check hashes calculated by the clients. It acts as a proxy server for common pools.
  5. _The client_ runs in the browser using javascript and webassembly.
  6. **websockets** are used for the connection between the client and the server, **webassembly** to perform hash calculations, **web workers** for threads.
  7. Thanks to [nierdz](https://github.com/notgiven688/webminerpool/pull/62) there is a **docker** file available. See below.
  8. # Will the hardfork (<span style="color:red">March 2019</span>) be supported?
  9. Yes. Update to the current Master branch and you should be fine. Much work was put into optimizing the miner
  10. once again.
  11. Unfortunately the newest version of cryptonight, cn/r (cnv4), does perform poorly on the browser. To partly compensate for this I added cn-pico/trtl and cn-half/half. If you mine to a pool
  12. which allows autoswitching algorithms (at the moment [moneroocean.stream](https://moneroocean.stream)) webminerpool will automatically
  13. switch to an algorithm which is most profitable at the moment.
  14. ## Update notes: It is beneficial to first update your clients (step_A) to the newest mining script (Version 7, the version number can be found in the "handshake-data" within the source code). Wait a few days till your user base followed (because of browser caching) and then update to the newest server version (step_B). This is recommended because of the possibility that the new server negotiates a mining algorithm with the pool, which is not supported by an old client (and therefore is not forwarded by the server).
  15. ## step_A and step_B have to be performed before March 9th!
  16. # Currently supported algorithms
  17. | # | xmrig short notation | webminerpool internal | description |
  18. | -- | --------------| --------------------------------- | ------------------------------------------------ |
  19. | 1 | cn | algo="cn", variant=-1 | autodetect cryptonight variant (block.major - 6) |
  20. | 2 | cn/0 | algo="cn", variant=0 | original cryptonight |
  21. | 3 | cn/1 | algo="cn", variant=1 | also known as monero7 and cryptonight v7 |
  22. | 4 | cn/2 | algo="cn", variant=2 or 3 | cryptonight variant 2 |
  23. | 5 | cn/r | algo="cn", variant=4 | cryptonight variant 4 also known as cryptonightR |
  24. | 6 | cn-lite | algo="cn-lite", variant=-1 | same as #1 with memory/2, iterations/2 |
  25. | 7 | cn-lite/0 | algo="cn-lite", variant=0 | same as #2 with memory/2, iterations/2 |
  26. | 8 | cn-lite/1 | algo="cn-lite", variant=1 | same as #3 with memory/2, iterations/2 |
  27. | 9 | cn-pico/trtl | algo="cn-pico", variant=2 or 3 | same as #4 with memory/8, iterations/8 |
  28. | 10 | cn-half | algo="cn-half", variant=2 or 3 | same as #4 with memory/1, iterations/2 |
  29. # What is new?
  30. - **March 1, 2019**
  31. - Added cryptonight v4. Hard fork ready!. Added support for cn/half and cn-pico/trtl. Added support for auto-algo switching. (**client-side** / **server-side**)
  32. - **September 27, 2018**
  33. - Added cryptonight v2. Hard fork ready! (**client-side** / **server-side**)
  34. - **June 15, 2018**
  35. - Support for blocks with more than 2^8 transactions. (**client-side** / **server-side**)
  36. - **May 21, 2018**
  37. - Support for multiple open tabs. Only one tab is constantly mining if several tabs/browser windows are open. (**client-side**).
  38. - **May 6, 2018**
  39. - Check if webasm is available. Please update the script. (**client-side**)
  40. - **May 5, 2018**
  41. - Support for multiple websocket servers in the client script (load-distribution).
  42. - **April 26, 2018**
  43. - A further improvement to fully support the [extended stratum protocol](https://github.com/xmrig/xmrig-proxy/blob/dev/doc/STRATUM_EXT.md#mining-algorithm-negotiation) (**server-side**)
  44. - A simple json config-file holding all available pools (**server-side**)
  45. - **April 22, 2018**
  46. - All cryptonight and cryptonight-light based coins are supported in a single miner. [Stratum extension](https://github.com/xmrig/xmrig-proxy/blob/dev/doc/STRATUM_EXT.md#mining-algorithm-negotiation) were implemented: The server now takes pool suggestions (algorithm and variant) into account. Defaults can be specified for each pool - that makes it possible to mine coins like Stellite, Turtlecoin,.. (**client/server-side**)
  47. - Client reconnect time gets larger with failed attempts. (**client-side**)
  48. # Repository Content
  49. ### SDK
  50. The SDK directory contains all client side mining scripts which allow mining in the browser.
  51. #### Minimal working example
  52. ```html
  53. <script src="webmr.js"></script>
  54. <script>
  55. server = "ws://localhost:8181"
  56. startMining("minexmr.com","49kkH7rdoKyFsb1kYPKjCYiR2xy1XdnJNAY1e7XerwQFb57XQaRP7Npfk5xm1MezGn2yRBz6FWtGCFVKnzNTwSGJ3ZrLtHU");
  57. </script>
  58. ```
  59. webmr.js can be found under SDK/miner_compressed.
  60. The startMining function can take additional arguments
  61. ```javascript
  62. startMining(pool, address, password, numThreads, userid);
  63. ```
  64. - pool, this has to be a pool registered at the server.
  65. - address, a valid XMR address you want to mine to.
  66. - password, password for your pool. Often not needed.
  67. - numThreads, the number of threads the miner uses. Use "-1" for auto-config.
  68. - userid, allows you to identify the number of hashes calculated by a user. Can be any string with a length < 200 characters.
  69. To **throttle** the miner just use the global variable "throttleMiner", e.g.
  70. ```javascript
  71. startMining(..);
  72. throttleMiner = 20;
  73. ```
  74. If you set this value to 20, the cpu workload will be approx. 80% (for 1 thread / CPU). Setting this value to 100 will not fully disable the miner but still
  75. calculate hashes with 10% CPU load.
  76. If you do not want to show the user your address or even the password you have to create a *loginid*. With the *loginid* you can start mining with
  77. ```javascript
  78. startMiningWithId(loginid)
  79. ```
  80. or with optional input parameters:
  81. ```javascript
  82. startMiningWithId(loginid, numThreads, userid)
  83. ```
  84. Get a *loginid* by opening *register.html* in SDK/other. You also find a script which enumerates all available pools and a script which shows you the amount of hashes calculated by a *userid*. These files are quite self-explanatory.
  85. #### What are all the *.js files?
  86. SDK/miner_compressed/webmr.js simply combines
  87. 1. SDK/miner_raw/miner.js
  88. 2. SDK/miner_raw/worker.js
  89. 3. SDK/miner_raw/cn.js
  90. Where *miner.js* handles the server-client connection, *worker.js* are web workers calculating cryptonight hashes using *cn.js* - a emscripten generated wrapped webassembly file. The webassembly file can also be compiled by you, see section hash_cn below.
  91. ### Server
  92. The C# server. It acts as proxy between the clients (the browser miners) and the pool server. Whenever several clients use the same credentials (pool, address and password) they get "bundled" into a single pool connection, i.e. only a single connection is seen by the pool server. This measure helps to prevent overloading regular pool servers with many low-hash web miners.
  93. The server uses asynchronous websockets provided by the
  94. [FLECK](https://github.com/statianzo/Fleck) library. Smaller fixes were applied to keep memory usage low. The server code should be able to handle several thousand connections with modest resource usage.
  95. The following compilation instructions apply for linux systems. Windows users have to use Visual Studio to compile the sources.
  96. To compile under linux (with mono and msbuild) use
  97. ```bash
  98. ./build
  99. ```
  100. and follow the instructions. No additional libraries are needed.
  101. ```bash
  102. mono server.exe
  103. ```
  104. should run the server.
  105. Optionally you can compile the C-library **libhash**.so found in *hash_cn*. Place this library in the same folder as *server.exe*. If this library is present the server will make use of it and check hashes which gets submitted by the clients. If clients submit bad hashes ("low diff shares"), they get disconnected. The server occasionally writes ip-addresses to *ip_list*. These addresses should get (temporarily) banned on your server for example by adding them to [*iptables*](http://ipset.netfilter.org/iptables.man.html). The file can be deleted after the ban. See *Firewall.cs* for rules when a client is seen as malicious - submitting wrong hashes is one possibility.
  106. Without a **SSL certificate** the server will open a regular websocket (ws://0.0.0.0:8181). To use websocket secure (ws**s**://0.0.0.0:8181) you should place *certificate.pfx* (a pkcs12 file) into the server directory. The default password which the server uses to load the certificate is "miner". To create a pkcs12 file from regular certificates, e.g. from [*Let's Encrypt*](https://letsencrypt.org/), use the command
  107. ```bash
  108. openssl pkcs12 -export -out certificate.pfx -inkey privkey.pem -in cert.pem -certfile chain.pem
  109. ```
  110. The server should autodetect the certificate on startup and create a secure websocket.
  111. **Attention:** Most linux based systems have a (low) fixed limit of
  112. available file-descriptors configured ("ulimit"). This can cause an
  113. unwanted upper limit for the users who can connect (typical 1000). You
  114. should change this limit if you want to have more connections.
  115. ### hash_cn
  116. The cryptonight hashing functions in C-code. With simple Makefiles (use the "make" command to compile) for use with gcc and emcc - the [emscripten](https://github.com/kripken/emscripten) webassembly compiler. *libhash* should be compiled so that the server can check hashes calculated by the user.
  117. # Dockerization
  118. Find the original pull request with instructions by nierdz [here](https://github.com/notgiven688/webminerpool/pull/62).
  119. Added Dockerfile and entrypoint.sh.
  120. Inside entrypoint.sh, if `$DOMAIN` is provided, a certificate is registered and packed in pkcs12 format to be used with server.exe.
  121. ```bash
  122. cd webminerpool
  123. docker build -t webminerpool .
  124. ```
  125. To run it:
  126. ```bash
  127. docker run -d -p 80:80 -p 8181:8181 -e DOMAIN=mydomain.com webminerpool
  128. ```
  129. The 80:80 bind is used to obtain a certificate.
  130. The 8181:8181 bind is used for server itself.
  131. If you want to bind these ports to a specific IP, you can do this:
  132. ```bash
  133. docker run -d -p xx.xx.xx.xx:80:80 -p xx.xx.xx.xx:8181:8181 -e DOMAIN=mydomain.com webminerpool
  134. ```
  135. You can even use docker-compose, here is a sample snippet:
  136. ```
  137. webminer:
  138. container_name: webminer
  139. image: webminer:1.0
  140. build:
  141. context: ./webminerpool
  142. args:
  143. - DONATION_LEVEL=${WEBMINER_DONATION_LEVEL}
  144. restart: always
  145. ports:
  146. - ${WEBMINER_IP}:80:80
  147. - ${WEBMINER_IP}:8181:8181
  148. environment:
  149. DOMAIN: ${WEBMINER_DOMAIN}
  150. networks:
  151. - my-network
  152. ```
  153. To use this snippet, you need to define `$WEBMINER_DONATION_LEVEL`, `$WEBMINER_DOMAIN` and `$WEBMINER_IP` in a `.env` file.
  154. # Developer Donations
  155. By default a server-side 3% dev-donation is configured. Leaving this fee at the current level is highly appreciated. If you want
  156. to turn it off or just find the content of this repository helpful consider a one time donation, the addresses are as follows:
  157. ```
  158. BTC - 175jHD6ErDhZHoW4u54q5mr98L9KSgm56D
  159. XMR - 49kkH7rdoKyFsb1kYPKjCYiR2xy1XdnJNAY1e7XerwQFb57XQaRP7Npfk5xm1MezGn2yRBz6FWtGCFVKnzNTwSGJ3ZrLtHU
  160. AEON - WmtUFkPrboCKzL5iZhia4iNHKw9UmUXzGgbm5Uo3HPYwWcsY1JTyJ2n335gYiejNysLEs1G2JZxEm3uXUX93ArrV1yrXDyfPH
  161. ```