assumeutxo: nTx and nChainTx in RPC results are off #29328

issue maflcko openend this issue on January 26, 2024
  1. maflcko commented at 3:38 pm on January 26, 2024: member

    AssumeUtxo mocks the nTx value of headers after the last background block and before the snapshot header with nTx=1. This means that the getblockheader and getchaintxstats RPCs return the wrong nTx or txcount fields for those blocks.

    Not sure if anything should be done about this?

  2. maflcko added the label Brainstorming on Jan 26, 2024
  3. maflcko added the label RPC/REST/ZMQ on Jan 26, 2024
  4. ryanofsky commented at 3:22 pm on January 29, 2024: contributor

    The RPCs should probably be fixed to never return fake values.

    It is pretty easy to tell when the nTx value is fake. You can just call IsValid(), and if it returns true, the nTx value is real, and if it returns false, the value is fake.

    It is less straightforward to determine when the nChainTx is fake, but we could introduce a helper function to do that which could be used by these RPCs and also be useful for #29299. If nChainTx is greater than 0, and nSequenceId is not 0 or BLOCK_ASSUMED_VALID is not set or the block is the snapshot block, then nChainTx value is real. Otherwise the nChainTx is probably fake. This check could falsely indicate that real nChainTx values were fake in the interval between blocks being downloaded and fully validated, but this should not be a big deal.

    In the long run it would be better to just not set fake values. According to a comment in PopulateAndValidateSnapshot these values are only faked so that GuessVerificationProgress works better. I don’t know if this is true, but if it is true, it seems like GuessVerificationProgress could just report progress based on block heights instead of transaction counts below the snapshot height, and we could get rid of the fake values, leaving nTx and nChainTx set to 0 when unknown and nonzero when known.

  5. mzumsande commented at 4:18 pm on January 29, 2024: contributor

    I don’t know if this is true, but if it is true, it seems like GuessVerificationProgress could just report progress based on block heights instead of transaction counts

    If we can do that, we should get rid of nChainTx altogether. I think that its only other use is for HaveNumChainTxs which doesn’t use its value but checks whether it is 0. That would also save some memory and eliminate problems like #29258.

    However, just using block heights would be very inaccurate because the first ~300k blocks are almost empty. Maybe we could plot the nChainTx for each block, use non-linear regression to fit some mathematical function (e.g. some polynomial, possibly piecewise) to approximate it, and then use that and get rid of nChainTx?

  6. ryanofsky commented at 4:55 pm on January 29, 2024: contributor

    If we can do that, we should get rid of nChainTx altogether.

    Oh, I don’t think we should use block heights instead of real nChainTx values, because as you say using block heights would be very inaccurate. I’m just suggesting we could use block heights instead of fake nChainTx values, and we would not be worse off because currently the fake nChainTx values are set to block heights. Also probably it probably be good to estimate the number of transactions in BLOCK_ASSUMED_VALID blocks by interpolating between nChainTx in the snapshot block, and nChainTx in the last validated block, instead of assuming each block before the snapshot has 1 transaction.

  7. mzumsande commented at 5:41 pm on January 29, 2024: contributor
    I see, I misunderstood. Still might also be worth thinking about getting rid of nChainTx in the long run (which has been discussed before in #13875), but that is off-topic here.
  8. maflcko commented at 5:27 pm on January 30, 2024: member

    It is pretty easy to tell when the nTx value is fake. You can just call IsValid(), and if it returns true, the nTx value is real, and if it returns false, the value is fake.

    I don’t think this is true. For example, it is possible that a block was downloaded and the nTx value was set, but the block later turned out to be invalid. Thus IsValid() will return false, but the nTx value is real.

  9. ryanofsky commented at 6:37 pm on January 30, 2024: contributor

    I don’t think this is true. For example, it is possible that a block was downloaded and the nTx value was set, but the block later turned out to be invalid. Thus IsValid() will return false, but the nTx value is real.

    Good point. Maybe the practical consequences would not be too bad if it just causes nTx to be omitted from rpc results when in some cases it shouldn’t be. But this seems like another reason to want get rid of the fake assumeutxo nTx and nChainTx values, so we can simply treat 0 values as invalid, and nonzero values as valid.

    EDIT: It also seems like BLOCK_VALID_TRANSACTIONS level is not removed if a block is marked invalid (a BLOCK_FAILED_VALID flag is added instead). So code could check level is >= BLOCK_VALID_TRANSACTIONS directly to see if nTx is valid.

  10. bitcoin deleted a comment on Jan 30, 2024
  11. ryanofsky referenced this in commit 4c70d993e3 on Feb 2, 2024
  12. ryanofsky commented at 4:20 pm on February 2, 2024: contributor
    Attempting to get rid of the fake values in #29370
  13. ryanofsky referenced this in commit a3228f02f6 on Feb 2, 2024
  14. ryanofsky referenced this in commit 1dd59d6fe4 on Feb 5, 2024
  15. ryanofsky referenced this in commit 59a8ca9333 on Feb 5, 2024
  16. ryanofsky referenced this in commit 5cde4d121b on Feb 7, 2024
  17. ryanofsky referenced this in commit 288269a3b0 on Feb 7, 2024
  18. ryanofsky referenced this in commit 717f3fa69e on Feb 7, 2024
  19. ryanofsky referenced this in commit 207a171769 on Feb 8, 2024
  20. ryanofsky referenced this in commit 50273702d7 on Feb 15, 2024
  21. ryanofsky referenced this in commit 594336ae8a on Feb 20, 2024
  22. ryanofsky referenced this in commit c69db62d5e on Feb 26, 2024
  23. ryanofsky referenced this in commit d351ea2f88 on Feb 26, 2024
  24. ryanofsky referenced this in commit 6c154da50e on Feb 29, 2024
  25. ryanofsky referenced this in commit fdabd745d1 on Mar 8, 2024
  26. ryanofsky referenced this in commit 95474d9f3b on Mar 8, 2024
  27. ryanofsky referenced this in commit 85233b2032 on Mar 8, 2024
  28. ryanofsky referenced this in commit 6096542e4c on Mar 11, 2024
  29. ryanofsky referenced this in commit 95829338ed on Mar 12, 2024
  30. ryanofsky referenced this in commit 875156cdd8 on Mar 12, 2024
  31. ryanofsky referenced this in commit 43f800cdd0 on Mar 13, 2024
  32. ryanofsky referenced this in commit b3d695f913 on Mar 13, 2024
  33. ryanofsky referenced this in commit ef29c8b662 on Mar 18, 2024
  34. ryanofsky referenced this in commit 38175d034e on Mar 18, 2024
  35. achow101 referenced this in commit b50554babd on Mar 20, 2024
  36. mzumsande referenced this in commit 7d8cc84913 on Apr 1, 2024
  37. achow101 closed this on Jul 2, 2024

  38. achow101 referenced this in commit 173ab0ccf2 on Jul 2, 2024

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: 2024-11-21 09:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me