Return errors from importmulti if complete rescans are not successful #9773

pull ryanofsky wants to merge 1 commits into bitcoin:master from ryanofsky:pr/multicheck changing 6 files +114 −13
  1. ryanofsky commented at 10:19 pm on February 15, 2017: member

    This is supposed to address the concern from @gmaxwell in #9761 that importmulti rescans on pruned nodes could unsuccessfully scan pruned blocks and fail to inform the user.

    An alternative approach of just simply disabling importmulti rescans on pruned nodes was initially discussed in https://botbot.me/freenode/bitcoin-core-dev/msg/81023921/, but running being able to import keys and do partial rescans on pruned nodes was determined to be an important use-case.

  2. morcos commented at 10:48 pm on February 15, 2017: member

    Concept ACK This looks like a reasonable approach to me.

    Don’t forget that you may want to include the grace period in detecting whether it scanned enough. Also you might want to skip the rest of the loop if ReadBlockFromDisk is false.

  3. fanquake added the label RPC/REST/ZMQ on Feb 16, 2017
  4. fanquake added the label Wallet on Feb 16, 2017
  5. laanwj added this to the milestone 0.14.0 on Feb 16, 2017
  6. laanwj commented at 12:09 pm on February 16, 2017: member

    Concept ACK.

    The code has not been tested at all, and I’m actually not sure how I’m going to go about writing a unit test because there doesn’t seem to be an easy way to target individual blocks for pruning inside RPC tests.

    There’s pruneblockchain but yes pruning works on a per-file, not a per-block basis, so it would need some extra effort on regtest to generate full blocks instead of empty ones otherwise at block 30000 you’re still in the first file, and that RPC will do nothing.

  7. gmaxwell commented at 12:16 pm on February 16, 2017: contributor
    Concept ACK. Will test/review further.
  8. morcos commented at 3:42 pm on February 16, 2017: member
    Please rebase on #9761 so we can verify the grace period works properly
  9. ryanofsky force-pushed on Feb 16, 2017
  10. ryanofsky commented at 3:53 pm on February 16, 2017: member
    Rebased
  11. ryanofsky renamed this:
    WIP: Return errors from importmulti if complete rescans are not successful
    WIP: Return errors from importmulti if complete rescans are not successful (on top of #9761)
    on Feb 16, 2017
  12. in src/wallet/wallet.cpp: in 34e4209275 outdated
    1583             int posInBlock;
    1584             for (posInBlock = 0; posInBlock < (int)block.vtx.size(); posInBlock++)
    1585             {
    1586-                if (AddToWalletIfInvolvingMe(*block.vtx[posInBlock], pindex, posInBlock, fUpdate))
    1587-                    ret++;
    1588+                AddToWalletIfInvolvingMe(*block.vtx[posInBlock], pindex, posInBlock, fUpdate);
    


    morcos commented at 6:53 pm on February 16, 2017:
    I think this loop should also be skipped if ReadBlockFromDisk fails

    ryanofsky commented at 6:59 pm on February 16, 2017:
    Skipped in d6f6a23c7092aa21110cc77ebeb018492bacae28
  13. ryanofsky referenced this in commit d6f6a23c70 on Feb 16, 2017
  14. ryanofsky commented at 7:02 pm on February 16, 2017: member
    Add test for CWallet::ScanForWalletTransactions in e3d4f257ce0202811464d3b6860db87ba147aa24
  15. ryanofsky renamed this:
    WIP: Return errors from importmulti if complete rescans are not successful (on top of #9761)
    Return errors from importmulti if complete rescans are not successful (on top of #9761)
    on Feb 16, 2017
  16. ryanofsky force-pushed on Feb 16, 2017
  17. in src/wallet/rpcdump.cpp: in 34e4209275 outdated
    1095+                if (GetImportTimestamp(request, now) - 7200 >= scannedRange->GetBlockTimeMax() || results.at(i).exists("error")) {
    1096+                    response.push_back(results.at(i));
    1097+                } else {
    1098+                    UniValue result = UniValue(UniValue::VOBJ);
    1099+                    result.pushKV("success", UniValue(false));
    1100+                    result.pushKV("error", JSONRPCError(RPC_MISC_ERROR, strprintf("Failed to rescan before time %" PRId64 ", transactions may be missing.", (long long)scannedRange->GetBlockTimeMax())));
    


    jonasschnelli commented at 7:23 pm on February 16, 2017:
    just curious: Is there an advantage using PRId64 over %ul (rest of the code uses this)?

    ryanofsky commented at 7:33 pm on February 16, 2017:

    Actually I need to change this to either remove PRId64 or the (long long) cast.

    You’re supposed to use PRId64 whenever you pass an int64_t type to printf. %ld or %lld aren’t always correct because longs and long longs just have minimum widths in standard c++, not fixed widths that are the same on all systems.


    ryanofsky commented at 8:16 pm on February 16, 2017:
    Removed cast in e49f0394f07a95e6cc5cdabe32f2c6b8f53c40fb.
  18. ryanofsky commented at 8:13 pm on February 16, 2017: member
    Previously squashed e3d4f257ce0202811464d3b6860db87ba147aa24 -> 455b8f7cb2a1889053a006055e9dcad923c77029 (multicheck.2 -> multicheck.3)
  19. ryanofsky referenced this in commit e49f0394f0 on Feb 16, 2017
  20. ryanofsky force-pushed on Feb 16, 2017
  21. ryanofsky commented at 8:19 pm on February 16, 2017: member

    Added C++ test for new importmulti RPC code in e64cdfba4a7e8a670e76c7bf770c248dc6b78c3d

    Squashed e64cdfba4a7e8a670e76c7bf770c248dc6b78c3d -> b73252de549984a06aae294252d0d055aca43a4a (multicheck.4 -> multicheck.5)

  22. sipa commented at 8:29 pm on February 16, 2017: member
    Note that our strprintf is a wrapper around tfm::format, and doesn’t need type specs at all.
  23. morcos commented at 8:30 pm on February 16, 2017: member
    lightly tested ACK b73252d Only reviewed/tested code, not the tests.
  24. jonasschnelli approved
  25. jonasschnelli commented at 9:24 am on February 17, 2017: contributor
    utACK b73252de549984a06aae294252d0d055aca43a4a
  26. in src/wallet/rpcdump.cpp: in b73252de54 outdated
    1096+                if (GetImportTimestamp(request, now) - 7200 >= scannedRange->GetBlockTimeMax() || results.at(i).exists("error")) {
    1097+                    response.push_back(results.at(i));
    1098+                } else {
    1099+                    UniValue result = UniValue(UniValue::VOBJ);
    1100+                    result.pushKV("success", UniValue(false));
    1101+                    result.pushKV("error", JSONRPCError(RPC_MISC_ERROR, strprintf("Failed to rescan before time %" PRId64 ", transactions may be missing.", scannedRange->GetBlockTimeMax())));
    


    laanwj commented at 11:56 am on February 17, 2017:
    Please remove the PRI64d here. It gives problems with some platforms, and as @sipa says don’t need it.

    ryanofsky commented at 12:08 pm on February 17, 2017:
    Ok will change, but what are the problems with some platforms?

    ryanofsky commented at 12:24 pm on February 17, 2017:

    Removed in aaaf65a90b87c18889d177ff3f0ab8a868f849f3.

    Reason I am asking about the problem you’re seeing is that not using PRI64d for int64_t would prevent us from using compile time format string checking (as suggested in #9423 (comment)) which would be much better than the runtime checking we currently use.


    laanwj commented at 11:37 am on February 22, 2017:

    Ok will change, but what are the problems with some platforms?

    The conceptual problem is that PRI64d can evaluate to anything depending on the platform, e.g. “%ponyfood”. tinyformat.h cannot know about all these platform-dependent escape sequences, so might produce garbled output or even raise an exception. We had a lot of problems with this back in the day with windows and mingw. It is wrong to pass platform-specific stuff to a platform-independent library. Also PRI64d is C99, so not all C++ compilers are guaranteed to have it at all.

    Offline checking could still work, the script would just need to be smart enough to cope with a) translations b) tinyformat’s specifiers and type-safety. (b) is actually a subset, not a superset of what platform printfs support (none of the insecure ones like %n) so if anything that should make it easier.

  27. ryanofsky force-pushed on Feb 17, 2017
  28. ryanofsky commented at 12:12 pm on February 17, 2017: member
    Rebased b73252de549984a06aae294252d0d055aca43a4a -> 90671ee7e77c17c18f5ea82ea041962ef5d53f8a (multicheck.5 -> multicheck.6)
  29. ryanofsky renamed this:
    Return errors from importmulti if complete rescans are not successful (on top of #9761)
    Return errors from importmulti if complete rescans are not successful
    on Feb 17, 2017
  30. ryanofsky referenced this in commit aaaf65a90b on Feb 17, 2017
  31. ryanofsky force-pushed on Feb 17, 2017
  32. ryanofsky commented at 12:24 pm on February 17, 2017: member
    Squashed aaaf65a90b87c18889d177ff3f0ab8a868f849f3 -> 1425c727863b335bf98bb4b17b575e59552d38e9 (multicheck.7 -> multicheck.8)
  33. MarcoFalke commented at 2:36 pm on February 17, 2017: member
  34. ryanofsky commented at 3:43 pm on February 17, 2017: member

    Somehow travis didn’t like your commit.

    Appears to be a spurious error. The travis run for b72521dd7f570b0c557439d534f7523a5be52999 which is aaaf65a90b87c18889d177ff3f0ab8a868f849f3 merged into 9828f9a9962c1bee5c343847030b9cfd87a40a5e succeeded: https://travis-ci.org/bitcoin/bitcoin/builds/202600321

    Only the travis run for 64072b74ebbf7b5585b39f6c117c6ffa9dc820f0 which is 1425c727863b335bf98bb4b17b575e59552d38e9 merged into 9828f9a9962c1bee5c343847030b9cfd87a40a5e failed: https://travis-ci.org/bitcoin/bitcoin/builds/202600549

    There are no differences between the two commits:

    0$ git rev-parse aaaf65a90b87c18889d177ff3f0ab8a868f849f3^{tree} 1425c727863b335bf98bb4b17b575e59552d38e9^{tree}
    19e695fd32f65b1596f3ff613b96ec756bb2f1d2b
    29e695fd32f65b1596f3ff613b96ec756bb2f1d2b
    
  35. ryanofsky force-pushed on Feb 17, 2017
  36. ryanofsky force-pushed on Feb 17, 2017
  37. ryanofsky commented at 3:48 pm on February 17, 2017: member
    Touched CommitDate to rerun travis 1425c727863b335bf98bb4b17b575e59552d38e9 -> e2e2f4c856363bbb0e3b5ba4df225f3754c3db39 (multicheck.8 -> multicheck.12)
  38. ryanofsky force-pushed on Feb 17, 2017
  39. Return errors from importmulti if complete rescans are not successful e2e2f4c856
  40. ryanofsky force-pushed on Feb 17, 2017
  41. jtimon commented at 11:21 pm on February 18, 2017: contributor
    Concept ACK
  42. laanwj merged this on Feb 22, 2017
  43. laanwj closed this on Feb 22, 2017

  44. laanwj referenced this in commit ba7220b5e8 on Feb 22, 2017
  45. laanwj referenced this in commit 9072395e5f on Feb 22, 2017
  46. in src/wallet/test/wallet_tests.cpp: in e2e2f4c856
    372+    CBlockIndex* newTip = chainActive.Tip();
    373+
    374+    // Verify ScanForWalletTransactions picks up transactions in both the old
    375+    // and new block files.
    376+    {
    377+        CWallet wallet;
    


    paveljanik commented at 5:07 pm on February 22, 2017:

    This brings a few Wshadow warnings:

    0Wshadow statistics: 
    1   1 wallet/test/wallet_tests.cpp:377:17: warning: declaration shadows a variable in namespace 'wallet_tests' [-Wshadow]
    2   1 wallet/test/wallet_tests.cpp:391:17: warning: declaration shadows a variable in namespace 'wallet_tests' [-Wshadow]
    3   1 wallet/test/wallet_tests.cpp:399:17: warning: declaration shadows a variable in namespace 'wallet_tests' [-Wshadow]
    
  47. ryanofsky referenced this in commit 09fe346a4f on Feb 22, 2017
  48. practicalswift referenced this in commit cf0bbf42c4 on Apr 27, 2017
  49. codablock referenced this in commit ac981ec3cc on Jan 26, 2018
  50. andvgal referenced this in commit 85e44ba1ea on Jan 6, 2019
  51. CryptoCentric referenced this in commit 597df87c6f on Feb 27, 2019
  52. 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: 2024-10-31 12:12 UTC

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