novitski / bitcoinj

Automatically exported from code.google.com/p/bitcoinj
Apache License 2.0
0 stars 0 forks source link

H2 store: block header hash code is off by 4 bytes #477

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Recently I had an email from Huang GuangYu in China pointing out a possible 
error in the block header code:

// We skip the first 4 bytes because (on prodnet) the minimum target has 4 
0-bytes
byte[] hashBytes = new byte[28];
System.arraycopy(storedBlock.getHeader().getHash().getBytes(), 3, hashBytes, 0, 
28);

If the intention is to skip the first 4 bytes, shouldn't the arraycopy start at 
position 4, not 3?

This code appears in several places within the H2FullPrunedBlockStore (search 
on "skip the first 4 bytes", but may not be causing an immediate problem since 
it is probably internally self-consistent to the store.

Have I (and Huang) missed something obvious here?

Original issue reported on code.google.com by g.rowe.f...@gmail.com on 3 Nov 2013 at 5:58

GoogleCodeExporter commented 9 years ago
Heh, wow that's embarrassing.
Anyway, it doesn't really matter since the probability of two blocks having the 
same 27-bytes in their hash is pretty low...
Still, should be fixed next time the on-disk schema is changed.

Original comment by BlueMatt...@gmail.com on 3 Nov 2013 at 6:03

GoogleCodeExporter commented 9 years ago
No worries - thanks for the really quick response. I'm just glad it's low 
impact. I'll feed back to Huang GuangYu in case he can't see the issue.

Original comment by g.rowe.f...@gmail.com on 3 Nov 2013 at 6:12

GoogleCodeExporter commented 9 years ago

Original comment by mh.in.en...@gmail.com on 24 Dec 2013 at 1:02