Bitcoin Forum
May 09, 2024, 07:33:46 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Counting the number of tx in a block without downloading the whole block?  (Read 1055 times)
jl2012 (OP)
Legendary
*
Offline Offline

Activity: 1792
Merit: 1097


View Profile
March 04, 2015, 05:54:04 AM
 #1

Is it possible to count the number of tx in a block without downloading the whole block? (e.g. only using the Merkle tree)

Donation address: 374iXxS4BuqFHsEwwxUuH3nvJ69Y7Hqur3 (Bitcoin ONLY)
LRDGENPLYrcTRssGoZrsCT1hngaH3BVkM4 (LTC)
PGP: D3CC 1772 8600 5BB8 FF67 3294 C524 2A1A B393 6517
The trust scores you see are subjective; they will change depending on who you have in your trust list.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
gmaxwell
Moderator
Legendary
*
expert
Offline Offline

Activity: 4172
Merit: 8418



View Profile WWW
March 04, 2015, 06:19:46 AM
Last edit: March 04, 2015, 09:06:39 AM by gmaxwell
 #2

Is it possible to count the number of tx in a block without downloading the whole block? (e.g. only using the Merkle tree)
No, you can get an upper bound on the size by the depth of the tree if you get the coinbase (or any other) txn,  and a lower bound if you get given a transaction late in the block. You can get an exact measure by taking the rightmost branch and observing the duplicated hashes, but nothing more compact than that.
hhanh00
Sr. Member
****
Offline Offline

Activity: 467
Merit: 266


View Profile
March 04, 2015, 10:16:45 AM
 #3

On a related note, what's the reason why the tx-count in the block header retrieved by getheaders always 0? It seems it would be as easy to return the actual count.

jl2012 (OP)
Legendary
*
Offline Offline

Activity: 1792
Merit: 1097


View Profile
March 04, 2015, 10:58:27 AM
 #4

Is it possible to count the number of tx in a block without downloading the whole block? (e.g. only using the Merkle tree)
No, you can get an upper bound on the size by the depth of the tree if you get the coinbase (or any other) txn,  and a lower bound if you get given a transaction late in the block. You can get an exact measure by taking the rightmost branch and observing the duplicated hashes, but nothing more compact than that.

Having a upper bound is probably good enough for me. The upper bound is the nearest power of 2, right?

As a related question, in the current protocol, could an SPV node requests for the x-th transaction in the y-th block, without knowing the txid of the transaction?

Donation address: 374iXxS4BuqFHsEwwxUuH3nvJ69Y7Hqur3 (Bitcoin ONLY)
LRDGENPLYrcTRssGoZrsCT1hngaH3BVkM4 (LTC)
PGP: D3CC 1772 8600 5BB8 FF67 3294 C524 2A1A B393 6517
TierNolan
Legendary
*
Offline Offline

Activity: 1232
Merit: 1083


View Profile
March 04, 2015, 11:52:51 AM
 #5

Having a upper bound is probably good enough for me. The upper bound is the nearest power of 2, right?

I think the Merkle path to the last transaction would give you the number of txids.  You could prove that it is the last by making sure that hashes are doubled.

You can work out which levels of the tree have an odd number of entries, and so has to double up the last hash.

Quote
As a related question, in the current protocol, could an SPV node requests for the x-th transaction in the y-th block, without knowing the txid of the transaction?

The merkleblock packet could be used as a response.  I don't think there is is a way to request a particular indexed transaction though.

Indexed lookups would be good though.  Parallel download would be easier if you could ask for the 100,000th block rather than having to download the first 99,999 blocks.  In almost all cases all peers would agree, so there is no risk.  Headers first makes this less of an issue though.

1LxbG5cKXzTwZg9mjL3gaRE835uNQEteWF
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!