gettransaction details does not include send to myself balance changes for imported addresses #28555

issue VojtechMyslivec openend this issue on October 2, 2023
  1. VojtechMyslivec commented at 9:26 am on October 2, 2023: none

    Is there an existing issue for this?

    • I have searched the existing issues

    Current behaviour

    At first, thanks for your work, Bitcoin Core team.

    AFAIK, if I send some amount to myself (retrieved with getnewaddress), it should include both send and receive elements with the same negative and positive amount respectively. This behavior is described e.g. in github issue #4807 and I can confirm that it’s a fact in some cases.

    Hovewer, the .details array does not include neither send nor receive elements sometimes. It’s omitted from the output as if nothing had been sent or received.

    Example:

     0$ bitcoin-cli gettransaction XXX...
     1{
     2  "amount": -0.1,
     3  "fee": -0.00002,
     4  "confirmations": 7967,
     5  "txid": "XXX...",
     6  ...,
     7  "details": [
     8    {
     9      "address": "SOME_RECIPIENT",
    10      "category": "send",
    11      "amount": -0.1,
    12      "vout": 0,
    13      "fee": -0.00002,
    14      "abandoned": false
    15    }
    16  ],
    17  "hex": "..."
    18}
    

    The transaction in mempool.space or other blockchain explorers shows other outputs as well.

     0[
     1  {
     2    "value": 0.1,
     3    "n": 0,
     4    "address": "SOME_RECIPIENT",
     5    ...
     6  },
     7  {
     8    "value": 0.05,
     9    "n": 0,
    10    "address": "MY_ANOTHER_ADDRESS_1",
    11    ...
    12  },
    13  {
    14    "value": 0.04,
    15    "n": 0,
    16    "address": "MY_ANOTHER_ADDRESS_2",
    17    ...
    18  }
    19]
    

    Raw transaction in .hex element includes these of course but they are missing in the .details element.

    Please note that both MY_ANOTHER_ADDRESS_n is tracked as .mine == true when I call getaddressinfo MY_ANOTHER_ADDRESS_n.

    Expected behaviour

    Both send and receive balance changes with the same amount appears in the details section of gettransaction output.

    Steps to reproduce

    These transactions are constructed with sendmany RPC call, but I am not able to reproduce them. (I tried it on testnet).

    Relevant log output

    I am not sure if it is relevant, but these are log lines about that transaction:

     02023-09-29T19:37:16Z [default] Fee Calculation: Fee:10233 Bytes:393 Tgt:0 (requested 0) Reason:"PayTxFee set" Decay 0.00000: Estimation: (-1 - -1) 0.00% 0.0/(0.0 0 mem 0.0 out) Fail: (-1 - -1) 0.00% 0.0/(0.0 0 mem 0.0 out)
     12023-09-29T19:37:41Z [default] Fee Calculation: Fee:10233 Bytes:393 Tgt:0 (requested 0) Reason:"PayTxFee set" Decay 0.00000: Estimation: (-1 - -1) 0.00% 0.0/(0.0 0 mem 0.0 out) Fail: (-1 - -1) 0.00% 0.0/(0.0 0 mem 0.0 out)
     22023-09-29T19:37:41Z [default] Fee non-grouped = 10233, grouped = 10233, using grouped
     32023-09-29T19:37:41Z [default] CommitTransaction:
     4CTransaction(hash=XXX, ver=2, vin.size=5, vout.size=1, nLockTime=809912)
     5    CTxIn(COutPoint(..., 30), scriptSig=, nSequence=4294967293)
     6    CTxIn(COutPoint(..., 7), scriptSig=, nSequence=4294967293)
     7    CTxIn(COutPoint(..., 11), scriptSig=, nSequence=4294967293)
     8    CTxIn(COutPoint(..., 0), scriptSig=, nSequence=4294967293)
     9    CTxIn(COutPoint(..., 19), scriptSig=, nSequence=4294967293)
    10    CScriptWitness(...., ...)
    11    CScriptWitness(...., ...)
    12    CScriptWitness(...., ...)
    13    CScriptWitness(...., ...)
    14    CScriptWitness(...., ...)
    15    CTxOut(nValue=0.14500000, scriptPubKey=...)
    162023-09-29T19:37:41Z [default] AddToWallet XXX...  newupdate
    172023-09-29T19:37:41Z [default] Submitting wtx XXX... to mempool for relay
    182023-09-29T19:37:41Z [default] MarkUnusedAddresses: Detected a used keypool item at index 121340, mark all keypool items up to this item as used
    192023-09-29T19:37:41Z [default] AddToWallet XXX...  
    

    How did you obtain Bitcoin Core

    Pre-built binaries

    What version of Bitcoin Core are you using?

    v25.0.0

    Operating system and version

    Debian 11 bullseye (oldstable)

    Machine specifications

    No response

  2. VojtechMyslivec commented at 1:11 pm on October 2, 2023: none

    I have just reproduced the issue. The problem is with destination addresses that were derived from imported descriptors. These transaction and addresses behaves correctly as “mine” addresses, but details section is missing for balance changes in gettransaction RPC output.

    Steps to reproduce

    1. Create new wallet and generate an address from it

      0read -rs passphrase
      1
      2bitcoin-cli -named createwallet wallet_name='tmp_to_export' passphrase="$passphrase" load_on_startup=false
      3problematic_address=$(bitcoin-cli getnewaddress)
      
    2. Export descriptors and unload the wallet

      edit: (private keys included)

      0bitcoin-cli -named walletpassphrase passphrase="$passphrase" timeout=20
      1bitcoin-cli -named listdescriptors private=true | jq '.descriptors' > 'descriptors-to-import.json'
      2bitcoin-cli unloadwallet 'tmp_to_export'
      
    3. Load another wallet and import descriptors

      0read -rs passphrase
      1
      2bitcoin-cli loadwallet default
      3bitcoin-cli -named walletpassphrase passphrase="$passphrase" timeout=20
      4bitcoin-cli importdescriptors "$(< 'descriptors-to-import.json')"
      
    4. Send some funds to the address derived from imported descriptors

      0bitcoin-cli -named walletpassphrase passphrase="$passphrase" timeout=20
      1bitcoin-cli send "{\"$problematic_address\": 0.1}"
      
    5. See missing details in gettransaction output:

      0bitcoin-cli gettransaction 'dc082c830c05e9600cf32d8c4484c3acffe7d85cd3e578d50b68e1c4fef53750'
      
       0{
       1  "amount": 0.00000000,
       2  "fee": -0.00012425,
       3  "confirmations": 0,
       4  "trusted": false,
       5  "txid": "dc082c830c05e9600cf32d8c4484c3acffe7d85cd3e578d50b68e1c4fef53750",
       6  "wtxid": "1bb51ec89915bf8c3a01144ffa4c2d2d1688ab3a0b59134cbbac73b160b0704a",
       7  "walletconflicts": [
       8  ],
       9  "time": 1696251182,
      10  "timereceived": 1696251182,
      11  "bip125-replaceable": "yes",
      12  "details": [
      13  ],
      14  "hex": "0200000000010387bfd79defdeb70b68cbf09cb03e613053e8aa2963074bdd67e9467672cd76810100000000fdffffff74de2418e3145b0ffbb0dc31878dcca40c158987b47996afea3c6073cc3cc41d0100000000fdffffff87bfd79defdeb70b68cbf09cb03e613053e8aa2963074bdd67e9467672cd76810000000000fdffffff0246179900000000002251206d18596b999dc4781f3de5e9f8e2eb6f1beeff8b5d83be0b3c1322cd863997fd8096980000000000225120460e9f7581f18cd79fccd4c4f86ae86a6e5ca469f1a845a240cd0b7d84f7e63d0140dfd690ed01e7a1f014c49aa750d29ea43f4ddc44a4393b43ba080c24f63787fa2ffaa8cea26f522f0a954fbf04e32edac6ec920f312d3f22cdf8c58d3532b2030140cde1904f21d760c0fb2d2f3bd1fc11e7cca60e24a4f5071fe76a184d71e542577b0d3ba8a1189aec4e31fdbe4bed014f55f12b961fffa9634fdfd6e2d6db8ebd0140716fa018e07bae6ac29bad3803957f5a5cae9cee6c720805c0ed657c59312d460392218d5ea14f99ad7364d8cd99880aa8363289938ec38c554a3c91954eacec00000000"
      15}
      

    FYI: this is a real TX on testnet: mempool.space/testnet

  3. VojtechMyslivec renamed this:
    gettransaction details does not include send to myself balance changes
    gettransaction details does not include send to myself balance changes for imported addresses
    on Oct 2, 2023
  4. willcl-ark commented at 1:32 pm on October 2, 2023: contributor

    Thanks for the report @VojtechMyslivec.

    Can you try running gettransaction with include_watchonly=true?

    I guess since you only imported the pubkey descriptor into “default” wallet, it might consider this a watchonly wallet, and so be (correctly) skipping those outputs from the details field.

    side note: I thought mixing privkey and watchonly wallets was prohibited, so not sure how the import of your descriptors to default, which then seems able to send transactions, is currently permitted…

  5. VojtechMyslivec commented at 1:41 pm on October 2, 2023: none

    Thanks for your response Will!

    I am really sorry for the confusion. I exported description including private keys, so these addresses should not be in watchonly mode. I forgot to mention private=true parameter in the commands above (which I have just corrected).

    Running with include_watchonly=true does not make any difference.

  6. furszy commented at 1:57 pm on October 2, 2023: member
    gettransaction result does not include change outputs. The functionality could be added if needed. Meanwhile, could use listsinceblock setting the include_change arg to true.
  7. VojtechMyslivec commented at 2:25 pm on October 2, 2023: none

    Thank you for the reply Matias. But I am not talking about change addresses nor outputs. This TX is from my wallet to the receiving address, that is derived from the imported descriptor. There is of course some change output but I don’t bother about that.

    Another TX, that send funds from my wallet to another address (derived from the original descriptors), includes both send and receive items in the details array of gettransaction output.

    Also, another TX, that transfer funds from the outside to the address of imported descriptor, includes receive item in the details.

    So it appears to me as a bug in the “edge” case of sending a TX to myself and using a destination address that is derived from an imported descriptor.

  8. VojtechMyslivec commented at 9:56 am on December 20, 2023: none

    Is there anything more I can provide to investigate this problem?

    I would label this with ~bug, ~descriptors and ~wallet

    Thanks

  9. maflcko added the label Wallet on Dec 20, 2023
  10. maflcko added the label RPC/REST/ZMQ on Dec 20, 2023

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-06-29 07:13 UTC

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