Properly document target_confirmations in listsinceblock #10655

pull RHavar wants to merge 1 commits into bitcoin:master from RHavar:listsinceblock changing 1 files +2 −2
  1. RHavar commented at 3:05 AM on June 23, 2017: contributor

    There seems to be some misunderstandings about this, but it's a heavily used function so I'd like to make sure the docs are clear about how it works.

    For a later issue:

    • Change the default of target_confirmations to 6 (1 is a pretty silly default)
    • Change the name of target_confirmations (it's really a horrible name)
  2. fanquake added the label Docs and Output on Jun 23, 2017
  3. RHavar force-pushed on Jun 23, 2017
  4. RHavar force-pushed on Jun 23, 2017
  5. TheBlueMatt commented at 5:46 PM on July 14, 2017: member

    utACK I know this is a super old issue but I find the current docs astoundingly confusing, can we try for 15?

  6. instagibbs commented at 5:54 PM on July 14, 2017: member

    @kallewoof I think you have experience with this call?

    documentation sounds reasonable, but I don't actually know how it's used.

  7. RHavar commented at 6:00 PM on July 14, 2017: contributor

    The way the API is designed to be used is like this:

    Let's say I care about only rescanning of 10:

    let confsCareAbout = 10
    let  hash = ""
    while (true) {
         let res = exec(`bitcoin-cli listsinceblock ${hash} ${confsCareAbout)`)
         process(res.transactions)
         hash = res.lastblock;
    }
    

    It's a pretty sweet work flow for handling deposits. Just unfortunately listsinceblock is too buggy and ill-defined (I'll create some bug reports when I can).

    But this PR fixes the docs, that makes it a bit clearer what it does. Most people when they read the docs think it's a filter, when it's not.

  8. in src/wallet/rpcwallet.cpp:1693 in 4bb8fc1fc7 outdated
    1689 | @@ -1690,7 +1690,7 @@ UniValue listsinceblock(const JSONRPCRequest& request)
    1690 |              "\nGet all transactions in blocks since block [blockhash], or all transactions if omitted\n"
    1691 |              "\nArguments:\n"
    1692 |              "1. \"blockhash\"            (string, optional) The block hash to list transactions since\n"
    1693 | -            "2. target_confirmations:    (numeric, optional) The confirmations required, must be 1 or more\n"
    1694 | +            "2. target_confirmations:    (numeric, optional, default=1) Return the nth block hash from the main chain. 1 would mean the bestblockhash (see lastblock in return value)\n"
    


    TheBlueMatt commented at 6:05 PM on July 14, 2017:

    Maybe add a note that transactions with fewer confirmations than this are still included in the response, only lastblock is changed by this argument.

  9. morcos commented at 6:10 PM on July 14, 2017: member

    NACK as is

    The documentation is very misleading. But it needs to be made even more clear than this. Perhaps add "Transactions with any number of confirmations in the range from blockhash to current tip (or the fork point if blockhash is not on current chain) will be returned." somewhere

  10. RHavar commented at 6:17 PM on July 14, 2017: contributor

    (or the fork point if blockhash is not on current chain)

    Is that what it actually does? o.0 If so thats ....bizarre and wtf.

  11. TheBlueMatt commented at 6:23 PM on July 14, 2017: member

    Yes, thats what it appears to have always done...docs need to be a shitload clearer here.

  12. RHavar force-pushed on Jul 14, 2017
  13. RHavar commented at 9:34 PM on July 14, 2017: contributor

    I pushed another stab at documenting it based on what @morcos said, but it honestly makes no sense to me. I assume I'm misunderstanding.

    Let's imagine I have the blocks:

               /--> C 
    A--->B
               \-->D -->E
    

    Where E is the main chain tip. And C is orphaned.

    So you're saying if I call listsinceblock C, it's going to return me only transactions between [B, C) AKA transactions I've already processed, and are orphaned?). The expected set of transactions it would return you is between [B, E).

  14. morcos commented at 9:41 PM on July 14, 2017: member

    Yes it will return between B and E

  15. RHavar commented at 9:44 PM on July 14, 2017: contributor

    Hm, so when you said:

    Transactions with any number of confirmations in the range from blockhash to current tip (or the fork point if blockhash is not on current chain) will be returned.

    You mean that just the lastblock returns $target_confirmations from the (mainTip or convergencePoint) ?.

    But this is independent to the transaction filtering stuff?

  16. RHavar force-pushed on Jul 14, 2017
  17. in src/wallet/rpcwallet.cpp:1693 in 8f71159cbd outdated
    1689 | @@ -1690,7 +1690,7 @@ UniValue listsinceblock(const JSONRPCRequest& request)
    1690 |              "\nGet all transactions in blocks since block [blockhash], or all transactions if omitted\n"
    1691 |              "\nArguments:\n"
    1692 |              "1. \"blockhash\"            (string, optional) The block hash to list transactions since\n"
    1693 | -            "2. target_confirmations:    (numeric, optional) The confirmations required, must be 1 or more\n"
    1694 | +            "2. target_confirmations:    (numeric, optional, default=1) Return the nth block hash from the main chain. e.g. 1 would mean the bestblockhash, unless [blockhash] is not on the current chain, in which case it would return be the common ancestor block between it an the main chain). Note: this is not used as a filter, but only affects [lastblock] in the return value\n"
    


    TheBlueMatt commented at 11:32 PM on July 14, 2017:

    No, the value returned is always the Nth-from-top block on the best chain.


    RHavar commented at 11:36 PM on July 14, 2017:

    Yeah, that's what i thought ><

  18. RHavar force-pushed on Jul 14, 2017
  19. RHavar force-pushed on Jul 14, 2017
  20. RHavar force-pushed on Jul 14, 2017
  21. kallewoof commented at 1:11 AM on July 15, 2017: member

    target_confirmations seems to be handled in a very weird way right now. It only affects the returned last block, and does not actually affect the transactions being returned in any way. I would declare this a bug, personally. The only time the value is used is at https://github.com/bitcoin/bitcoin/blob/0d457c7b274a66d66d59725f5fe1ee1cef5b6391/src/wallet/rpcwallet.cpp#L1859 where

        CBlockIndex *pblockLast = chainActive[chainActive.Height() + 1 - target_confirms];
    

    i.e. to determine the block hash of he last block.

    Correct me if I'm wrong.

  22. TheBlueMatt commented at 1:15 AM on July 15, 2017: member

    @kallewoof you are correct, but that behavior long predates the documentation for the function. I have no idea if anyone uses its previous behavior, but assuming people test things before putting them in production, best to fix the docs and leave the behavior IMO.

  23. kallewoof commented at 1:20 AM on July 15, 2017: member

    @TheBlueMatt That makes sense to me.

  24. RHavar commented at 1:51 AM on July 15, 2017: contributor

    I don't think the behavior is a bug at all, it was intentionally designed for use in a loop like I describe in an earlier comment.

    It's actually a really nice and simple way to handle deposits, and I know a few people who do it that way. Note how it works really well if your depositor goes down, because you keep storing the hash you want to scan from. Changing the behavior at this point would be totally unreasonable.

    (The only reason I don't handle deposits myself that way, is how it handles double spend (attempts) are weird and inconsistent, which make it very difficult to work with when you're showing unconfirmed stuff)

  25. morcos commented at 3:54 AM on July 15, 2017: member

    ACK 52295ba

    I think that language is clear and accurate

    (except I'm not sure about putting brackets around the argument names in the help text, is that something we do anywhere else?)

  26. RHavar commented at 3:57 AM on July 15, 2017: contributor

    (except I'm not sure about putting brackets around the argument names in the help text, is that something we do anywhere else?)

    I just copied it from the original. It's a bit messy, but it's pretty clear and makes things a lot less ambiguous.

  27. kallewoof commented at 5:02 AM on July 15, 2017: member

    (The only reason I don't handle deposits myself that way, is how it handles double spend (attempts) are weird and inconsistent, which make it very difficult to work with when you're showing unconfirmed stuff)

    The reason why double spends are weird and inconsistent is probably because you are using target_confs > 1. This means if there's a 1-2 block fork, and your target_confs = 10 or something, you will not be told of the differences caused by the orphan since you're listing a block that preceded the fork point.

    That's how I interpret this, anyway.

  28. fanquake deleted a comment on Jul 15, 2017
  29. kallewoof commented at 8:06 AM on July 15, 2017: member

    My initial expectation was that transactions with less than target_confs confirmations (i.e. transactions in blocks newer than the returned lastblock at the end) would be excluded from the results. This would give you a buffer of 0-confs and 1-confs that are still at risk. That's not what is happening though.

  30. in src/wallet/rpcwallet.cpp:1721 in 52295ba238 outdated
    1717 | @@ -1717,7 +1718,7 @@ UniValue listsinceblock(const JSONRPCRequest& request)
    1718 |              "    \"label\" : \"label\"       (string) A comment for the address/transaction, if any\n"
    1719 |              "    \"to\": \"...\",            (string) If a comment to is associated with the transaction.\n"
    1720 |               "  ],\n"
    1721 | -            "  \"lastblock\": \"lastblockhash\"     (string) The hash of the last block\n"
    1722 | +            "  \"lastblock\": \"lastblockhash\"     (string) The hash of the block (target_confirmations-1) from the best block on the main chain. This is typically used to feed back into listsinceblock the next time you call it. So you would generally use a target_confirmations of say 6, so you can keep rescanning the last 6 blocks plus any new ones\n"
    


    TheBlueMatt commented at 4:58 PM on July 15, 2017:

    "rescanning" means something specific, maybe "so you will be continually re-notified of transactions until they've reached 6 confirmations"

  31. laanwj added this to the milestone 0.15.0 on Jul 19, 2017
  32. laanwj commented at 12:13 PM on July 25, 2017: member

    Needs rebase and addressing of @TheBlueMatt 's nit, if this is still to make 0.15

  33. RHavar force-pushed on Jul 25, 2017
  34. RHavar force-pushed on Jul 25, 2017
  35. RHavar force-pushed on Jul 25, 2017
  36. RHavar commented at 1:29 PM on July 25, 2017: contributor

    Ok, rebased and addressed Matt's nit

  37. in src/wallet/rpcwallet.cpp:1758 in e4c1c79a56 outdated
    1754 | @@ -1755,14 +1755,13 @@ UniValue listsinceblock(const JSONRPCRequest& request)
    1755 |  
    1756 |      if (request.fHelp || request.params.size() > 4)
    1757 |          throw std::runtime_error(
    1758 | -            "listsinceblock ( \"blockhash\" target_confirmations include_watchonly include_removed )\n"
    1759 | -            "\nGet all transactions in blocks since block [blockhash], or all transactions if omitted.\n"
    1760 | -            "If \"blockhash\" is no longer a part of the main chain, transactions from the fork point onward are included.\n"
    1761 | -            "Additionally, if include_removed is set, transactions affecting the wallet which were removed are returned in the \"removed\" array.\n"
    1762 | +            "listsinceblock ( \"blockhash\" target_confirmations include_watchonly)\n"
    


    TheBlueMatt commented at 7:05 PM on July 25, 2017:

    Looks like a rebase error - you've removed the include_removed parameter here.


    RHavar commented at 7:11 PM on July 25, 2017:

    Sorry, yeah. I fail. Pushed a fix.

  38. in src/wallet/rpcwallet.cpp:1761 in e4c1c79a56 outdated
    1754 | @@ -1755,14 +1755,13 @@ UniValue listsinceblock(const JSONRPCRequest& request)
    1755 |  
    1756 |      if (request.fHelp || request.params.size() > 4)
    1757 |          throw std::runtime_error(
    1758 | -            "listsinceblock ( \"blockhash\" target_confirmations include_watchonly include_removed )\n"
    1759 | -            "\nGet all transactions in blocks since block [blockhash], or all transactions if omitted.\n"
    1760 | -            "If \"blockhash\" is no longer a part of the main chain, transactions from the fork point onward are included.\n"
    1761 | -            "Additionally, if include_removed is set, transactions affecting the wallet which were removed are returned in the \"removed\" array.\n"
    


    TheBlueMatt commented at 7:07 PM on July 25, 2017:

    Rebase error here, too.

  39. in src/wallet/rpcwallet.cpp:1764 in e4c1c79a56 outdated
    1765 |              "\nArguments:\n"
    1766 |              "1. \"blockhash\"            (string, optional) The block hash to list transactions since\n"
    1767 | -            "2. target_confirmations:    (numeric, optional, default=1) The confirmations required, must be 1 or more\n"
    1768 | -            "3. include_watchonly:       (bool, optional, default=false) Include transactions to watch-only addresses (see 'importaddress')\n"
    1769 | +            "2. target_confirmations:    (numeric, optional, default=1) Return the nth block hash from the main chain. e.g. 1 would mean the bestblockhash. Note: this is not used as a filter, but only affects [lastblock] in the return value\n"
    1770 | +            "3. include_watchonly:       (bool, optional, default=false) Include transactions to watch-only addresses (see 'importaddress')"
    


    TheBlueMatt commented at 7:07 PM on July 25, 2017:

    Why did you delete the \n here?


    RHavar commented at 7:11 PM on July 25, 2017:

    some how screwed that up in the rebase. fixed

  40. TheBlueMatt commented at 7:07 PM on July 25, 2017: member

    Looks like a few rebase errors.

  41. RHavar force-pushed on Jul 25, 2017
  42. RHavar force-pushed on Jul 25, 2017
  43. RHavar force-pushed on Jul 25, 2017
  44. in src/wallet/rpcwallet.cpp:1764 in 2fd4060eb6 outdated
    1763 | +            "If [blockhash] is not in the best chain, it will return all transactions since [blockhash]'s first common ancestor with the best chain\n"
    1764 |              "Additionally, if include_removed is set, transactions affecting the wallet which were removed are returned in the \"removed\" array.\n"
    1765 |              "\nArguments:\n"
    1766 |              "1. \"blockhash\"            (string, optional) The block hash to list transactions since\n"
    1767 | -            "2. target_confirmations:    (numeric, optional, default=1) The confirmations required, must be 1 or more\n"
    1768 | +            "2. target_confirmations:    (numeric, optional, default=1) Return the nth block hash from the main chain. e.g. 1 would mean the bestblockhash. Note: this is not used as a filter, but only affects [lastblock] in the return value\n"
    


    TheBlueMatt commented at 7:18 PM on July 25, 2017:

    I dont think "bestblockhash" is one word.


    RHavar commented at 7:26 PM on July 25, 2017:

    Ok. 😭

  45. RHavar force-pushed on Jul 25, 2017
  46. RHavar force-pushed on Jul 25, 2017
  47. RHavar force-pushed on Jul 25, 2017
  48. RHavar commented at 7:20 PM on July 25, 2017: contributor

    Ok, fixed my rebase fail...

  49. TheBlueMatt commented at 7:23 PM on July 25, 2017: member

    utACK.

  50. Properly document target_confirmations in listsinceblock 9f8a46f077
  51. RHavar force-pushed on Jul 25, 2017
  52. TheBlueMatt commented at 7:43 PM on July 25, 2017: member

    utACK

  53. laanwj commented at 6:45 AM on July 26, 2017: member

    utACK 9f8a46f

  54. laanwj merged this on Jul 26, 2017
  55. laanwj closed this on Jul 26, 2017

  56. laanwj referenced this in commit 78f307b664 on Jul 26, 2017
  57. RHavar deleted the branch on Oct 2, 2018
  58. PastaPastaPasta referenced this in commit 9829a6dac1 on Sep 4, 2019
  59. barrystyle referenced this in commit 25ac313865 on Jan 22, 2020
  60. MarcoFalke locked this on Sep 8, 2021
Labels

Milestone
0.15.0


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