[RPC] gettransaction calculates fee incorrectly if inputs are not all from the bitcoind wallet #11893

issue pinheadmz opened this issue on December 14, 2017
  1. pinheadmz commented at 1:41 AM on December 14, 2017: member

    I created a transaction with an offline wallet that spent outputs from two different addresses. I then imported only one of those two private keys into bitcoind with importprivkey.

    When I viewed the transaction in bitcoind I was shocked to see such an incredible fee! I realize it's because the fee is calculated from the perspective of the wallet, not the actual total vin - vout difference the miner actually collects:

    vin: 0.00037120 from imported key 0.09799380 from the other key

    vout: 0.09802500

    actual miner fee: 0.00034000

    fee reported by gettransaction: 0.09765380

    $ bitcoin-cli gettransaction fa[...obfuscated...]39
    {
      "amount": -0.09802500,
      "fee": 0.09765380,
      "confirmations": 0,
      "trusted": false,
      "txid": "fa[...obfuscated...]39",
      "walletconflicts": [
      ],
      "time": 1513211216,
      "timereceived": 1513211216,
      "bip125-replaceable": "no",
      "details": [
        {
          "account": "",
          "address": "1[...obfuscated...]j",
          "category": "send",
          "amount": -0.09802500,
          "vout": 0,
          "fee": 0.09765380,
          "abandoned": false
        }
      ],
      "hex": "01[...obfuscated...]00"
    }
    
    
  2. fanquake added the label RPC/REST/ZMQ on Dec 14, 2017
  3. morcos commented at 1:55 AM on December 14, 2017: member

    This was addressed in #9167 which I let go stale after it didn't get much love. I or someone should rebase that PR.

  4. pinheadmz commented at 1:57 AM on December 14, 2017: member

    Ah thanks I'll take a look. I had a feeling this would have already been addressed

  5. sipa commented at 2:38 AM on December 14, 2017: member

    @pinheadmz We can't compute the fee for arbitrary transactions. The inputs may not be available.

  6. promag commented at 2:50 AM on December 14, 2017: member

    @sipa yes, but should we do it if the inputs are available? With -txindex it should be normally possible.

  7. sipa commented at 2:52 AM on December 14, 2017: member

    @promag I don't think we should. Changing behaviour just because an index is available is very confusing - I think its functionality should be limited to strictly enabling certain functionality but not modify something. Furthemore, -txindex is slow, not optimized, and not something we can expect common users to enable.

  8. pinheadmz commented at 6:58 PM on December 14, 2017: member

    Thanks @sipa that makes sense, I forgot the input values may not be available unless the transaction is relevant to the wallet.

  9. pinheadmz closed this on Dec 14, 2017

  10. MarcoFalke 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-04-13 15:15 UTC

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