Title: Whats the command to ping my Bitcoin node to send me X amount of blocks? Post by: Xenland on November 06, 2012, 09:07:26 AM Whats the command to ping my Bitcoin node to send me X amount of blocks?
Title: Re: Whats the command to ping my Bitcoin node to send me X amount of blocks? Post by: mskwik on November 06, 2012, 03:50:34 PM https://en.bitcoin.it/wiki/Protocol_specification#getblocks (https://en.bitcoin.it/wiki/Protocol_specification#getblocks)
Not really set up to give a certain number, you just give it the hash for the last block you have (or a couple of the latest) and it will send a list of anything newer (up to 500 blocks). Title: Re: Whats the command to ping my Bitcoin node to send me X amount of blocks? Post by: mskwik on November 06, 2012, 04:00:50 PM https://en.bitcoin.it/wiki/Protocol_specification#getblocks (https://en.bitcoin.it/wiki/Protocol_specification#getblocks) Not really set up to give a certain number, you just give it the hash for the last block you have (or a couple of the latest) and it will send a list of anything newer (up to 500 blocks). that is actual code, for the protocol, that has nothing to do with the API of the bitcoin node That is correct, as far as I know there isn't any way to get multiple blocks out of the RPC interface (unless that has changed in recent versions) but if you connect via the P2P interface it will spit out a list fairly quickly. Depends on your application which is easier and the original question wasn't very specific. Title: Re: Whats the command to ping my Bitcoin node to send me X amount of blocks? Post by: Gavin Andresen on November 06, 2012, 04:11:40 PM That is correct, as far as I know there isn't any way to get multiple blocks out of the RPC interface (unless that has changed in recent versions) Recent versions support JSON-2.0 "batch" queries, so you can combine multiple RPC calls into one batch and get a list of responses. Title: Re: Whats the command to ping my Bitcoin node to send me X amount of blocks? Post by: mskwik on November 06, 2012, 04:38:30 PM That is correct, as far as I know there isn't any way to get multiple blocks out of the RPC interface (unless that has changed in recent versions) Recent versions support JSON-2.0 "batch" queries, so you can combine multiple RPC calls into one batch and get a list of responses. Ah, very nice. I've been using the P2P interface to get raw block data since before the getblock RPC calls were standard (seemed preferable to vetting various getblock patches and keeping up with changing arguments for them) and even in fairly recent releases the performance seems to be much better connecting that way, but I will admit I haven't tried it again that recently. Title: Re: Whats the command to ping my Bitcoin node to send me X amount of blocks? Post by: Xenland on November 06, 2012, 09:20:19 PM Thanks for the information everyone!
All this information is going towards the Bitcoin Pseudocode Client Documentation project: https://github.com/Xenland/Bitcoin-Pseudocode-Client/tree/gh-pages Does anyone know how to query a Bitcoin node from the outside with getblocks? I tried to curl request with my Bitcoin node in "JSON" formate and bitcoin client says unknown message or invalid message. Any BTC source code references for connecting to the p2p interface? Title: Re: Whats the command to ping my Bitcoin node to send me X amount of blocks? Post by: kjj on November 06, 2012, 09:32:47 PM To use the p2p protocol to spew blocks, you'll have to implement a fair chunk of the protocol; enough to convince your node that it is talking to another node.
If you just want to see the blocks, parsing the block files is super easy. The only catch is that you'll need to build your own index as you go. The satoshi client keeps an index, but it is in the BDB system, and interfacing with that is probably much more work than doing it yourself. Title: Re: Whats the command to ping my Bitcoin node to send me X amount of blocks? Post by: mskwik on November 07, 2012, 03:01:14 AM Here's a basic sample of connecting to the P2P interface in Perl, this just connects and spits out any new blocks in raw format on STDOUT and debug information about the connection on STDERR but once you've got the connection running you can send any commands through it, just need to be careful about the network byte orders that bitcoin uses.
Code: #!/usr/bin/perl |