node-stratum-pool icon indicating copy to clipboard operation
node-stratum-pool copied to clipboard

Question: host does the blockHasher code works?

Open zefirka opened this issue 7 years ago • 2 comments

I found this block of code and was very surprised when it works correctly.

Can somebody explain me why this works? default case in switch-case block is unreachable code because of breaks lack. Which means that by default block header's hashing by SHA256D algo. Is this what it was supposed to be? ForIf we choose, for example, DOGE which uses scrypt (POW) then in that switch-case we'll fall into sha1 case, which seems illogical.

zefirka avatar Jul 11 '18 11:07 zefirka

@zone117x @foxer666 @devnull-ed

Guys, can someone explain?

zefirka avatar Jul 12 '18 19:07 zefirka

This is an interesting case. I don't really remember this code (it was 4 years ago), but after looking through it I think it works because of:

The full block hash is not the hash algorithm that matters. Its the block header hash which miners calculate and which most altcoins even bother changing. See here where block header hash is used for difficulty validation: https://github.com/zone117x/node-stratum-pool/blob/4f298c3ead7651646c27a30601fcdbf6512b367a/lib/jobManager.js#L225

The full block hex is what is gets submitted to the daemon and the daemon does its own hashing and validation on the block, see here: https://github.com/zone117x/node-stratum-pool/blob/4f298c3ead7651646c27a30601fcdbf6512b367a/lib/pool.js#L322

The full block hash is only used to validate that the block was accepted via the daemon rpc, see here: https://github.com/zone117x/node-stratum-pool/blob/4f298c3ead7651646c27a30601fcdbf6512b367a/lib/pool.js#L597

From what I can remember - most altcoins don't change the hash algorithm used in any of the other areas. Which is why that switch case statement is very selective with which coins it uses a different full block hash algo for. Apparently it is/was so rare for altcoins to change it that it was never necessary to add that configuration explicitly to the coin.json options.

So in other words - almost all altcoins use sha256d for hashing everything except for the block header.

zone117x avatar Jul 12 '18 20:07 zone117x