Skip to content

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

Closed

Description

@maflcko

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?

Activity

  1. ryanofsky commented on Jan 29, 2024

    @ryanofsky
    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.

  2. mzumsande commented on Jan 29, 2024

    @mzumsande
    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?

  3. ryanofsky commented on Jan 29, 2024

    @ryanofsky
    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.

  4. mzumsande commented on Jan 29, 2024

    @mzumsande
    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.

  5. maflcko commented on Jan 30, 2024

    @maflcko
    MemberAuthor

    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.

  6. ryanofsky commented on Jan 30, 2024

    @ryanofsky
    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.

  7. deleted a comment from Wwwwwwuuuuu on Jan 30, 2024
  8. ryanofsky commented on Feb 2, 2024

    @ryanofsky
    Contributor

    Attempting to get rid of the fake values in #29370

  9. 11 remaining items

  10. added a commit that references this issue on Mar 20, 2024
  11. added a commit that references this issue on Jul 2, 2024
  12. locked and limited conversation to collaborators on Jul 2, 2025
  13. added a commit that references this issue on Jun 28, 2026
  14. added a commit that references this issue on Jun 30, 2026
  15. added a commit that references this issue on Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions