Browse Source

better logic for when to start the miner

master
mortie 6 years ago
parent
commit
9566cc532c
1 changed files with 15 additions and 5 deletions
  1. 15
    5
      js/stratum-client.js

+ 15
- 5
js/stratum-client.js View File

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

this.waitFor = 2;
this.nounceReady = false;
this.difficultyReady = false;
this.miner = miner;
this.rpc = new RPCConn(ip, port);
}
@@ -15,6 +16,9 @@ class StratumClient {
}

async startWork() {
if (!this.work)
return;

this.log("Starting work", this.work.id);
var res;
try {
@@ -37,23 +41,29 @@ class StratumClient {
merkleBranch: params[4], version: params[5],
nBits: params[6], nTime: params[7], cleanJobs: params[8],
};
this.log("Got work", work.id);

this.work = work;
if (this.ready <= 0)
if (this.difficultyReady && this.nounceReady)
this.startWork();
});
this.rpc.on("mining.set_difficulty", params => {
this.log("difficulty", params[0]);
this.log("Got difficulty", params[0]);
this.miner.setDifficulty(params[0]);

if (--this.waitFor == 0)
if (this.difficultyReady)
return;

this.difficultyReady = true;
if (this.nounceReady)
this.startWork();
});

var sub = await this.rpc.call("mining.subscribe");
this.log("Got nounce", sub[1]);
this.miner.setNounce(sub[1], sub[2]);
if (--this.waitFor == 0)
this.nounceReady = true;
if (this.difficultyReady)
this.startWork();
}


Loading…
Cancel
Save