theymos
Administrator
Legendary
Offline
Activity: 5348
Merit: 13316
|
|
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.
|
1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
|
|
|
jgarzik (OP)
Legendary
Offline
Activity: 1596
Merit: 1099
|
|
November 13, 2010, 07:20:35 PM |
|
Patch updated to latest SVN + theymos's fix. See top of thread for URL.
|
Jeff Garzik, Bloq CEO, former bitcoin core dev team; opinions are my own. Visit bloq.com / metronome.io Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
|
|
|
jgarzik (OP)
Legendary
Offline
Activity: 1596
Merit: 1099
|
|
November 23, 2010, 12:05:11 AM |
|
Updated to SVN r188 (accounts).
|
Jeff Garzik, Bloq CEO, former bitcoin core dev team; opinions are my own. Visit bloq.com / metronome.io Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
|
|
|
theymos
Administrator
Legendary
Offline
Activity: 5348
Merit: 13316
|
|
November 27, 2010, 01:48:16 PM |
|
To get block/tx size, you can add this to block processing: obj.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK))); And add this to tx processing: 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).
|
1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
|
|
|
jgarzik (OP)
Legendary
Offline
Activity: 1596
Merit: 1099
|
|
November 27, 2010, 07:04:13 PM |
|
Patch updated to latest SVN, with additional block/TX size output.
|
Jeff Garzik, Bloq CEO, former bitcoin core dev team; opinions are my own. Visit bloq.com / metronome.io Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
|
|
|
jgarzik (OP)
Legendary
Offline
Activity: 1596
Merit: 1099
|
|
December 02, 2010, 05:50:44 AM |
|
Patch updated for latest SVN.
|
Jeff Garzik, Bloq CEO, former bitcoin core dev team; opinions are my own. Visit bloq.com / metronome.io Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
|
|
|
Luke-Jr
Legendary
Offline
Activity: 2576
Merit: 1186
|
|
January 29, 2011, 03:07:49 PM |
|
Any reason this shouldn't be merged with the main tree?
|
|
|
|
jgarzik (OP)
Legendary
Offline
Activity: 1596
Merit: 1099
|
|
February 24, 2011, 12:44:18 AM |
|
Patch updated to latest git. See URL at top of thread.
|
Jeff Garzik, Bloq CEO, former bitcoin core dev team; opinions are my own. Visit bloq.com / metronome.io Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
|
|
|
fahhem
Newbie
Offline
Activity: 11
Merit: 0
|
|
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/FdrYDVF5I 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.
|
|
|
|
xf2_org
Member
Offline
Activity: 98
Merit: 13
|
|
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.
|
|
|
|
error
|
|
May 23, 2011, 03:01:47 AM |
|
Any reason this shouldn't be merged with the main tree?
Seconded.
|
3KzNGwzRZ6SimWuFAgh4TnXzHpruHMZmV8
|
|
|
davout
Legendary
Offline
Activity: 1372
Merit: 1007
1davout
|
|
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 : david@bankbox:~/rails/bitcoin-pool$ bitcoin getblockbyhash 00000000003d7e088aba9d12e34cc3f75cd10ffa48a026fa535c0771e5c1b0c8 { "hash" : "00000000003d7e088aba9d12e34cc3f75cd10ffa48a026fa535c0771e5c1b0c8", "version" : 1, "prev_block" : "0000000000176fa50f3c759b2025acdbb0b4f311372e2b94acb0e69f73ae7c6b", "mrkl_root" : "46689b6020b67534e63fb81ddf379bb666a96ff55de27f8eebe8dffc924c09e7", "time" : 1307350469, "bits" : 470193746, "nonce" : 3293063839, "n_tx" : 1, "size" : 215, "tx" : [ { "hash" : "46689b6020b67534e63fb81ddf379bb666a96ff55de27f8eebe8dffc924c09e7", "version" : 1, "lock_time" : 0, "size" : 134, "in" : [ { "prev_out" : { "hash" : "0000000000000000000000000000000000000000000000000000000000000000", "n" : 4294967295 }, "coinbase" : "045296061c0112" } ], "out" : [ { "value" : 50.00000000, "scriptPubKey" : "04d98927faa89cd92df4861f08933ff68f50182850775fc590965049e34de80f6277cbcc9d5446ed43abf9794d70df9813b9fb7c589805a70676ddaee8e803d806 OP_CHECKSIG" } ] } ], "mrkl_tree" : [ "46689b6020b67534e63fb81ddf379bb666a96ff55de27f8eebe8dffc924c09e7" ] } Nothing wrong here, but when I want to get details about the generation tx this is what I get : david@bankbox:~/rails/bitcoin-pool$ bitcoin gettransaction 46689b6020b67534e63fb81ddf379bb666a96ff55de27f8eebe8dffc924c09e7 { "amount" : 0.00000000, "confirmations" : 0, "txid" : "46689b6020b67534e63fb81ddf379bb666a96ff55de27f8eebe8dffc924c09e7", "time" : 1307350469, "details" : [ { "account" : "", "category" : "orphan", "amount" : 50.00000000 } ] } Also this should get pulled in, it's incredibly useful when building decent bitcoin handling apps.
|
|
|
|
xf2_org
Member
Offline
Activity: 98
Merit: 13
|
|
June 11, 2011, 02:58:41 AM |
|
getblockbycount / getblockbyhash RPCs updated to latest git.
|
|
|
|
Grouver (BtcBalance)
|
|
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: Wich obviously worked flawlessly. Only when I restarted my Linux server and try for instance: I get the error: error: {"code":-32601,"message":"Method not found"} I builded the patch with wxWidgets. Thanks again.
|
|
|
|
jgarzik (OP)
Legendary
Offline
Activity: 1596
Merit: 1099
|
|
June 29, 2011, 11:39:33 PM |
|
Only when I restarted my Linux server and try for instance: I get the error: error: {"code":-32601,"message":"Method not found"} That's because it is called 'getblockbycount' not 'getblock' these days.
|
Jeff Garzik, Bloq CEO, former bitcoin core dev team; opinions are my own. Visit bloq.com / metronome.io Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
|
|
|
Grouver (BtcBalance)
|
|
June 30, 2011, 05:46:46 AM Last edit: June 30, 2011, 09:40:36 AM by Grouver |
|
Right, got it to work. (Thanks to the bitcoin-dev channel) Right now I get this: array 'hash' => string '000000000000053eb0059c82f86013cbf205033d82754b5252a04059e331c55d' (length=64) 'version' => int 1 'prev_block' => string '00000000000009e1e09847ee394f5394a3eed9d7c37949ac7ef0648760b0e488' (length=64) 'mrkl_root' => string '53f1acacb93d62107d7ba62bdb50beefcc803dd4e3dfd33ed26857108901006d' (length=64) 'time' => int 1309386843 'bits' => int 437004818 'nonce' => float 3446647446 'n_tx' => int 81 'size' => int 36104 'tx' => array 0 => array 'hash' => string '1720c9d73186c87f31e9da0e3189fb67ce3252f8b300f603f8ae659b6f2bf60f' (length=64) 'version' => int 1 'lock_time' => int 0 'size' => int 134 'in' => array ... 'out' => array ... 1 => array 'hash' => string 'd3cd0851e088481afebd0178537cbb4cb9464ea03454b1c646643a1097727915' (length=64) 'version' => int 1 'lock_time' => int 0 'size' => int 258 'in' => array ... 'out' => array ... 2 => array 'hash' => string 'cb81abf818ad18c51c78c9724dbd9b74be49c7d7d748d9a3eafcd8f4b346b498' (length=64) 'version' => int 1 'lock_time' => int 0 'size' => int 223 'in' => array ... 'out' => array ...
etc..
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.
|
|
|
|
TeraPool
Newbie
Offline
Activity: 42
Merit: 0
|
|
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
|
|
|
|
Furyan
|
|
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-0Copy that into a file (e.g. diff.txt), then run patch -i diff.txt rpc.cpp You may want to add 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).
|
|
|
|
Furyan
|
|
July 21, 2011, 04:50:57 PM Last edit: July 21, 2011, 06:44:06 PM by Furyan |
|
Screw that, won't work. Need a clean diff.Oh, ok, this is the latest: https://github.com/jgarzik/bitcoin/commit/168f5a4b30d5307281eb5bc4447afb04348e9f5d.patchBut 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. --- rpc.cpp 2011-07-21 11:37:38.000000000 -0700 +++ rpc.cpp 2011-07-21 11:39:21.000000000 -0700 @@ -168,6 +168,157 @@ }
+Value BlockToValue(CBlock &block) +{ + Object obj; + obj.push_back(Pair("hash", block.GetHash().ToString().c_str())); + obj.push_back(Pair("version", block.nVersion)); + obj.push_back(Pair("prev_block", block.hashPrevBlock.ToString().c_str())); + obj.push_back(Pair("mrkl_root", block.hashMerkleRoot.ToString().c_str())); + obj.push_back(Pair("time", (uint64_t)block.nTime)); + obj.push_back(Pair("bits", (uint64_t)block.nBits)); + obj.push_back(Pair("nonce", (uint64_t)block.nNonce)); + obj.push_back(Pair("n_tx", (int)block.vtx.size())); + obj.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK))); + + Array tx; + for (int i = 0; i < block.vtx.size(); i++) { + Object txobj; + + txobj.push_back(Pair("hash", block.vtx[i].GetHash().ToString().c_str())); + txobj.push_back(Pair("version", block.vtx[i].nVersion)); + txobj.push_back(Pair("lock_time", (uint64_t)block.vtx[i].nLockTime)); + txobj.push_back(Pair("size", + (int)::GetSerializeSize(block.vtx[i], SER_NETWORK))); + + Array tx_vin; + for (int j = 0; j < block.vtx[i].vin.size(); j++) { + Object vino; + + Object vino_outpt; + + vino_outpt.push_back(Pair("hash", + block.vtx[i].vin[j].prevout.hash.ToString().c_str())); + vino_outpt.push_back(Pair("n", (uint64_t)block.vtx[i].vin[j].prevout.n)); + + vino.push_back(Pair("prev_out", vino_outpt)); + + if (block.vtx[i].vin[j].prevout.IsNull()) + vino.push_back(Pair("coinbase", HexStr( + block.vtx[i].vin[j].scriptSig.begin(), + block.vtx[i].vin[j].scriptSig.end(), false).c_str())); + else + vino.push_back(Pair("scriptSig", + block.vtx[i].vin[j].scriptSig.ToString().c_str())); + if (block.vtx[i].vin[j].nSequence != UINT_MAX) + vino.push_back(Pair("sequence", (uint64_t)block.vtx[i].vin[j].nSequence)); + + tx_vin.push_back(vino); + } + + Array tx_vout; + for (int j = 0; j < block.vtx[i].vout.size(); j++) { + Object vouto; + + vouto.push_back(Pair("value", + (double)block.vtx[i].vout[j].nValue / (double)COIN)); + vouto.push_back(Pair("scriptPubKey", + block.vtx[i].vout[j].scriptPubKey.ToString().c_str())); + + tx_vout.push_back(vouto); + } + + txobj.push_back(Pair("in", tx_vin)); + txobj.push_back(Pair("out", tx_vout)); + + tx.push_back(txobj); + } + + obj.push_back(Pair("tx", tx)); + + Array mrkl; + for (int i = 0; i < block.vMerkleTree.size(); i++) + mrkl.push_back(block.vMerkleTree[i].ToString().c_str()); + + obj.push_back(Pair("mrkl_tree", mrkl)); + + return obj; +} + + +Value getblockbycount(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "getblockbycount height\n" + "Dumps the block existing at specified height"); + + int64 height = params[0].get_int64(); + if (height > nBestHeight) + throw runtime_error( + "getblockbycount height\n" + "Dumps the block existing at specified height"); + + string blkname = strprintf("blk%d", height); + + CBlock block; + CBlockIndex* pindex; + bool found = false; + + CRITICAL_BLOCK(cs_main) + { + + for (map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.begin(); + mi != mapBlockIndex.end(); ++mi) + { + pindex = (*mi).second; + if ((pindex->nHeight == height) && (pindex->IsInMainChain())) { + found = true; + break; + } + } + + if (!found) + throw runtime_error( + "getblockbycount height\n" + "Dumps the block existing at specified height"); + + block.ReadFromDisk(pindex); + block.BuildMerkleTree(); + } + + return BlockToValue(block); +} + + +Value getblockbyhash(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "getblockbyhash hash\n" + "Dumps the block with specified hash"); + + uint256 hash; + hash.SetHex(params[0].get_str()); + CBlock block; + + CRITICAL_BLOCK(cs_main) + { + + map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hash); + if (mi == mapBlockIndex.end()) + throw JSONRPCError(-18, "hash not found"); + + CBlockIndex* pindex = (*mi).second; + + block.ReadFromDisk(pindex); + block.BuildMerkleTree(); + } + + return BlockToValue(block); +} + + Value getblockcount(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) @@ -1434,6 +1585,8 @@ { make_pair("help", &help), make_pair("stop", &stop), + make_pair("getblockbycount", &getblockbycount), + make_pair("getblockbyhash", &getblockbyhash), make_pair("getblockcount", &getblockcount), make_pair("getblocknumber", &getblocknumber), make_pair("getconnectioncount", &getconnectioncount), @@ -2130,6 +2283,7 @@ if (strMethod == "listtransactions" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "listtransactions" && n > 2) ConvertTo<boost::int64_t>(params[2]); if (strMethod == "listaccounts" && n > 0) ConvertTo<boost::int64_t>(params[0]); + if (strMethod == "getblockbycount" && n > 0) ConvertTo<boost::int64_t>(params[0]); if (strMethod == "sendmany" && n > 1) { string s = params[1].get_str();
I suggest you use the -b flag to patch to make a backup of your rpc.cpp. Works great!
|
|
|
|
TeraPool
Newbie
Offline
Activity: 42
Merit: 0
|
|
July 21, 2011, 09:56:24 PM |
|
Thank you incredibly Furyan.
|
|
|
|
|