Open zefirka opened 6 years ago
@zone117x @foxer666 @devnull-ed
Guys, can someone explain?
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.
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 ofbreak
s 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 usesscrypt
(POW) then in that switch-case we'll fall intosha1
case, which seems illogical.