Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: host does the blockHasher code works? #154

Open
zefirka opened this issue Jul 11, 2018 · 2 comments
Open

Question: host does the blockHasher code works? #154

zefirka opened this issue Jul 11, 2018 · 2 comments

Comments

@zefirka
Copy link

zefirka commented Jul 11, 2018

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
Copy link
Author

zefirka commented Jul 12, 2018

@zone117x @foxer666 @devnull-ed

Guys, can someone explain?

@zone117x
Copy link
Owner

zone117x commented Jul 12, 2018

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:

var headerHash = hashDigest(headerBuffer, nTimeInt);

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:

SubmitBlock(blockHex, function(){

The full block hash is only used to validate that the block was accepted via the daemon rpc, see here:

function CheckBlockAccepted(blockHash, callback){

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants