[wallet] Rescan abortability #10208

pull kallewoof wants to merge 2 commits into bitcoin:master from kallewoof:rescan-abortability changing 4 files +46 −1
  1. kallewoof commented at 6:48 am on April 14, 2017: member

    The wallet importprivkey command triggers a rescan of the entire block chain unless explicitly asked not to. This oftentimes is not intentional, and there has so far not existed a way to abort a rescan in progress.

    This PR adds support for a new RPC command abortrescan which will prompt ScanForWalletTransactions to stop scanning.

  2. fanquake added the label RPC/REST/ZMQ on Apr 14, 2017
  3. fanquake added the label Wallet on Apr 14, 2017
  4. kallewoof force-pushed on Apr 14, 2017
  5. kallewoof force-pushed on Apr 14, 2017
  6. in src/wallet/rpcdump.cpp:178 in a9fd7c811c outdated
    166+            "abortrescan\n"
    167+            "\nStops current wallet rescan triggered e.g. by an importprivkey call.\n"
    168+        );
    169+
    170+    if (!pwallet->fScanningWallet) throw JSONRPCError(RPC_WALLET_ERROR, "No wallet rescans in progress.");
    171+    if (pwallet->fAbortRescan) throw JSONRPCError(RPC_WALLET_ERROR, "Rescan abort already in progress.");
    


    NicolasDorier commented at 6:53 am on April 14, 2017:
    nits: I don’t think it should throw an error. The expected state is correctly reached at the end of the call.

    kallewoof commented at 6:54 am on April 14, 2017:

    It’s a response to the RPC caller, so it’s more like feedback and less than an actual error. Compare this to the std::runtime_error thrown for the help message.

    Ultimately, if the scan is not in progress and/or if the rescan flag is already set, the end results will be the same even without throwing.

  7. in src/wallet/wallet.cpp:1563 in a9fd7c811c outdated
    1559@@ -1558,7 +1560,12 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool f
    1560                 LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, GuessVerificationProgress(chainParams.TxData(), pindex));
    1561             }
    1562         }
    1563+        if (pindex && fAbortRescan) {
    


    NicolasDorier commented at 6:54 am on April 14, 2017:

    need to set fAbortRescan to false again.

    EDIT: Actually it should be fine… I think it is best that the end state of the variable is known though.


    kallewoof commented at 6:55 am on April 14, 2017:
    It’s set at line 1530 above. I was thinking of setting it to false at end but it doesn’t really matter as it’s reset at top anyway.
  8. in src/wallet/rpcdump.cpp:180 in a9fd7c811c outdated
    168+        );
    169+
    170+    if (!pwallet->fScanningWallet) throw JSONRPCError(RPC_WALLET_ERROR, "No wallet rescans in progress.");
    171+    if (pwallet->fAbortRescan) throw JSONRPCError(RPC_WALLET_ERROR, "Rescan abort already in progress.");
    172+    pwallet->fAbortRescan = true;
    173+    return "Wallet rescan aborted.";
    


    NicolasDorier commented at 6:58 am on April 14, 2017:
    returning a human readable message feel a bit weird to me.

    kallewoof commented at 7:02 am on April 14, 2017:
    I was sure I’d seen that elsewhere but now I’m not so sure. Revisiting that part now.

    jonasschnelli commented at 7:08 am on April 14, 2017:
    From the API consumer perspective, what you want is parsable differentiations between the possible states. Your currently use RPC_WALLET_ERROR for fScanningWallet and fAbortRescan leading to the fact the one needs to parse string to get the correct state.

    kallewoof commented at 7:13 am on April 14, 2017:
    Right, good point – I will add error codes for these two and throw those instead.
  9. in src/wallet/rpcdump.cpp:167 in a9fd7c811c outdated
    162+    }
    163+
    164+    if (request.fHelp || request.params.size() > 0)
    165+        throw std::runtime_error(
    166+            "abortrescan\n"
    167+            "\nStops current wallet rescan triggered e.g. by an importprivkey call.\n"
    


    jonasschnelli commented at 7:05 am on April 14, 2017:
    nit: Usually we have the HelpExampleCli and HelpExampleRpc here.

    kallewoof commented at 7:06 am on April 14, 2017:
    @jonasschnelli I wasn’t sure that was the case even for no-arg commands. Will add.

    kallewoof commented at 7:12 am on April 14, 2017:
    Added.
  10. jonasschnelli commented at 7:09 am on April 14, 2017: contributor
    Nice. Concept ACK. Have you tested this together with the GUI? Are you willing to expand this to the GUI?
  11. jonasschnelli closed this on Apr 14, 2017

  12. jonasschnelli commented at 7:09 am on April 14, 2017: contributor
    Accidentally closed. Reopening.
  13. jonasschnelli reopened this on Apr 14, 2017

  14. kallewoof force-pushed on Apr 14, 2017
  15. kallewoof commented at 7:11 am on April 14, 2017: member
    @jonasschnelli I haven’t tried with the GUI. Definitely willing to add that, but wonder if that should be a separate PR?
  16. jonasschnelli commented at 7:13 am on April 14, 2017: contributor
    Can be separate if this PR does not break the GUI rescan additions (the popup window).
  17. kallewoof commented at 7:14 am on April 14, 2017: member
    Gotcha. I will test the GUI. If it doesn’t seem overly complex I’ll add support there as well while at it.
  18. kallewoof commented at 7:35 am on April 14, 2017: member

    @jonasschnelli I tested out the GUI. The only way I could find importing keys was the Help > Debug > Console > importprivkey … route. It brings up the “Rescanning…” popup with the progress bar, and locks input so I can’t abort the rescan to test that part. But the actual GUI works fine.

    Adding an “Abort” button to the progress popup seems sensible, but I’m going to declare that as a separate PR for now as I don’t immediately see a neat solution to doing so.

  19. sipa commented at 7:36 am on April 14, 2017: member
    @kallewoof You can run bitcoin-qt with the -server flag, and then issue command through bitcoin-cli or any other RPC client.
  20. jonasschnelli commented at 7:36 am on April 14, 2017: contributor
    @kallewoof: Great. Yes. Let’s fix this in an upcoming PR. I think you can also rescan by ./bitcoin-qt -server or ./bitcoin-qt -rescan.
  21. kallewoof commented at 7:41 am on April 14, 2017: member
    @sipa Ahh that let me try abortrescan from CLI while doing import from the GUI. Thanks! @jonasschnelli GUI fully tested and appears functional.
  22. kallewoof force-pushed on Apr 14, 2017
  23. NicolasDorier commented at 10:04 am on April 14, 2017: contributor
    utACK 33b93f52b4452008075520239f4991440380be1a
  24. rawodb approved
  25. KibbledJiveElkZoo commented at 7:45 pm on April 14, 2017: contributor

    “Wallet is being asked to abort rescan despite already pending rescan abort”

    I would change “abort” to “abortion”; I believe it may be more grammatically correct, and we need the word abortion in the core code.

  26. in src/wallet/wallet.h:726 in 33b93f52b4 outdated
    722@@ -723,6 +723,8 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
    723      */
    724     mutable CCriticalSection cs_wallet;
    725 
    726+    std::atomic<bool> fAbortRescan;
    


    rawodb commented at 8:18 pm on April 14, 2017:
    I would turn both these flags to private standard boolean and use CWallet getters&setters to change them

    kallewoof commented at 0:45 am on April 17, 2017:
    For some reason I didn’t think we used getters/setters but clearly we do. Fixed, thanks!
  27. gmaxwell commented at 5:49 am on April 15, 2017: contributor
    I wish we didn’t need this, but we do. Concept ACK.
  28. rawodb commented at 8:39 am on April 17, 2017: none
    ACK
  29. laanwj commented at 1:12 pm on April 17, 2017: member
    nice! utACK after squash
  30. kallewoof force-pushed on Apr 17, 2017
  31. kallewoof commented at 2:27 pm on April 17, 2017: member
    Squashed. Edit: Crap. Fixing…
  32. kallewoof force-pushed on Apr 17, 2017
  33. [wallet] Add support for aborting wallet transaction rescans. 75a08e7d17
  34. kallewoof force-pushed on Apr 17, 2017
  35. in src/wallet/rpcdump.cpp:177 in 153d24d073 outdated
    172+            + HelpExampleCli("abortrescan", "") +
    173+            "\nAs a JSON-RPC call\n"
    174+            + HelpExampleRpc("abortrescan", "")
    175+        );
    176+
    177+    if (!pwallet->IsScanning()) throw JSONRPCError(RPC_WALLET_NOT_SCANNING, "No wallet rescans in progress.");
    


    TheBlueMatt commented at 7:14 pm on April 17, 2017:
    I have to agree with the previous comment, throwing here is super strange. The direct API we expose is likely fine, but many API wrappers will throw a corresponding exception like we do here, and I’d consider “not currently scanning” to be a warning, not a critical error - it would be nice to just return a boolean for “we did something”.

    kallewoof commented at 1:14 am on April 18, 2017:

    I can’t find the previous comment you are referring to? (Did you get this and #9622 (review) mixed up, by any chance?)

    Since we’re throwing when a user types the word help, it conceptually feels like a throw is simply a result with a code and a message, rather than a critical error. It’s a way to distinguish from “ACK” and “NACK” even for trivial reasons. Compare e.g. the addnode RPC which throws an error when a node being added is already there, or when a node being removed is not in the list. That feels similarly non-critical to me – end result is the same – but could be harder to code for without error codes if we changed to returning a success bool or something.


    TheBlueMatt commented at 1:43 am on April 18, 2017:
    I was referring to #10208 (review) The help throw, however, is for when you provide bad arguments, which is the correct “you fucked up” response. Throwing if not scanning is just a race in client applications, an almost-guaranteed-benign race to boot.

    kallewoof commented at 2:20 am on April 18, 2017:

    I guess the worst thing that happens is that you accidentally target the wrong node and one node ends up scanning the entire wallet even though you asked it not to. That’s not a biggie, really, especially if you don’t even realize it yourself.

    I’ll switch to returning true/false for did/didn’t do something as you suggest.

  36. TheBlueMatt commented at 7:14 pm on April 17, 2017: member
    One comment, utACK otherwise.
  37. [rpc] Add abortrescan command to RPC interface. 9141622a0f
  38. kallewoof force-pushed on Apr 18, 2017
  39. kallewoof commented at 2:55 am on April 18, 2017: member

    Per #10208 (review) I have replaced the RPC throws with true/false for “did something” / “did nothing” return values in abortrescan.

    Unsquashed history: 123∈2

  40. laanwj merged this on Apr 18, 2017
  41. laanwj closed this on Apr 18, 2017

  42. laanwj referenced this in commit 393160cf6c on Apr 18, 2017
  43. laanwj commented at 6:06 am on April 18, 2017: member

    This still needs (in follow-up PR):

    • a test in test/functional
    • mention in the release notes
  44. kallewoof deleted the branch on Apr 18, 2017
  45. TheBlueMatt commented at 7:17 pm on April 18, 2017: member
    postumous utACK
  46. PastaPastaPasta referenced this in commit f05ad69488 on May 21, 2019
  47. PastaPastaPasta referenced this in commit 05bec2c40a on May 21, 2019
  48. PastaPastaPasta referenced this in commit 797d91a278 on May 22, 2019
  49. PastaPastaPasta referenced this in commit df0a6b3696 on May 22, 2019
  50. PastaPastaPasta referenced this in commit 2cfc9bd52a on May 22, 2019
  51. PastaPastaPasta referenced this in commit c81be60bc1 on May 22, 2019
  52. PastaPastaPasta referenced this in commit 0b232fd1cf on May 23, 2019
  53. UdjinM6 referenced this in commit 1c16fee17e on May 28, 2019
  54. barrystyle referenced this in commit 7f22d0510b on Jan 22, 2020
  55. random-zebra referenced this in commit db2057e5ee on Apr 4, 2021
  56. DrahtBot 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: 2024-10-30 00:12 UTC

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