TransactionError::ALREADY_IN_CHAIN inconsistency #19363

issue hebasto openend this issue on June 23, 2020
  1. hebasto commented at 12:07 pm on June 23, 2020: member

    If a transaction is already in the block chain, and all of its outputs are spent, the BroadcastTransaction() fails to detect the correct transaction status. It returns TransactionError::MISSING_INPUTS instead of TransactionError::ALREADY_IN_CHAIN.

    The related code: https://github.com/bitcoin/bitcoin/blob/80fd474e402bb003c3a427f1997eb649e69138ba/src/node/transaction.cpp#L32-L37

    I think that TransactionError::ALREADY_IN_CHAIN should be returned in all cases when the transaction is in the block chain, or it should be dropped from the code at all as inconsistent.

    What are other opinions?

  2. willcl-ark commented at 4:04 pm on February 17, 2023: member

    Although it is inconsistent I slightly prefer the idea of returning the most accurate information available to the user.

    Following this logic instead of removing this error type, we could take two new actions to try and increase the chance that the caller gets more accurate information back:

    1. Inside BroadcastTransaction() add a call to GetTransaction() on the condition that the user has txindex enabled
    2. Augment HandleATMPError to include a more detailed error string in the TxValidationResult::TX_MISSING_INPUTS case, which might prompt a recipient to find another way to check if the transaction is already in the chain.
  3. ryanofsky commented at 2:39 pm on August 6, 2024: contributor

    I think that TransactionError::ALREADY_IN_CHAIN should be returned in all cases when the transaction is in the block chain, or it should be dropped from the code at all as inconsistent.

    #30212 implements the second option. It gets rid of “already in chain” error code since that case can’t be reliably detected, and returns “already in utxo set”, or “missing inputs” instead.

  4. ryanofsky closed this on Aug 6, 2024

  5. fanquake referenced this in commit 870447fd58 on Aug 6, 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-10-30 03:12 UTC

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