1

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:

  1. Callget_block_template
  2. Add a id (to id the miner) in the reserved_space (which is preserved in the get_block_template). Is this in hex?
  3. Add a starting nonce & difficulty in the block template
  4. 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:

  1. Do the hashes match? (which hashes?)
  2. Does the hash meet the network difficulty? (How to calculate this from a hash?)
  3. Is this the first time this hash is submitted?

Questions 2: See 3 point above :)

If the hash is submitted and valid then:

  1. Calculate the new diff(how is this done?) which is set in the new job
  2. 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?

1
  • That's a lot of questions. In future, please refer to the help.
    – jtgrassie
    Dec 11, 2022 at 19:16

1 Answer 1

1

The code you reference is woefully outdated and unmaintained, but here you go anyway.

I assume the above code hashes the blocktemplate_blob or blockhashing_blob for the job get_block_template?

No. What that code (the nextBlob function) is doing is getting a new block hashing blob for the job. It doesn't hash a block template, rather creates a blob of data that the miner can hash.

The steps for sending work to a miner is:

  1. Call get_block_template

The pool does not call get_block_template every time it creates a job. It only fetches a block template when the network height changes or it wants to refresh the block template. The fetched block template is then copied and cached to create jobs based off it, and used later when validating shares.

  1. Add a id (to id the miner) in the reserved_space (which is preserved in the get_block_template). Is this in hex?

The miner ID is not added into the block template, it's added to the job.

  1. Add a starting nonce & difficulty in the block template

No, "starting nonce" is not added to anything, and "difficulty" is not changed from the cached block template (it's the difficulty of the next block). The target (which is the job difficulty) is added to the job.

  1. Hash the edited block_template and sent it to the miner?

No. The pool is not "hash"ing the block template here, see above.

To verify the hash the following steps are:

  1. Do the hashes match? (which hashes?)

The submitted hash and the hash the pool produces for the job (based on the job's cached template and submitted nonce).

  1. Does the hash meet the network difficulty? (How to calculate this from a hash?)

A hash is just a big number (as is the block difficulty). The code you reference checks here.

If the hash is submitted and valid then:

  1. Calculate the new diff(how is this done?) which is set in the new job

"new diff" here is the miner difficulty, used for setting future job target. A pool using "vardiff" calculates this "new diff" based on the time it took the miner to submit past job difficulties.

  1. 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)?

By "share" here, I presume you mean the share of the reward the miner would receive if the block is mined by the pool. The code you reference stores a score for each valid submitted share ("share" here meaning submitted work). It records this score in the function recordShareData and then uses it when the block is paid out (when it's matured) in blockUnlocker.js.

The config for the code is... Can someone explain the last four?

They are documented in the README:

"targetTime": 100, //Try to get 1 share per this many seconds
"retargetTime": 30, //Check to see if we should retarget every this many seconds
"variancePercent": 30, //Allow time to vary this % from target without retargeting
"maxJump": 100 //Limit diff percent increase/decrease in a single retargetting
2
  • Hmm alright, thanks for the response. There is one thing I don't understand. According to this topic monero.stackexchange.com/questions/11286/… the job for the miner should include: blockheader data, merkle tree hash and the tx count. But where is target difficulty?
    – J_P
    Dec 13, 2022 at 13:51
  • "the job for the miner should include..." <- That's in the block hashing blob. "But where is target difficulty?" <- Set as the target on the job (ref).
    – jtgrassie
    Dec 13, 2022 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.