Getting individual block by height from Bitcoin P2P network

0

Is it possible to request an individual block from the bitcoin network, using the block height as parameter? Or would one have to start a node and wait until all blocks up to the desired height have been retrieved?

I'd like to be able to retrieve the actual, raw, serialized data, but e.g. blockchain.info, even when saying format=raw doesn't give you the raw block data.

N.B. If I understand bitcoin correctly though, I fear that if I don't build up a node by myself, starting from block 0, I can never be sure what I'm getting is true data from the bitcoin blockchain, no matter if I get it from blockchain.info (which could be compromised) or from a p2p peer, which is just one (potentially malicious) peer.

Eugene Beresovsky

Posted 2019-01-25T13:01:31.033

Reputation: 101

Answers

1

To request an individual block from a p2p peer, consider the get_data message, indicating what type of block (witness/compact/filtered).

Since you do not wish to do full block download and validation, you can first build a header chain to the most recent height, and then verify the block you are requesting is in the header chain. This would ensure that it would be expensive to falsify the block data you receive from a peer. You can also determine the block header hash corresponding to the height index you are interested in, as blocks cannot be uniquely referred to by height over the p2p network (two branches can have same height).

To build a header chain, consider the GET_HEADERS message, which also provides information (so-called block locator) about your current header branch so the peer can provide the headers for your node to catch-up to its header height.

James C.

Posted 2019-01-25T13:01:31.033

Reputation: 2 183

@Eugene Did this answer your question?James C. 2019-01-27T14:21:31.387

Thanks James. Yes it did, and I hope this week I'll get around to actually confirming that, after which I intended to accept your answer.Eugene Beresovsky 2019-01-28T21:57:52.597