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

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


this.waitFor = 2;
this.nounceReady = false;
this.difficultyReady = false;
this.miner = miner; this.miner = miner;
this.rpc = new RPCConn(ip, port); this.rpc = new RPCConn(ip, port);
} }
} }


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

this.log("Starting work", this.work.id); this.log("Starting work", this.work.id);
var res; var res;
try { try {
merkleBranch: params[4], version: params[5], merkleBranch: params[4], version: params[5],
nBits: params[6], nTime: params[7], cleanJobs: params[8], nBits: params[6], nTime: params[7], cleanJobs: params[8],
}; };
this.log("Got work", work.id);


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


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

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


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



Loading…
Cancel
Save