Title: [PATCH] getblockbycount, getblockbyhash RPCs Post by: jgarzik on August 06, 2010, 07:34:52 AM Gavin's bitcointools are nice for dumping blocks, but they require you to shutdown bitcoind, because bitcoin sets DB_PRIVATE flag, preventing outside users from using the multi-user database :)
See "getblockbycount" branch of git repository https://github.com/jgarzik/bitcoin Here is sample command usage and output for block at height 71995: Code: $ /spare/repo/bitcoin.hacks/bitcoind -datadir=/garz/bitcoin/data getblock 71995 Title: Re: [PATCH] implement getblock RPC command Post by: knightmb on August 06, 2010, 07:47:48 AM Hey cool, you can even see the generation and other transactions in it, nice ;D
Title: Re: [PATCH] implement getblock RPC command Post by: jgarzik on August 07, 2010, 05:11:58 AM Updated patch to v2, with a simple cast fix for 32-bit machines.
Same URL: http://gtf.org/garzik/bitcoin/patch.bitcoin-getblock (http://gtf.org/garzik/bitcoin/patch.bitcoin-getblock) Title: Re: [PATCH] implement getblock RPC command Post by: throughput on August 09, 2010, 12:41:25 PM Oh! You have already implemented the feature I need!
Great! Title: Re: [PATCH] implement getblock RPC command Post by: jgarzik on August 13, 2010, 07:42:34 PM Patch updated for current SVN, r130. Same patch URL, no change in implementation or operation. Title: Re: [PATCH] implement getblock RPC command Post by: jgarzik on September 01, 2010, 06:39:57 PM Patch updated for current SVN, r146, aka the "break patches with a CR/LF policy change" revision. Same patch URL (see top of this thread), no change in implementation or operation. Title: Re: [PATCH] implement getblock RPC command Post by: jgarzik on September 18, 2010, 07:45:08 PM Patch updated to latest SVN.
Title: Re: [PATCH] implement getblock RPC command Post by: Gavin Andresen on September 27, 2010, 05:57:53 PM I've been working on a "monitoraddress" / "monitorblocks" patch, so bitcoind will POST transaction/block information to an arbitrary URL.
And it seems to me "getblock" should be split into "getblockbycount", "getblockbyhash" and "gettransaction". I also have some suggestions for making the naming more consistent: I'd suggest getblockby* return: Code: { Reasoning: blockcount instead of 'height' or 'depth' because getinfo returns "blockcount" getblockbyhash might return a block not on the "best" chain; return blockcount=-1 in that case? version instead of 'ver' because abbrvs shd b avoided (thy cn b hrd to rd/rmbr) only return transaction hashes; if you need more transaction details, call gettransaction. No n_tx (or n_anything) because it is implicit in length of returned array (stuff I'm not sure about: what is 'bits' in the implemented getblock? Is that difficulty? Does anybody really need all the detailed merkle tree info?) I'd suggest gettransaction return: Code: { Reasoning: Returning the CScript string seems like it is both too much detail AND not very useful (I want the bitcoin addresses, NOT OP_DUP 0xblahblahblah ...) "from" is just a list of pointers to previous transaction "to"s confirmations is duplicate info (you could getblockbyhash and then look at its blockcount), but is so useful I think it belongs here. Title: Re: [PATCH] implement getblock RPC command Post by: jgarzik on September 27, 2010, 06:20:46 PM Is there an index that indexes all transaction ids for all blocks?
Or should 'gettransaction' only work for wallet transactions? Title: Re: [PATCH] implement getblock RPC command Post by: Gavin Andresen on September 27, 2010, 07:40:20 PM blkindex.dat contains all the transactions, in records that look like:
key: "tx" + HASH_OF_TRANSACTION value: serialized CTxIndex The CTxIndex points to a record in one of the blk000n.dat files. That does bring up an interesting point, though: if lightweight clients are implemented, they wouldn't be able to support an arbitrary 'gettransaction'. Title: Re: [PATCH] implement getblock RPC command Post by: jgarzik on September 29, 2010, 05:30:52 PM Patch updated to latest SVN, with a few of the suggested gavinchanges:
Title: Re: [PATCH] implement getblock RPC command Post by: mizerydearia on October 14, 2010, 09:27:46 PM Just a quick note that this patch is not compatible with http://bitcointalk.org/index.php?topic=1319.msg15065#msg15065
Quote <gavinandresen> I reimplemented getblock in the monitor* patch <gavinandresen> (so it returned the same JSON data structures as monitorblock ) <necrodearia> Ah, so your patch makes getblock patch deprecated, right? <gavinandresen> Yup <necrodearia> Yay! ^_^ Title: Re: [PATCH] implement getblock RPC command Post by: jgarzik on October 15, 2010, 12:40:53 AM That is incorrect.
The content in gavin's patch makes my getblock largely redundant -- but they are not incompatible. Title: Re: [PATCH] implement getblock RPC command Post by: mizerydearia on October 15, 2010, 02:49:25 AM That is incorrect. The content in gavin's patch makes my getblock largely redundant -- but they are not incompatible. Hummm... I was able to use one patch or the other. When trying to use both patches, I couldn't apply the patches. Perhaps I did something wrong. I will try again. When applying gavin's monitor patch first and your getblock patch second, the following error occurs: http://pastebin.com/CUr1cvgS When applying your getblock patch first and gavin's monitor patch second, the following error occurs: http://pastebin.com/6UY4dscY Title: Re: [PATCH] implement getblock RPC command Post by: theymos on October 15, 2010, 03:50:24 AM Hummm... I was able to use one patch or the other. When trying to use both patches, I couldn't apply the patches. Perhaps I did something wrong. I will try again. patch is not meant to be used blindly. You're supposed to look at the reject file manually and figure it out. The problem is caused when trying to patch the section of rpc.cpp around line 1330. Both patches try to apply their changes to the bottom of the list, with context looking up. They modify each other's context. To fix this, they should be applied to the top looking only up or the bottom looking only down. (Not sure if you can actually do this, however.) Title: Re: [PATCH] implement getblock RPC command Post by: jgarzik on October 21, 2010, 07:36:49 PM Patch updated to latest SVN (v0.3.14).
Title: Re: [PATCH] implement getblock RPC command Post by: theymos on November 07, 2010, 05:00:05 AM I noticed a bug in getblock (and bitcointools). Block 67300 is missing several transactions when compared to the output of Bitcoin's printblock, and the hash is also wrong.
I ran into the bug while parsing the entire chain: transaction e7a995 is spent in 67301, but according to getblock data that transaction was never made. Title: Re: [PATCH] implement getblock RPC command Post by: jgarzik on November 07, 2010, 04:08:50 PM I noticed a bug in getblock (and bitcointools). Block 67300 is missing several transactions when compared to the output of Bitcoin's printblock, and the hash is also wrong. I ran into the bug while parsing the entire chain: transaction e7a995 is spent in 67301, but according to getblock data that transaction was never made. hmmmm. That's quite strange, considering the code simply loops over all 'vin' and 'vout', duplicating the code pattern used elsewhere to dump a block to the debug log. Title: Re: [PATCH] implement getblock RPC command Post by: theymos on November 11, 2010, 02:36:39 AM ArtForz figured out that this is caused because getblock is showing an orphan block at that position instead of the real block. Deleting the block database files fixes it because you won't re-download orphan blocks.
Title: Re: [PATCH] implement getblock RPC command Post by: theymos on November 11, 2010, 05:03:09 PM I think that this can be fixed by changing this:
Code: if (pindex->nHeight == height) { to this: Code: if (pindex->nHeight == height && pindex->IsInMainChain()) { jgarzik: I don't have any orphan blocks right now, so can you test this on your block 90539 and compare it to the real one (http://theymos.ath.cx:64150/bbe/rawblock/00000000000c80a30b1e4242c30a6795b7fbcc2b1ce6e59132fd11fd47c729fd)? Title: Re: [PATCH] implement getblock RPC command Post by: theymos on November 13, 2010, 08:31:36 AM An orphan block was created at 91405, and I was able to verify that my change to getblock fixes the problem. I suggest that it be included in the patch.
Title: Re: [PATCH] implement getblock RPC command Post by: jgarzik on November 13, 2010, 07:20:35 PM Patch updated to latest SVN + theymos's fix. See top of thread for URL.
Title: Re: [PATCH] implement getblock RPC command Post by: jgarzik on November 23, 2010, 12:05:11 AM Updated to SVN r188 (accounts).
Title: Re: [PATCH] implement getblock RPC command Post by: theymos on November 27, 2010, 01:48:16 PM To get block/tx size, you can add this to block processing:
Code: obj.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK))); And add this to tx processing: Code: txobj.push_back(Pair("size", (int)::GetSerializeSize(block.vtx[i], SER_NETWORK))); I don't know that this is the best way of doing this (I'm not really familiar with C++). That cast to integer is probably not necessary, but it works and I don't want to test another version (overflow is impossible for the foreseeable future). Title: Re: [PATCH] implement getblock RPC command Post by: jgarzik on November 27, 2010, 07:04:13 PM Patch updated to latest SVN, with additional block/TX size output.
Title: Re: [PATCH] implement getblock RPC command Post by: jgarzik on December 02, 2010, 05:50:44 AM Patch updated for latest SVN.
Title: Re: [PATCH] implement getblock RPC command Post by: Luke-Jr on January 29, 2011, 03:07:49 PM Any reason this shouldn't be merged with the main tree?
Title: Re: [PATCH] implement getblock RPC command Post by: jgarzik on February 24, 2011, 12:44:18 AM Patch updated to latest git. See URL at top of thread.
Title: Re: [PATCH] implement getblock RPC command Post by: fahhem on April 23, 2011, 11:11:26 PM Patch updated to latest git. See URL at top of thread. I updated it to the latest git. http://pastebin.com/FdrYDVF5 I made it as a git format-patch so it can be applied using git-apply. To make it a normal patch, just delete the first 9 lines. Title: Re: [PATCH] getblockbycount, getblockbyhash RPCs Post by: xf2_org on May 15, 2011, 07:05:20 AM getblockbycount RPC updated to latest git. As the top post notes, this work is now maintained at github, jgarzik/bitcoin's "getblockbycount" branch. Notable addition: new RPC "getblockbyhash" added, to retrieve block by block header hash. Title: Re: [PATCH] getblockbycount, getblockbyhash RPCs Post by: error on May 23, 2011, 03:01:47 AM Any reason this shouldn't be merged with the main tree? Seconded. Title: Re: [PATCH] getblockbycount, getblockbyhash RPCs Post by: davout on June 06, 2011, 12:19:21 PM Could it be possible that getblockbyhash returns an "orphan_block" flag ?
See this example that I generated on testnet : Code: david@bankbox:~/rails/bitcoin-pool$ bitcoin getblockbyhash 00000000003d7e088aba9d12e34cc3f75cd10ffa48a026fa535c0771e5c1b0c8 Nothing wrong here, but when I want to get details about the generation tx this is what I get : Code: david@bankbox:~/rails/bitcoin-pool$ bitcoin gettransaction 46689b6020b67534e63fb81ddf379bb666a96ff55de27f8eebe8dffc924c09e7 Also this should get pulled in, it's incredibly useful when building decent bitcoin handling apps. Title: Re: [PATCH] getblockbycount, getblockbyhash RPCs Post by: xf2_org on June 11, 2011, 02:58:41 AM getblockbycount / getblockbyhash RPCs updated to latest git.
Title: Re: [PATCH] getblockbycount, getblockbyhash RPCs Post by: Grouver (BtcBalance) on June 29, 2011, 08:11:02 PM Hello,
Thank you so much for developing this patch. I am trying to install it right now on my bitcoin server. I followed your instructions that are in the manual and all went fine. I tried: Code: bitcoin getblockcount Wich obviously worked flawlessly. Only when I restarted my Linux server and try for instance: Code: bitcoin getblock 71995 I get the error: Code: error: {"code":-32601,"message":"Method not found"} I builded the patch with wxWidgets. Thanks again. Title: Re: [PATCH] getblockbycount, getblockbyhash RPCs Post by: jgarzik on June 29, 2011, 11:39:33 PM Only when I restarted my Linux server and try for instance: Code: bitcoin getblock 71995 I get the error: Code: error: {"code":-32601,"message":"Method not found"} That's because it is called 'getblockbycount' not 'getblock' these days. Title: Re: [PATCH] getblockbycount, getblockbyhash RPCs Post by: Grouver (BtcBalance) on June 30, 2011, 05:46:46 AM Right, got it to work. (Thanks to the bitcoin-dev channel)
Right now I get this: Code: array Why are the IN and OUT arrays empty? When I check the startpost I see there is a another array in there? EDIT: Also I am not sure what I should do with Berkeley DB. The readme told me to make but thats all. How do I need to create and connect the DB to the Bitcoin server? Or am I tottaly misunderstanding this. Title: Re: [PATCH] getblockbycount, getblockbyhash RPCs Post by: TeraPool on July 20, 2011, 07:08:27 AM Any reason this shouldn't be merged with the main tree? Seconded. Thirded! This is amazing stuff though, thanks jgarzik! Perfect for the novice pool operator. Can somebody please explain to me how to add this patch to the main bitcoind client? I have never done a patch before :S Title: Re: [PATCH] getblockbycount, getblockbyhash RPCs Post by: Furyan on July 21, 2011, 04:09:57 PM Any reason this shouldn't be merged with the main tree? Seconded. Thirded! This is amazing stuff though, thanks jgarzik! Perfect for the novice pool operator. Can somebody please explain to me how to add this patch to the main bitcoind client? I have never done a patch before :S You need the diff to apply the patch. This should be against 0.3.24 source but I haven't checked. You can get the diff at github (sort of) - https://github.com/jgarzik/bitcoin/commit/168f5a4b30d5307281eb5bc4447afb04348e9f5d#diff-0 Copy that into a file (e.g. diff.txt), then run Code: patch -i diff.txt rpc.cpp You may want to add Code: -r rejects.txt to catch any rejections that may happen so you can fix them. Will be doing this when I get home, I like this patch. Edit: Actually it looks like JoelKatz' pull request has the complete diff.... Unless jgarzik would be so kind as to generate one for us :) (Reason I need a diff is that I have other patches applied to my local copy - most of JoelKatz' work). Title: Re: [PATCH] getblockbycount, getblockbyhash RPCs Post by: Furyan on July 21, 2011, 04:50:57 PM Oh, ok, this is the latest: https://github.com/jgarzik/bitcoin/commit/168f5a4b30d5307281eb5bc4447afb04348e9f5d.patch But you'd need a unified diff of all changes to that file. There's a way to do that using git on the command line but I'm not familiar with it. Edit: Here you go. This is against the 0.3.24 release version so if you've made other custom changes you'll need to apply the patch more carefully. Code: --- rpc.cpp 2011-07-21 11:37:38.000000000 -0700 I suggest you use the -b flag to patch to make a backup of your rpc.cpp. Works great! Title: Re: [PATCH] getblockbycount, getblockbyhash RPCs Post by: TeraPool on July 21, 2011, 09:56:24 PM Thank you incredibly Furyan.
Title: Re: [PATCH] getblockbycount, getblockbyhash RPCs Post by: Furyan on July 22, 2011, 11:47:21 AM Thank you incredibly Furyan. Glad to help :) Now if I can get Gavin's Monitor patch in there... much more invasive and stomps on some patches I've already applied.. Title: Re: [PATCH] getblockbycount, getblockbyhash RPCs Post by: JoelKatz on November 02, 2011, 11:07:36 PM Doesn't this code access mapBlockIndex without holding the cs_main lock? If that's legal, what protects mapBlockIndex? If that's illegal, isn't the patch broken? (If this question is obsolete because there's a newer version of the patch, where can I find it?)
|