Title: parsing getwork blockheaders with BitCoinJ Post by: shads on June 24, 2011, 11:59:26 AM So what are the extra bytes?
I've tried feeding the getwork data field into the BitCoinJ Block class for parsing but I get rubbish results: This is the JSON result: Code: { This is what I get from parsing it with BitCoinJ: Code: size: 128 The only thing that seems correct is the nonce. I've tried reversing the bytes but still rubbish. Should I be offsetting perhaps? Title: Re: Block header should be 81 bytes but getwork:data is 128 bytes Post by: kjj on June 24, 2011, 01:26:41 PM The block is right. The parser is wrong. SHA256 works on 64 byte blocks, so messages get padded and salted before hashing.
Title: Re: Block header should be 81 bytes but getwork:data is 128 bytes Post by: shads on June 24, 2011, 01:45:10 PM ok, so do you know if they are padded at the beginning or end? Is it just a simple matter of trimming the byte array? The parser is probably not designed to handle the results of a getwork. According to it's constructor:
/** Constructs a block object from the BitCoin wire format. */ Which probably doesn't include the padding I'm guessing. Title: Re: Block header should be 81 bytes but getwork:data is 128 bytes Post by: kjj on June 24, 2011, 02:20:34 PM I couldn't tell without looking at the function, and I despise Java, so... Hopefully someone familiar with bitcoinj will pop in and help. Maybe change the subject of the thread.
Usually the first problem people run into when trying to parse/hash this stuff is the difference between network byte order and host byte order. Title: Re: Block header should be 81 bytes but getwork:data is 128 bytes Post by: Mike Hearn on June 24, 2011, 04:27:56 PM Yes, that constructor isn't intended to take the output of getwork.
Presumably the problem is the following code from FormatHashBuffers: Code: // Byte swap all the input buffer But what are you trying to do? If you want to build a miner I don't think you don't have to parse the output of getwork. The getwork protocol is something else. Title: Re: parsing getwork blockheaders with BitCoinJ Post by: shads on June 25, 2011, 12:00:18 AM I thought it might be a problem with endianess. Never had to deal with it before in my little java bubble.
Most likely use is to parse the returned getwork to verify it before passing it on upstream. Or possibly even to generate work for downstream clients. I know bitcoinj is really focussed on being an end user client atm so not really built with those sort of things in mind but seemed sensible to try an leverage some of the code and it's useful particularly as a learning exercise. p.s. Mike, the javadoc and comments are great, I've learned more from those than I have from the wiki. Title: Re: parsing getwork blockheaders with BitCoinJ Post by: shads on June 25, 2011, 04:05:47 AM got it... had to brute force it with ever permutation I could think of but finally got an almost result:
Code: public static void checkByteSwapped(String data) { produces: Code: offset: 0 which matches the last block from blockexplorer. The only part that doesn't match up is the difficulty target. Block explorer says: 1379223.4296725 but at least it's progress... Title: Re: parsing getwork blockheaders with BitCoinJ Post by: shads on June 25, 2011, 05:03:57 AM ok so I've just learned about compact form vs long form... and I seem to be decoding difficulty close but not precise:
Code: L.println("************************************************************************"); gives me: Code: ************************************************************************ which is pretty damn close to blockexplorer: 1379223.4296725 It seems odd that difference is very close to 32 (31.1414). Perhaps I've mashed a bit somewhere. Title: Re: parsing getwork blockheaders with BitCoinJ Post by: shads on June 25, 2011, 05:57:40 AM excuse me continuing to talk to myself...
Just notices that my bitcoind client is returning 1379192.28822808 from getdifficulty so it was decoded properly. Odd though that blockexplorer is returning a different difficulty? Title: Re: parsing getwork blockheaders with BitCoinJ Post by: theymos on June 25, 2011, 06:41:40 AM BBE's /q/getdifficulty uses Bitcoin's old difficulty calculation, which has some precision problems. You'll notice that the difficulty reported on block pages (http://blockexplorer.com/block/000000000000028b3c88a2744b602f86ddf9a5ed250c661ad83519b6e198238b) is the same as yours.
|