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



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

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

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

constructor(ip, port, miner) { constructor(ip, port, miner) {
this.name = ip+":"+port; this.name = ip+":"+port;


this.queue = [];
this.working = false;
this.nounceReady = false; this.nounceReady = false;
this.difficultyReady = false; this.difficultyReady = false;
this.miner = miner; this.miner = miner;
} }


async startWork() { async startWork() {
if (!this.work)
if (this.working)
return; 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; var res;
try { try {
res = await this.miner.startWork(this.work);
res = await this.miner.startWork(work);
} catch (err) { } catch (err) {
console.trace(err); console.trace(err);
return; return;
} finally {
this.working = false;
this.startWork();
} }
this.log("Work done,", res.toString("hex")); this.log("Work done,", res.toString("hex"));
} }
}; };
this.log("Got work", work.id); this.log("Got work", work.id);


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

Loading…
Cancel
Save