Browse Source

work is now properly queued

master
mortie 6 years ago
parent
commit
4adeb63ba3
2 changed files with 17 additions and 5 deletions
  1. 3
    1
      js/miner-cpu/index.js
  2. 14
    4
      js/stratum-client.js

+ 3
- 1
js/miner-cpu/index.js View File

@@ -81,7 +81,9 @@ function mine(

childs.forEach(child => {
child.on("exit", code => {
console.error("Child exited with code", code);
if (code != null)
console.error("Child exited with code", code);

if (code === 0) {
childsLeft -= 1;
childs.forEach(x => x !== child && x.kill());

+ 14
- 4
js/stratum-client.js View File

@@ -4,6 +4,8 @@ class StratumClient {
constructor(ip, port, miner) {
this.name = ip+":"+port;

this.queue = [];
this.working = false;
this.nounceReady = false;
this.difficultyReady = false;
this.miner = miner;
@@ -16,16 +18,24 @@ class StratumClient {
}

async startWork() {
if (!this.work)
if (this.working)
return;
if (this.queue.length === 0)
return;

var work = this.queue.shift();

this.log("Starting work", this.work.id);
this.log("Starting work", work.id);
this.working = true;
var res;
try {
res = await this.miner.startWork(this.work);
res = await this.miner.startWork(work);
} catch (err) {
console.trace(err);
return;
} finally {
this.working = false;
this.startWork();
}
this.log("Work done,", res.toString("hex"));
}
@@ -43,7 +53,7 @@ class StratumClient {
};
this.log("Got work", work.id);

this.work = work;
this.queue.push(work);
if (this.difficultyReady && this.nounceReady)
this.startWork();
});

Loading…
Cancel
Save