So I have a mining pool that is able to call RPC methods from my node. I can connect my miners to my pool only now I am stuck at the part where I need to sent/validate work to/from the miner.
I'm trying to make use of the code of this repo and I saw the following code:
BlockTemplate.prototype = {
nextBlob: function(){
this.buffer.writeUInt32BE(++this.extraNonce, this.reserveOffset);
return cnUtil.convert_blob(this.buffer).toString('hex');
}
};
I assume the above code hashes the blocktemplate_blob
or blockhashing_blob
for the job get_block_template
?
The steps for sending work to a miner is:
- Call
get_block_template
- Add a id (to id the miner) in the reserved_space (which is preserved in the
get_block_template
). Is this in hex? - Add a starting nonce & difficulty in the block template
- Hash the edited block_template and sent it to the miner?
Questions 1: Are these stepts correct?
To verify the hash the following steps are:
- Do the hashes match? (which hashes?)
- Does the hash meet the network difficulty? (How to calculate this from a hash?)
- Is this the first time this hash is submitted?
Questions 2: See 3 point above :)
If the hash is submitted and valid then:
- Calculate the new diff(how is this done?) which is set in the new job
- Calculate the share (the share is equal to the difficulty), if a block reward is found it would be something like this ((blockReward / allShares) * minerShare)?
This code has the function to calc the new diff?
if (avg > VarDiff.tMax && this.difficulty > options.minDiff){
newDiff = options.targetTime / avg * this.difficulty;
newDiff = newDiff > options.minDiff ? newDiff : options.minDiff;
direction = -1;
}
else if (avg < VarDiff.tMin && this.difficulty < options.maxDiff){
newDiff = options.targetTime / avg * this.difficulty;
newDiff = newDiff < options.maxDiff ? newDiff : options.maxDiff;
direction = 1;
}
else{
return;
}
if (Math.abs(newDiff - this.difficulty) / this.difficulty * 100 > options.maxJump){
var change = options.maxJump / 100 * this.difficulty * direction;
newDiff = this.difficulty + change;
}
The config for the code is
"varDiff": {
"minDiff": 2,
"maxDiff": 100000,
"targetTime": 100,
"retargetTime": 30,
"variancePercent": 30,
"maxJump": 100
},
Can someone explain the last four?