Browse Source

finalize 1

notgiven688 2 years ago
3 changed files with 218 additions and 32 deletions
  1. +0
  2. +217
  3. +1

+ 0
- 1 View File

@ -201,4 +201,3 @@ to turn it off or just find the content of this repository helpful consider a on
- BTC - 175jHD6ErDhZHoW4u54q5mr98L9KSgm56D
- XMR - 49kkH7rdoKyFsb1kYPKjCYiR2xy1XdnJNAY1e7XerwQFb57XQaRP7Npfk5xm1MezGn2yRBz6FWtGCFVKnzNTwSGJ3ZrLtHU
- AEON - WmtUFkPrboCKzL5iZhia4iNHKw9UmUXzGgbm5Uo3HPYwWcsY1JTyJ2n335gYiejNysLEs1G2JZxEm3uXUX93ArrV1yrXDyfPH

+ 217
- 0 View File

@ -0,0 +1,217 @@
# webminerpool
**Complete sources** for a Monero (cryptonight/cryptonight-lite) webminer. **Hard fork ready**.
_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.
_The client_ runs in the browser using javascript and webassembly.
**websockets** are used for the connection between the client and the server, **webassembly** to perform hash calculations, **web workers** for threads.
Thanks to [nierdz]( there is a **docker** file available. See below.
# Will the hardfork (<span style="color:red">March 2019</span>) be supported?
Yes. Update to the current Master branch and you should be fine. Much work was put into optimizing the miner
once again.
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
which allows autoswitching algorithms (at the moment webminerpool will automatically
switch to an algorithm which is most profitable at the moment.
## Update notes: It is beneficial to first update your clients (stepA) 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 userbase followed (because of browser caching) and then update to the newest server version (stepB). This is recommended because of the possibility that the new server negotiates a mining algorithm with the pool, which is not yet supported by on old client (and therefore is not forwarded to the client).
## StepA and StepB have to be performed before March 9th!
# What is new?
- **March 1, 2019**
- Added cryptonight v4. Hard fork ready! (**client-side** / **server-side**). Added support for cn/half and cn-pico/trtl. Added support for auto-algo switching.
- **September 27, 2018**
- Added cryptonight v2. Hard fork ready! (**client-side** / **server-side**).
- **June 15, 2018**
- Support for blocks with more than 2^8 transactions. (**client-side** / **server-side**).
- **May 21, 2018**
- Support for multiple open tabs. Only one tab is constantly mining if several tabs/browser windows are open. (**client-side**).
- **May 6, 2018**
- Check if webasm is available. Please update the script. (**client-side**).
- **May 5, 2018**
- Support for multiple websocket servers in the client script (load-distribution).
- **April 26, 2018**
- A further improvement to fully support the [extended stratum protocol]( (**server-side**).
- A simple json config-file holding all available pools (**server-side**).
- **April 22, 2018**
- All cryptonight and cryptonight-light based coins are supported in a single miner. [Stratum extension]( 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**)
- Client reconnect time gets larger with failed attempts. (**client-side**)
# Repository Content
### SDK
The SDK directory contains all client side mining scripts which allow mining in the browser.
#### Minimal working example
<script src="webmr.js"></script>
server = "ws://localhost:8181"
webmr.js can be found under SDK/miner_compressed.
The startMining function can take additional arguments
startMining(pool, address, password, numThreads, userid);
- pool, this has to be a pool registered at the server.
- address, a valid XMR address you want to mine to.
- password, password for your pool. Often not needed.
- numThreads, the number of threads the miner uses. Use "-1" for auto-config.
- userid, allows you to identify the number of hashes calculated by a user. Can be any string with a length < 200 characters.
To **throttle** the miner just use the global variable "throttleMiner", e.g.
throttleMiner = 20;
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
calculate hashes with 10% CPU load.
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
or with optional input parameters:
startMiningWithId(loginid, numThreads, userid)
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.
#### What are all the *.js files?
SDK/miner_compressed/webmr.js simply combines
1. SDK/miner_raw/miner.js
2. SDK/miner_raw/worker.js
3. SDK/miner_raw/cn.js
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.
### Server
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.
The server uses asynchronous websockets provided by the
[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.
The following compilation instructions apply for linux systems. Windows users have to use Visual Studio to compile the sources.
To compile under linux (with mono and msbuild) use
and follow the instructions. No additional libraries are needed.
mono server.exe
should run the server.
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*]( 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.
Without a **SSL certificate** the server will open a regular websocket (ws:// To use websocket secure (ws**s**:// 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*](, use the command
openssl pkcs12 -export -out certificate.pfx -inkey privkey.pem -in cert.pem -certfile chain.pem
The server should autodetect the certificate on startup and create a secure websocket.
**Attention:** Most linux based systems have a (low) fixed limit of
available file-descriptors configured ("ulimit"). This can cause an
unwanted upper limit for the users who can connect (typical 1000). You
should change this limit if you want to have more connections.
### hash_cn
The cryptonight hashing functions in C-code. With simple Makefiles (use the "make" command to compile) for use with gcc and emcc - the [emscripten]( webassembly compiler. *libhash* should be compiled so that the server can check hashes calculated by the user.
# Dockerization
Find the original pull request with instructions by nierdz [here](
Added Dockerfile and
Inside, if `$DOMAIN` is provided, a certificate is registered and packed in pkcs12 format to be used with server.exe.
cd webminerpool
docker build -t webminerpool .
To run it:
docker run -d -p 80:80 -p 8181:8181 -e webminerpool
The 80:80 bind is used to obtain a certificate.
The 8181:8181 bind is used for server itself.
If you want to bind these ports to a specific IP, you can do this:
docker run -d -p xx.xx.xx.xx:80:80 -p xx.xx.xx.xx:8181:8181 -e webminerpool
You can even use docker-compose, here is a sample snippet:
container_name: webminer
image: webminer:1.0
context: ./webminerpool
restart: always
- ${WEBMINER_IP}:80:80
- ${WEBMINER_IP}:8181:8181
- my-network
To use this snippet, you need to define `$WEBMINER_DONATION_LEVEL`, `$WEBMINER_DOMAIN` and `$WEBMINER_IP` in a `.env` file.
# Developer Donations
By default a server-side 3% dev-donation is configured. Leaving this fee at the current level is highly appreciated. If you want
to turn it off or just find the content of this repository helpful consider a one time donation, the addresses are as follows:
- BTC - 175jHD6ErDhZHoW4u54q5mr98L9KSgm56D
- XMR - 49kkH7rdoKyFsb1kYPKjCYiR2xy1XdnJNAY1e7XerwQFb57XQaRP7Npfk5xm1MezGn2yRBz6FWtGCFVKnzNTwSGJ3ZrLtHU
- AEON - WmtUFkPrboCKzL5iZhia4iNHKw9UmUXzGgbm5Uo3HPYwWcsY1JTyJ2n335gYiejNysLEs1G2JZxEm3uXUX93ArrV1yrXDyfPH

+ 1
- 31
server/Server/PoolConnection.cs View File

@ -119,7 +119,6 @@ namespace Server
private static void ReceiveCallback(IAsyncResult result)
PoolConnection mypc = result.AsyncState as PoolConnection;
TcpClient client = mypc.TcpClient;
@ -139,7 +138,6 @@ namespace Server
if (bytesread == 0) // disconnected
// slow that down a bit to avoid negative feedback loop
Task.Run(async delegate
@ -154,10 +152,8 @@ namespace Server
json = Encoding.ASCII.GetString(mypc.ReceiveBuffer, 0, bytesread);
networkStream.BeginRead(mypc.ReceiveBuffer, 0, mypc.ReceiveBuffer.Length, new AsyncCallback(ReceiveCallback), mypc);
catch { return; }
@ -229,7 +225,6 @@ namespace Server
ReceiveJob(ev, mypc.LastJob, mypc.LastSolved);
else if (msg.ContainsKey("method") && msg["method"].GetString() == "job")
@ -246,7 +241,6 @@ namespace Server
// extended stratum
//if (!lastjob.ContainsKey("variant")) lastjob.Add("variant", mypc.DefaultVariant);
if (!lastjob.ContainsKey("algo")) lastjob.Add("algo", mypc.DefaultAlgorithm);
if (!AlgorithmHelper.NormalizeAlgorithmAndVariant(lastjob))
@ -266,7 +260,6 @@ namespace Server
ReceiveJob(ev, mypc.LastJob, mypc.LastSolved);
@ -274,7 +267,6 @@ namespace Server
// who knows?
ReceiveError(mypc.LastSender, msg);
@ -286,13 +278,11 @@ namespace Server
private static void ConnectCallback(IAsyncResult result)
PoolConnection mypc = result.AsyncState as PoolConnection;
TcpClient client = mypc.TcpClient;
if (!mypc.Closed && client.Connected)
NetworkStream networkStream = client.GetStream();
@ -311,17 +301,13 @@ namespace Server
string msg5 = ",\"id\":1}";
string msg = msg0 + mypc.Login + msg1 + mypc.Password + msg2 + msg3 + msg4 + msg5 + "\n";
mypc.Send(mypc.LastSender, msg);
catch { return; }
// slow that down a bit
Task.Run(async delegate
await Task.Delay(TimeSpan.FromSeconds(4));
@ -330,7 +316,6 @@ namespace Server
foreach (Client ev in cllist)
Disconnect(ev, "can not connect to pool.");
@ -342,7 +327,6 @@ namespace Server
if (connection.WebClients.Count == 0)
connection.Closed = true;
@ -359,7 +343,6 @@ namespace Server
Console.WriteLine("{0}: closed a pool connection.", client.WebSocket.ConnectionInfo.Id);
@ -372,7 +355,6 @@ namespace Server
public static void CheckPoolConnection(PoolConnection connection)
if (connection.Closed) return;
if ((DateTime.Now - connection.LastInteraction).TotalMinutes < 10)
@ -389,25 +371,21 @@ namespace Server
try { connection.TcpClient.Close(); } catch { }
try { connection.TcpClient.Client.Close(); } catch { }
connection.ReceiveBuffer = null;
connection.ReceiveBuffer = null;
connection.LastInteraction = DateTime.Now;
connection.PoolId = "";
connection.LastJob = null;
connection.TcpClient = new TcpClient();
Fleck.SocketExtensions.SetKeepAlive(connection.TcpClient.Client, 60000, 1000);
connection.TcpClient.Client.ReceiveBufferSize = 4096 * 2;
try { connection.TcpClient.BeginConnect(connection.Url, connection.Port, new AsyncCallback(ConnectCallback), connection); } catch { }
public static PoolConnection CreatePoolConnection(Client client, string url, int port, string login, string password)
string credential = url + port.ToString() + login + password;
PoolConnection lpc, mypc = null;
@ -422,17 +400,14 @@ namespace Server
credential += batchCounter.ToString();
if (mypc == null)
CConsole.ColorInfo(() =>
Console.WriteLine("{0}: initiated new pool connection", client.WebSocket.ConnectionInfo.Id);
Console.WriteLine("{0} {1} {2}", login, password, url);
mypc = new PoolConnection();
mypc.Credentials = credential;
mypc.LastSender = client;
@ -452,13 +427,9 @@ namespace Server
Connections.TryAdd(credential, mypc);
try { mypc.TcpClient.Client.BeginConnect(url, port, new AsyncCallback(ConnectCallback), mypc); } catch { }
Console.WriteLine("{0}: reusing pool connection", client.WebSocket.ConnectionInfo.Id);
@ -471,7 +442,6 @@ namespace Server
client.PoolConnection = mypc;
return mypc;