rpc: expose CBlockIndex::nTx in getblock(header) #13451

pull instagibbs wants to merge 1 commits into bitcoin:master from instagibbs:expose_nTx changing 3 files +12 −0
  1. instagibbs commented at 8:47 PM on June 12, 2018: member

    Recent publication of a weakness in Bitcoin's merkle tree construction demonstrates many SPV applications vulnerable to an expensive to pull off yet still plausible attack: https://bitslog.wordpress.com/2018/06/09/leaf-node-weakness-in-bitcoin-merkle-tree-design/

    Including the coinbase in the txoutproof seems the most effective fix, however results in a significant efficiency downgrade. Transactors will not even know a priori what the size of their proof will be within a couple orders of magnitude, unless they use the mid-state of SHA2 as detailed in the blog post.

    Some applications, like Elements blockchain platform that take SPV-style proofs have optional access to a bitcoind to verify these proofs of inclusion and check depth in the chain. Returning CBlockIndex::nTx would allow an extremely easy and compact way of checking the depth of the tree, with no additional overhead to the codebase, and works with pruned nodes.

    getblockheader is arguably not the place for it, but as mentioned before, is a natural workflow for us checking depth of a block in a possibly pruned node.

    We should also ensure that verifytxoutproof ends up validating this depth fact as well, but left this for another PR.

  2. instagibbs cross-referenced this on Jun 12, 2018 from issue rpc: have verifytxoutproof check the number of txns in proof structure by instagibbs
  3. in src/rpc/blockchain.cpp:698 in f9eda3e14e outdated
     694 | @@ -694,6 +695,7 @@ static UniValue getblockheader(const JSONRPCRequest& request)
     695 |              "  \"bits\" : \"1d00ffff\", (string) The bits\n"
     696 |              "  \"difficulty\" : x.xxx,  (numeric) The difficulty\n"
     697 |              "  \"chainwork\" : \"0000...1f3\"     (string) Expected number of hashes required to produce the current chain (in hex)\n"
     698 | +            "  \"nTx\" : n,             (numeric) The number of transactions in the block. This result can also be returned for pruned blocks, as it's stored in the block index.\n"
    


    MarcoFalke commented at 10:22 PM on June 12, 2018:

    This result can also be returned for pruned blocks, as it's stored in the block index

    Should be a comment in the source code instead?

    I believe we have a pruning test, so it would make sense to add an assert_equal(nTx, whatever) there?

  4. MarcoFalke added the label RPC/REST/ZMQ on Jun 12, 2018
  5. MarcoFalke renamed this:
    expose CBlockIndex::nTx in getblockheader
    rpc: expose CBlockIndex::nTx in getblockheader
    on Jun 12, 2018
  6. MarcoFalke commented at 10:27 PM on June 12, 2018: member

    Similar to mediantime, this should also be exposed in getblock

  7. expose CBlockIndex::nTx in getblock(header) 86edf4a2a5
  8. instagibbs force-pushed on Jun 13, 2018
  9. instagibbs commented at 2:21 PM on June 13, 2018: member

    more tests, exposure and rewording as per @MarcoFalke suggestions

  10. instagibbs commented at 2:22 PM on June 13, 2018: member

    If it's not too much trouble I'd also like this backported for 0.16.2

  11. instagibbs renamed this:
    rpc: expose CBlockIndex::nTx in getblockheader
    rpc: expose CBlockIndex::nTx in getblock(header)
    on Jun 13, 2018
  12. MarcoFalke commented at 2:38 PM on June 13, 2018: member

    utACK 86edf4a2a502416ba8d6cebbce61030992f7ff6f

    Also, tagged for backport, since it is a rather trivial rpc change with tests already included.

  13. MarcoFalke added this to the milestone 0.16.2 on Jun 13, 2018
  14. MarcoFalke added the label Needs backport on Jun 13, 2018
  15. promag commented at 5:34 PM on June 13, 2018: member

    utACK 86edf4a.

  16. jtimon commented at 3:11 PM on June 14, 2018: contributor

    utACK 86edf4a2a502416ba8d6cebbce61030992f7ff6f

  17. laanwj commented at 5:39 PM on June 14, 2018: member

    utACK 86edf4a2a502416ba8d6cebbce61030992f7ff6f

  18. laanwj merged this on Jun 14, 2018
  19. laanwj closed this on Jun 14, 2018

  20. laanwj referenced this in commit cc7cbd756a on Jun 14, 2018
  21. instagibbs cross-referenced this on Jun 14, 2018 from issue [0.16.2] Backports by fanquake
  22. fanquake referenced this in commit cbd2f70b75 on Jun 15, 2018
  23. Bushstar cross-referenced this on Jun 15, 2018 from issue commits from bitcoin/master by Bushstar
  24. fanquake commented at 12:03 AM on June 26, 2018: member

    Added to #13455 for backport.

  25. fanquake removed the label Needs backport on Jun 26, 2018
  26. laanwj referenced this in commit 7e74c54fed on Jul 9, 2018
  27. laanwj referenced this in commit dac5374cce on Jul 9, 2018
  28. instagibbs cross-referenced this on Aug 7, 2018 from issue Need to address merkle leaf detection weakness in peg-in proof by instagibbs
  29. HashUnlimited referenced this in commit 6f9ba098aa on Jan 11, 2019
  30. jasonbcox referenced this in commit b209ed30d6 on Dec 20, 2019
  31. PastaPastaPasta referenced this in commit 046b5b09e4 on Apr 7, 2020
  32. PastaPastaPasta referenced this in commit f7d5e538df on Apr 8, 2020
  33. jonspock referenced this in commit 38ba78b205 on Oct 2, 2020
  34. jonspock referenced this in commit 8aa103bfe2 on Oct 5, 2020
  35. jonspock referenced this in commit 682550b52a on Oct 10, 2020
  36. PastaPastaPasta referenced this in commit 300572e4f1 on Dec 16, 2020
  37. PastaPastaPasta referenced this in commit 46b08dada0 on Dec 18, 2020
  38. PastaPastaPasta referenced this in commit 0da4f596bb on Dec 18, 2020
  39. ckti referenced this in commit 381e268d45 on Mar 28, 2021
  40. harding cross-referenced this on Apr 2, 2021 from issue chain: request pruned blocks from backend peers by wpaulino
  41. bitcoin locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-20 06:55 UTC