refactor: Reduce number of LoadChainstate parameters and return values #25308

pull ryanofsky wants to merge 4 commits into bitcoin:master from ryanofsky:pr/retcode changing 10 files +168 −263
  1. ryanofsky commented at 1:31 pm on June 8, 2022: contributor

    Replace long LoadChainstate parameters list with options struct. Replace long list of return values with simpler error strings.

    No changes in behavior. Motivation is just to make libbitcoin_kernel API easier to use and more future-proof, and make internal code clearer and more maintainable.

  2. DrahtBot added the label Refactoring on Jun 8, 2022
  3. DrahtBot commented at 3:00 pm on June 8, 2022: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #25499 (Use steady clock for all millis bench logging by MarcoFalke)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  4. in src/kernel/checks.cpp:10 in 5ceae5c404 outdated
     6@@ -7,21 +7,22 @@
     7 #include <key.h>
     8 #include <random.h>
     9 #include <util/time.h>
    10+#include <util/translation.h>
    


    MarcoFalke commented at 3:06 pm on June 8, 2022:

    nit in the last commit. Maybe have this file checked by iwyu?

    #25065 (review)


    ryanofsky commented at 4:41 pm on June 8, 2022:

    re: #25308 (review)

    nit in the last commit. Maybe have this file checked by iwyu?

    Sure, done in new commit

  5. ryanofsky referenced this in commit 1066e9cff1 on Jun 8, 2022
  6. ryanofsky force-pushed on Jun 8, 2022
  7. ryanofsky commented at 4:42 pm on June 8, 2022: contributor
    Updated 5ceae5c40400037669e06fb759b7698e92d2b254 -> 1066e9cff1631cd7e3d5ef930c42c0c1227992b8 (pr/retcode.2 -> pr/retcode.3, compare) making a few more cleanups and enabling IWYU Updated 1066e9cff1631cd7e3d5ef930c42c0c1227992b8 -> 3981f5e7c090959b98a7fa0b9e92b52c36e60e96 (pr/retcode.3 -> pr/retcode.4, compare) fixing unintended change in catch statement
  8. ryanofsky referenced this in commit 3981f5e7c0 on Jun 8, 2022
  9. ryanofsky force-pushed on Jun 8, 2022
  10. jamesob commented at 6:12 pm on June 8, 2022: member
    Concept ACK! Code looks shorter and more readable.
  11. DrahtBot added the label Needs rebase on Jun 14, 2022
  12. dongcarl commented at 5:53 pm on June 16, 2022: contributor
    I really want to avoid reintroducing stringy error returns and coupling with util/translation if at all possible, why do you prefer error strings?
  13. ryanofsky referenced this in commit f3ec82fc46 on Jun 16, 2022
  14. ryanofsky force-pushed on Jun 16, 2022
  15. ryanofsky referenced this in commit 3135de18da on Jun 16, 2022
  16. ryanofsky commented at 6:39 pm on June 16, 2022: contributor

    I really want to avoid reintroducing stringy error returns and coupling with util/translation if at all possible, why do you prefer error strings?

    From most important to least important reasons:

    • Better user experience. Users can see complete information about an error instead of an error code with no context (flashback to https://en.wikipedia.org/wiki/Blue_screen_of_death#/media/File:Windows_9X_BSOD.png)
    • Better developer experience. Developers can call an API and have maybe 3-4 cases they need to handle, not 11 cases they need to decide what to do about.
    • Better separation of concerns and encapsulation. The too-narrow error codes that were here exposed implementation details of low level code to high level code
    • Maintainability. Getting rid of these error codes saves many lines of code. It makes code clearer, because putting error messages at error sites puts the error descriptions at the error site, not in some separate place. Putting error strings at error sites avoids possibilities of error codes getting mismapped or falling through unhandled (things we have no test coverage for, would be unlikely to be detected in manual testing, and could become broken at any time)
    • API compatibility. Related to the previous point about encapsulation, it’s nice to use an API that doesn’t break compatibility every time an internal implementation detail is changed, and some new error case is added, or an old one is removed

    Error codes can be great. Error strings can be great. Right tool for the job.


    Rebased 3981f5e7c090959b98a7fa0b9e92b52c36e60e96 -> f3ec82fc466b247e9ed6b329554e6938799fadb5 (pr/retcode.4 -> pr/retcode.5, compare) due to conflict with #25306

  17. DrahtBot removed the label Needs rebase on Jun 16, 2022
  18. in src/kernel/checks.cpp:16 in f3ec82fc46 outdated
    12+#include <memory>
    13 
    14 namespace kernel {
    15 
    16-std::optional<SanityCheckError> SanityChecks(const Context&)
    17+std::optional<bilingual_str> SanityChecks(const Context&)
    


    dongcarl commented at 9:34 pm on June 27, 2022:
    Could we just use std::string here? I don’t want to introduce further coupling with translation.

    ryanofsky commented at 6:59 pm on July 5, 2022:

    re: #25308 (review)

    In commit “refactor: Reduce number of SanityChecks return values” (0b9bb465e9a0e2d4c9b7dc398e59dc380e8c4e60)

    Could we just use std::string here? I don’t want to introduce further coupling with translation.

    We could actually use std::string instead of bilingual_str in this commit (not in the earlier commit), but I think it is better to use bilingual_str for reasons described in the other reply that commit.

  19. in src/node/chainstate.h:41 in f3ec82fc46 outdated
    47 };
    48 
    49+enum class InitStatus { SUCCESS, FAILURE, FAILURE_INCOMPATIBLE_DB, INTERRUPTED };
    50+
    51+//! Status code and optional error string.
    52+using InitResult = std::tuple<InitStatus, bilingual_str>;
    


    dongcarl commented at 9:34 pm on June 27, 2022:
    Could we just use std::string here? I don’t want to introduce further coupling with translation.

    dongcarl commented at 9:42 pm on June 27, 2022:
    nit: Perhaps rename to LoadChainstateResult so that it’s clearer it’s specifically about LoadChainstate and not all of init? Not a big deal either way.

    ryanofsky commented at 6:58 pm on July 5, 2022:

    re: #25308 (review)

    In commit “refactor: Reduce number of LoadChainstate return values” (ed3c27ae5034f27f6240d2dcafbdbfd9bc55b9d7)

    Could we just use std::string here?

    It’s not possible to do this without changing behavior. Error messages like “Error opening block database” and “Incorrect or no genesis block found. Wrong datadir for network?” are translated and can’t be returned through std::string.

    I don’t want to introduce further coupling with translation.

    I think there are only upsides not downsides to using bilingual_str for messages that may be shown to the users. Using bilingual_str instead of std::string only adds a dependency on the bilingual_str struct struct which is a simple pair of std::string’s. This is a very minimal dependency, and it doesn’t require the caller to use translations or the kernel library to provide them. It just allows translations to be passed along if they are present.

    In general, I think it is a good practice to use bilingual_str for user messages, whether or not they will be translated. Using the bilingual_str type distinguishes user messages from other types of strings, and helps future-proof code so API’s don’t have to change if translations are added or removed. The choice of whether or not to translate an string can be context dependent, and may depending on how frequently a specific message will be shown or how complicated it is to translate. Just using bilingual_str everywhere means APIs can pass translations along and not be tied to these implementation details.


    ryanofsky commented at 6:58 pm on July 5, 2022:

    re: #25308 (review)

    In commit “refactor: Reduce number of LoadChainstate return values” (ed3c27ae5034f27f6240d2dcafbdbfd9bc55b9d7)

    nit: Perhaps rename to LoadChainstateResult so that it’s clearer it’s specifically about LoadChainstate and not all of init? Not a big deal either way.

    Good suggestion, renamed both types

  20. in src/bitcoin-chainstate.cpp:92 in f3ec82fc46 outdated
     99+    node::CacheSizes cache_sizes;
    100+    cache_sizes.block_tree_db = 2 << 20;
    101+    cache_sizes.coins_db = 2 << 22;
    102+    cache_sizes.coins =  (450 << 20) - (2 << 20) - (2 << 22);
    103+    node::InitOptions options;
    104+    options.coins_error_cb=[] { return false; };
    


    dongcarl commented at 9:35 pm on June 27, 2022:
    0    options.coins_error_cb = [] { return false; };
    

    ryanofsky commented at 6:18 pm on July 5, 2022:

    re: #25308 (review)

    In commit “refactor: Reduce number of LoadChainstate return values” (ed3c27ae5034f27f6240d2dcafbdbfd9bc55b9d7)

    Thanks, updated whitespace

  21. in src/node/chainstate.h:38 in f3ec82fc46 outdated
    44+    int64_t check_level = DEFAULT_CHECKLEVEL;
    45+    std::function<bool()> check_interrupt;
    46+    std::function<void()> coins_error_cb;
    47 };
    48 
    49+enum class InitStatus { SUCCESS, FAILURE, FAILURE_INCOMPATIBLE_DB, INTERRUPTED };
    


    dongcarl commented at 9:37 pm on June 27, 2022:
    Perhaps we can add some Doxygen comments hinting callers on how they should behave when encountering each case.

    ryanofsky commented at 6:18 pm on July 5, 2022:

    re: #25308 (review)

    In commit “refactor: Reduce number of LoadChainstate return values” (ed3c27ae5034f27f6240d2dcafbdbfd9bc55b9d7)

    Perhaps we can add some Doxygen comments hinting callers on how they should behave when encountering each case.

    Thanks, added comment with suggestions

  22. dongcarl commented at 9:39 pm on June 27, 2022: contributor

    Concept ACK. I’ve thought about this a bit, and I think I’m convinced that this current way can work.

    The key point that convinced me was: what users of LoadChainstate care about discerning between is not what particular internal failure happened, but rather what to do about the failure, which is nicely encapsulated in InitStatus.

    Originally, my thought was that requiring callers to match against strings to determine what to do is footgun-y. However, if a case like that ever arises, it simply means that InitStatus should be modified to indicate the right course of action.

    In SanityChecks’s case, any sanity check failure indicates to the caller that something is catastrophically wrong and the only course of action is to bail, so there’s no need for an additional Status enum.

    Thanks for fixing the IWYU for src/kernel btw, I’ve been meaning to do that.

  23. in src/kernel/coinstats.cpp:26 in f3ec82fc46 outdated
    21 #include <util/overflow.h>
    22 #include <util/system.h>
    23 #include <validation.h>
    24+#include <version.h>
    25 
    26+#include <assert.h>
    


    fanquake commented at 9:21 am on June 28, 2022:
    We want to use/are migrating to the C++ headers. I know IWYU suggests <assert.h> (have been meaning to make it suggest the newer headers), but it will be equally as happy with <cassert>. Thanks for fixing these up in any case.

    ryanofsky commented at 7:01 pm on July 5, 2022:

    re: #25308 (review)

    In commit “ci: Enable IWYU in src/kernel directory” (f3ec82fc466b247e9ed6b329554e6938799fadb5)

    We want to use/are migrating to the C++ headers. I know IWYU suggests <assert.h> (have been meaning to make it suggest the newer headers), but it will be equally as happy with <cassert>. Thanks for fixing these up in any case.

    Thanks, switched to cassert

  24. MarcoFalke added the label Needs rebase on Jun 29, 2022
  25. DrahtBot removed the label Needs rebase on Jun 29, 2022
  26. in src/bitcoin-chainstate.cpp:90 in 1b32c5b726 outdated
     96-                                   false,
     97-                                   []() { return false; });
     98+    node::CacheSizes cache_sizes;
     99+    cache_sizes.block_tree_db = 2 << 20;
    100+    cache_sizes.coins_db = 2 << 22;
    101+    cache_sizes.coins =  (450 << 20) - (2 << 20) - (2 << 22);
    


    furszy commented at 6:50 pm on July 5, 2022:

    In 1b32c5b7:

    tiny nit, extra space

    0    cache_sizes.coins = (450 << 20) - (2 << 20) - (2 << 22);
    

    ryanofsky commented at 7:47 pm on July 5, 2022:

    re: #25308 (review)

    In 1b32c5b:

    tiny nit, extra space

    Thanks, fixed

  27. in src/node/chainstate.h:79 in 1b32c5b726 outdated
    86-                                                     bool coins_db_in_memory,
    87-                                                     std::function<bool()> shutdown_requested = nullptr,
    88-                                                     std::function<void()> coins_error_cb = nullptr);
    89+std::optional<ChainstateLoadingError> LoadChainstate(ChainstateManager& chainman,
    90+                                                     const CacheSizes& cache_sizes,
    91+                                                     const InitOptions& options = {});
    


    furszy commented at 6:57 pm on July 5, 2022:
    In 1b32c5b7: The InitOptions default value can be removed.

    ryanofsky commented at 7:48 pm on July 5, 2022:

    re: #25308 (review)

    In 1b32c5b: The InitOptions default value can be removed.

    Thanks, removed

  28. in src/node/chainstate.h:88 in 1b32c5b726 outdated
    84@@ -75,10 +85,7 @@ enum class ChainstateLoadVerifyError {
    85 };
    86 
    87 std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManager& chainman,
    88-                                                                bool fReset,
    89-                                                                bool fReindexChainState,
    90-                                                                int check_blocks,
    91-                                                                int check_level);
    92+                                                                const InitOptions& options = {});
    


    furszy commented at 6:57 pm on July 5, 2022:
    Same as above, in 1b32c5b7: The InitOptions default value can be removed.

    ryanofsky commented at 7:49 pm on July 5, 2022:

    re: #25308 (review)

    Same as above, in 1b32c5b: The InitOptions default value can be removed.

    Thanks, removed

  29. in src/node/chainstate.cpp:60 in ed3c27ae50 outdated
    60 
    61     // Check for changed -prune state.  What we are concerned about is a user who has pruned blocks
    62     // in the past, but is now trying to run unpruned.
    63     if (chainman.m_blockman.m_have_pruned && !options.prune) {
    64-        return ChainstateLoadingError::ERROR_PRUNED_NEEDS_REINDEX;
    65+        return {InitStatus::FAILURE, _("You need to rebuild the database using -reindex to go back to unpruned mode.  This will redownload the entire blockchain")};
    


    furszy commented at 7:00 pm on July 5, 2022:

    In ed3c27ae:

    tiny nit: remove extra space.

    0        return {InitStatus::FAILURE, _("You need to rebuild the database using -reindex to go back to unpruned mode. This will redownload the entire blockchain")};
    

    ryanofsky commented at 7:58 pm on July 5, 2022:

    re: #25308 (review)

    In ed3c27a:

    tiny nit: remove extra space.

    This is a refactoring PR, so would prefer not to change behavior here. (This is a translated string so changing it may require updating translations, as well as the original string)

  30. furszy commented at 7:08 pm on July 5, 2022: member
    Initial code review ACK f3ec82fc Left few tiny nits, nothing biggie nor blocking.
  31. ryanofsky commented at 8:06 pm on July 5, 2022: contributor

    Thanks for reviews!

    Updated f3ec82fc466b247e9ed6b329554e6938799fadb5 -> 7d97076cb7d4020110a830ae9fe4107f82511c41 (pr/retcode.5 -> pr/retcode.6, compare) with suggestions, mainly fixing up whitespace and renaming the new types

  32. ryanofsky referenced this in commit 7d97076cb7 on Jul 5, 2022
  33. ryanofsky force-pushed on Jul 5, 2022
  34. ryanofsky referenced this in commit 9ac9a11d4a on Jul 5, 2022
  35. ryanofsky force-pushed on Jul 5, 2022
  36. ryanofsky referenced this in commit 27abc29b88 on Jul 5, 2022
  37. ryanofsky commented at 9:06 pm on July 5, 2022: contributor
    Rebased 7d97076cb7d4020110a830ae9fe4107f82511c41 -> 9ac9a11d4aa1c051c9d486657ff3021019e802e5 (pr/retcode.6 -> pr/retcode.7, compare) due to conflict with #25290
  38. in src/init.cpp:1445 in 9ac9a11d4a outdated
    1459+        options.check_level = args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL);
    1460+        options.check_interrupt = ShutdownRequested;
    1461+        options.coins_error_cb = [] {
    1462                                                   uiInterface.ThreadSafeMessageBox(
    1463                                                                                    _("Error reading from database, shutting down."),
    1464                                                                                    "", CClientUIInterface::MSG_ERROR);
    


    furszy commented at 3:11 pm on July 11, 2022:
    nit: indentation here seems to be screwed.

    ryanofsky commented at 4:27 pm on July 11, 2022:

    nit: indentation here seems to be screwed.

    I can change it if desired, but it was actually intentional to just move these lines without changing the indentation

  39. in src/node/chainstate.cpp:107 in ca5862538b outdated
    91         }
    92 
    93         // ReplayBlocks is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate
    94         if (!chainstate->ReplayBlocks()) {
    95-            return ChainstateLoadingError::ERROR_REPLAYBLOCKS_FAILED;
    96+            return {ChainstateLoadStatus::FAILURE, _("Unable to replay blocks. You will need to rebuild the database using -reindex-chainstate.")};
    


    furszy commented at 3:25 pm on July 11, 2022:

    Not for this PR but thinking about possible translations errors: shouldn’t we remove -reindex-chainstate from the translatable string?

    0            return {ChainstateLoadStatus::FAILURE, strprintf(_("Unable to replay blocks. You will need to rebuild the database using %s."), "-reindex-chainstate")};
    

    (Same for the rest startup flags on this function)

  40. furszy commented at 3:32 pm on July 11, 2022: member

    Code review ACK 9ac9a11d

    A tiny non-blocking nit and an extra comment to improve in a future PR only.

  41. in src/node/chainstate.h:25 in 9237c2295d outdated
    17@@ -16,6 +18,23 @@ struct Params;
    18 } // namespace Consensus
    19 
    20 namespace node {
    21+
    22+struct CacheSizes;
    23+
    24+struct ChainstateLoadOptions
    25+{
    


    MarcoFalke commented at 8:55 am on July 12, 2022:
    nit in the first commit: clang-format this new line?

    ryanofsky commented at 5:11 pm on July 12, 2022:

    re: #25308 (review)

    nit in the first commit: clang-format this new line?

    Thanks, ran clang-format here and elsewhere

  42. in src/node/chainstate.h:33 in 9237c2295d outdated
    28+    bool coins_db_in_memory = false;
    29+    bool reindex = false;
    30+    bool reindex_chainstate = false;
    31+    bool prune = false;
    32+    int64_t check_blocks = DEFAULT_CHECKBLOCKS;
    33+    int64_t check_level = DEFAULT_CHECKLEVEL;
    


    MarcoFalke commented at 8:56 am on July 12, 2022:
    first commit: Use {} over = to enable narrowing warnings for integers?

    ryanofsky commented at 5:11 pm on July 12, 2022:

    re: #25308 (review)

    first commit: Use {} over = to enable narrowing warnings for integers?

    Thanks, changed

  43. in src/init.cpp:1460 in 9237c2295d outdated
    1456+        options.prune = node::fPruneMode;
    1457+        options.check_blocks = args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS);
    1458+        options.check_level = args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL);
    1459+        options.check_interrupt = ShutdownRequested;
    1460+        options.coins_error_cb = [] {
    1461+                                                  uiInterface.ThreadSafeMessageBox(
    


    MarcoFalke commented at 8:57 am on July 12, 2022:
    nit in the first commit: It is possible to ignore moved space changes: --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space, so adjusting it should be fine.

    ryanofsky commented at 5:10 pm on July 12, 2022:

    re: #25308 (review)

    nit in the first commit: It is possible to ignore moved space changes: --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space, so adjusting it should be fine.

    Thanks, fixed indentation

  44. in src/bitcoin-chainstate.cpp:92 in 9237c2295d outdated
     98+    node::CacheSizes cache_sizes;
     99+    cache_sizes.block_tree_db = 2 << 20;
    100+    cache_sizes.coins_db = 2 << 22;
    101+    cache_sizes.coins = (450 << 20) - (2 << 20) - (2 << 22);
    102+    node::ChainstateLoadOptions options;
    103+    options.coins_error_cb = [] { return false; };
    


    MarcoFalke commented at 9:03 am on July 12, 2022:
    First commit: This is wrong, see options.check_interrupt.

    MarcoFalke commented at 12:01 pm on July 12, 2022:
    Why does this even compile? coins_error_cb is of type std::function<void()>, but this lambda returns a bool

    ryanofsky commented at 5:10 pm on July 12, 2022:

    re: #25308 (review)

    Why does this even compile? coins_error_cb is of type std::function<void()>, but this lambda returns a bool

    Good catch! Changed coins_error_cb to check_interrupt. I think this change would not actually have caused a problem in the bitcoin-chainstate example program, but now the new code should be more obviously equivalent to the previous code.

    Reason it compiled is that the lambda is Callable with arguments and return type of the std::function. Rules about what can be assigned to a std::function are https://en.cppreference.com/w/cpp/utility/functional/function/operator%3D

  45. in src/node/chainstate.cpp:42 in 9237c2295d outdated
    42     auto& pblocktree{chainman.m_blockman.m_block_tree_db};
    43     // new CBlockTreeDB tries to delete the existing file, which
    44     // fails if it's still open from the previous loop. Close it first:
    45     pblocktree.reset();
    46-    pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, block_tree_db_in_memory, fReset));
    47+    pblocktree.reset(new CBlockTreeDB(cache_sizes.block_tree_db, options.block_tree_db_in_memory, options.reindex));
    


    MarcoFalke commented at 9:27 am on July 12, 2022:
    unrelated nit in the first commit: Could use std::make_unique, which is used in most other places over new?

    ryanofsky commented at 5:11 pm on July 12, 2022:

    re: #25308 (review)

    unrelated nit in the first commit: Could use std::make_unique, which is used in most other places over new?

    Yes there is basically no reason to use new anywhere. Just to keep this commit straightforward I would not want to change this here, especially since pblocktree is an auto reference and it’s not totally obvious that it is a unique_ptr. But I’d happily review followups replacing new with make_unique here and elsewhere.

  46. in src/node/chainstate.cpp:35 in 9237c2295d outdated
    49-    if (fReset) {
    50+    if (options.reindex) {
    51         pblocktree->WriteReindexing(true);
    52         //If we're reindexing in prune mode, wipe away unusable block files and all undo data files
    53-        if (fPruneMode)
    54+        if (options.prune)
    


    MarcoFalke commented at 9:27 am on July 12, 2022:
    nit: Add missing { while touching this line?

    ryanofsky commented at 5:11 pm on July 12, 2022:

    re: #25308 (review)

    nit: Add missing { while touching this line?

    Added

  47. in src/node/chainstate.cpp:44 in 9237c2295d outdated
    61     // LoadBlockIndex will load m_have_pruned if we've ever removed a
    62     // block file from disk.
    63-    // Note that it also sets fReindex based on the disk flag!
    64-    // From here on out fReindex and fReset mean something different!
    65+    // Note that it also sets fReindex global based on the disk flag!
    66+    // From here on out fReindex and options.reindex values may be different!
    


    MarcoFalke commented at 9:30 am on July 12, 2022:
    first commit: What does “out” mean? Maybe remove it?

    ryanofsky commented at 5:11 pm on July 12, 2022:

    re: #25308 (review)

    first commit: What does “out” mean? Maybe remove it?

    Dropped “out”. here on out is just more verbose

  48. in src/test/util/setup_common.cpp:224 in 9237c2295d outdated
    229-                                           /*coins_db_in_memory=*/true);
    230+    node::ChainstateLoadOptions options;
    231+    options.mempool = Assert(m_node.mempool.get());
    232+    options.block_tree_db_in_memory = true;
    233+    options.coins_db_in_memory = true;
    234+    options.reindex = node::fReindex.load();
    


    MarcoFalke commented at 9:32 am on July 12, 2022:
    first commit: I think load is not needed in this context, as the compiler can infer the type?

    ryanofsky commented at 5:11 pm on July 12, 2022:

    re: #25308 (review)

    first commit: I think load is not needed in this context, as the compiler can infer the type?

    Thanks, dropped

  49. in src/test/util/setup_common.cpp:229 in 9237c2295d outdated
    234+    options.reindex = node::fReindex.load();
    235+    options.reindex_chainstate = m_args.GetBoolArg("-reindex-chainstate", false);
    236+    options.prune = node::fPruneMode;
    237+    options.check_blocks = m_args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS);
    238+    options.check_level = m_args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL);
    239+    auto maybe_load_error = LoadChainstate(*Assert(m_node.chainman.get()), m_cache_sizes, options);
    


    MarcoFalke commented at 9:37 am on July 12, 2022:
    first commit: I think get is not needed? (Calling * on a reference to a unique ptr’s underlying raw pointer is equal to calling * on a reference to the unique ptr ?)

    ryanofsky commented at 5:16 pm on July 12, 2022:

    re: #25308 (review)

    first commit: I think get is not needed? (Calling * on a reference to a unique ptr’s underlying raw pointer is equal to calling * on a reference to the unique ptr ?)

    Thanks, dropped

  50. MarcoFalke commented at 9:41 am on July 12, 2022: member

    there is a bug in 9237c2295d9aa3d5e184db3da37760d7c78cdc27 🚆

    Signature:

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA512
     2
     3there is a bug in 9237c2295d9aa3d5e184db3da37760d7c78cdc27 🚆
     4-----BEGIN PGP SIGNATURE-----
     5
     6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
     7pUjNQAv/Zs7YW1PwWfHH+yRuxXGJ6sfoSy4e0PeSKwgs9dLOkPxtvj1jE7y2HK+q
     80Hxv4C98L3zGI223Gz0dC1q7urfYykO0erS7Dd5yYnVA8Vkfq5Lg+22xramAYOPu
     9X9XHtyZi74y5H/vxw8DFQAqGUppzZIuyD8UA/h0RvUbbHPZmwsd/z6UFQlHYGIak
    10vTPzwa7XbtEm/tfF9Qo6zQyU1ukbBxMx6Mm787C0X8pKSiz0RNTvOEGXB+csxBOu
    119WH5b0q4hKMcwZwY54I8UJ4UPiG1id2YF5LVb4Ce3R2hHrKoWBJWbaMcFR6wnG0I
    12TEbqiTACEC1uS6C8uMlw1jdRq1YFXNXYOxnegrunwPbbOcdboaizNMjd93TpPUXi
    13MZhGNfrDhP+Vki9wRDfRJNb+QBeSJawDpSORMqSqoFPlWWVnEErVzx6/5i8WBZa4
    1424VJ9ophDcgmIALKDSCnjVKJnur5gnkzIGJA4fLdJQhlX5kg7SL1IVeXpeeq2L6p
    15Czc262DE
    16=dehA
    17-----END PGP SIGNATURE-----
    
  51. ryanofsky referenced this in commit e022eaf87c on Jul 12, 2022
  52. ryanofsky force-pushed on Jul 12, 2022
  53. ryanofsky commented at 6:44 pm on July 12, 2022: contributor

    Updated 9ac9a11d4aa1c051c9d486657ff3021019e802e5 -> e022eaf87c65e8d7d27d8f5fa4cadc359c843e8a (pr/retcode.7 -> pr/retcode.8, compare) with suggested changes

    re: #25308 (comment)

    Could use 316afb1 ?

    Unfortunately, this does not work because BResult does not support returning an error string and an error status at the same time. This is why I was discouraging the std::variant implementation in #25218 in favor of it having a std::optional<bilingual_str> error field. I think BResult can be extended to cover this case, though, and I will follow up with another PR to incorporate it. I think it would expand the scope of this PR too much to try to extend BResult here, though.

  54. in src/bitcoin-chainstate.cpp:98 in fac56cb261 outdated
     97         std::cerr << "Failed to load Chain state from your datadir." << std::endl;
     98         goto epilogue;
     99     } else {
    100-        auto maybe_verify_error = node::VerifyLoadedChainstate(chainman, options);
    101-        if (maybe_verify_error.has_value()) {
    102+        std::tie(status, error) = node::VerifyLoadedChainstate(chainman, options);
    


    MarcoFalke commented at 10:04 am on July 13, 2022:
    second commit: Any reason to overwrite/shadow this? Should be fine to have [load_status, load_error] and [verify_status, verify_error]?

    ryanofsky commented at 11:59 am on July 13, 2022:

    re: #25308 (review)

    second commit: Any reason to overwrite/shadow this? Should be fine to have [load_status, load_error] and [verify_status, verify_error]?

    If you look at init.cpp you can see how error handling would get more complicated with multiple status and error values. This example program doesn’t have any error handling (right now), but the logic of using one status and error variable to represent the latest status instead of multiple variables to previous statuses still applies. It keeps function state simpler and is less prone to errors from referencing the wrong variable.

    More broadly though the whole LoadChainState / VerifyLoadedChainstate separation seems janky to me. And the logging and timing init.cpp code is doing around these calls also seems awkward. I think a good followup to this PR would get rid for VerifyLoadedChainstate function and just add an bool verify option to ChainstateLoadOptions and move more logging and timing code out of init.cpp.

  55. in src/node/chainstate.h:57 in fac56cb261 outdated
    80-};
    81-
    82-std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManager& chainman,
    83-                                                                const ChainstateLoadOptions& options);
    84+ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSizes& cache_sizes,
    85+                                    const ChainstateLoadOptions& options);
    


    MarcoFalke commented at 10:10 am on July 13, 2022:
    second commit: I wonder if it was easier to review if the two functions were converted in separate commits?

    ryanofsky commented at 12:07 pm on July 13, 2022:

    re: #25308 (review)

    second commit: I wonder if it was easier to review if the two functions were converted in separate commits?

    I think it would be harder to review and introduce the potential for bugs in the intermediate commit. If you look code calling these functions in init.cpp you can see it has a lot of cases that need to be handled, and a twisty control flow involving exceptions and changing intermediate variables and timing and log statements. It seems like less of a burden on reviewers and less error prone to update the init.cpp code in one shot, than to change the same code twice and leave it in an intermediate state where the load and verify calls don’t have consistent return styles.

  56. MarcoFalke commented at 10:10 am on July 13, 2022: member

    review ACK c7c3059507 🍈

    Signature:

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA512
     2
     3review ACK c7c3059507 🍈
     4-----BEGIN PGP SIGNATURE-----
     5
     6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
     7pUg6KQv/dRTmRfl2ssxhtuwmONucZd9Ip3Gtl8RLmSZjPBiS2mOO6dD34ZNt1NL7
     8/d3chuy5aAf2c3LtQKA0j0qzWQOvb0mz3jUAFiBS50RK/rUAzzcBrvSZpyv/F4IL
     9SA3M0gNEfytNxV0uwk8aGAUPAVqoH1hveT2O7NHKcQNEoBq/cchW6TBoQZVZz13E
    10IXDuETCcbHp8mXEDSKT+JSDxt5bDBVYJHO9/c3XJO6B7gb2/FWsnx1pgRqmD0iDu
    11XD5O9GXq1a8b/hohPHEp7q0VF6m3FOj7fsvlx7g69x6Y0oCoKKtLOAfrbpZUAVm6
    12BtU1JzZ0NO9FiAyEsra9z4VymzryaCC488cZMeaQz7SqYaot0vdYTCEHrNJQHk4A
    13XnvPjhJbZ+OYIH6a9aWWNPuxK94mjMVCJpzsO2JGF+mzp96W5OGggEDmmffqo5hC
    14uRwmmFTBQiX+SRDiae1/8aWbjDReb19He3CvvJ7Ffyo1F/uDUCqLn6ghRRIIj6Ep
    15T7mVO8bS
    16=ITtH
    17-----END PGP SIGNATURE-----
    
  57. ryanofsky commented at 12:30 pm on July 13, 2022: contributor
    Thanks for the review!
  58. ryanofsky referenced this in commit 39769cc059 on Jul 13, 2022
  59. jamesob approved
  60. jamesob commented at 6:40 pm on July 13, 2022: member

    ACK e022eaf87c65e8d7d27d8f5fa4cadc359c843e8a (jamesob/ackr/25308.1.ryanofsky.refactor_reduce_number_o)

    The line count reduction speaks for itself! Nice refactor. Initially I was a little sad to lose the error value enums for the chainstate initialization functions, but if we aren’t testing on them or really using them for anything aside from mapping to error strings, I agree that it’s fine to forego them.

    Read through commits locally and built each one.

  61. ryanofsky commented at 2:28 pm on July 18, 2022: contributor
    Ready for merge maybe, or needs more review?
  62. DrahtBot added the label Needs rebase on Jul 18, 2022
  63. ryanofsky referenced this in commit 303b1d17ac on Jul 18, 2022
  64. ryanofsky force-pushed on Jul 18, 2022
  65. ryanofsky referenced this in commit 2387adab96 on Jul 18, 2022
  66. ryanofsky commented at 7:21 pm on July 18, 2022: contributor
    Rebased e022eaf87c65e8d7d27d8f5fa4cadc359c843e8a -> 303b1d17ac983c2e36ef2b6908acbb0a9c6fd606 (pr/retcode.8 -> pr/retcode.9, compare) due to conflict with #25487
  67. DrahtBot removed the label Needs rebase on Jul 18, 2022
  68. DrahtBot added the label Needs rebase on Jul 19, 2022
  69. ryanofsky referenced this in commit fb31664f94 on Jul 19, 2022
  70. ryanofsky force-pushed on Jul 19, 2022
  71. ryanofsky referenced this in commit f08742962d on Jul 19, 2022
  72. ryanofsky commented at 3:12 pm on July 19, 2022: contributor
    Rebased 303b1d17ac983c2e36ef2b6908acbb0a9c6fd606 -> fb31664f94451c51c77393b53274f3a8867ed1d6 (pr/retcode.9 -> pr/retcode.10, compare) due to conflict with #25466
  73. ryanofsky referenced this in commit fce2b7cec1 on Jul 19, 2022
  74. ryanofsky referenced this in commit dd91f29420 on Jul 19, 2022
  75. MarcoFalke commented at 4:51 pm on July 19, 2022: member

    ACK fb31664f94451c51c77393b53274f3a8867ed1d6 🚤

    Signature:

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA512
     2
     3ACK fb31664f94451c51c77393b53274f3a8867ed1d6 🚤
     4-----BEGIN PGP SIGNATURE-----
     5
     6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
     7pUjCIwv/YUURfo7o0AVAGSJZRLACHRy+lzHJIkI3aMdh895dYKmo1d1aVDNZd2XL
     8K6vTGMf2S6RgE4xvtRCz57c5KrfTcjlEgyT1xzZ9ybNOKjnf2a06emZLvgM1T5bg
     9i4cp4PJYqJkYlttNqXWawUuUlevYi/eD7uZMQyx2s61AAfWjJM0I8+idJYPmhzWg
    10KPMaF6U3amHCX4CRMjQRWUQNlzu1ZZz3d5pBIj+VtVDJ+GnW6NOvgUgsarQD5GQ7
    11KmQisteypNvSqd2lRZhIvqr0MLUKoowJlXpDzNZAjtDckC68kBtFPzRRW3ybKlEu
    12j7lH3wRpj46rgC1GP8JOWNQ+mJHkKLy9o3lIsT1JCM6vHiOXcH98WmnkEJFIXcix
    13dzmmURN+fh+JjL0Ft127iJa40R1mxqxQ/sI/xXgIAkzuZon7Xqt5otU7NhAJgLIf
    14fDt6usRDhVD0XD848xpUJ7XkFxlK9BuTAO6BmyWYW7x0naR8O1vGKw6ujiya28u4
    15jVaEjRYP
    16=vMWy
    17-----END PGP SIGNATURE-----
    
  76. DrahtBot removed the label Needs rebase on Jul 19, 2022
  77. refactor: Reduce number of LoadChainstate parameters 3b91d4b994
  78. refactor: Reduce number of LoadChainstate return values b3e7de7ee6
  79. refactor: Reduce number of SanityChecks return values 6db6552377
  80. ci: Enable IWYU in src/kernel directory
    Suggested https://github.com/bitcoin/bitcoin/pull/25308#discussion_r892505713
    1e761a0169
  81. DrahtBot added the label Needs rebase on Jul 19, 2022
  82. ryanofsky referenced this in commit fb951753d4 on Jul 19, 2022
  83. ryanofsky force-pushed on Jul 19, 2022
  84. ryanofsky commented at 10:01 pm on July 19, 2022: contributor
    Rebased fb31664f94451c51c77393b53274f3a8867ed1d6 -> 1e761a0169ebdbd3b5784af39fc2248b4546eeea (pr/retcode.10 -> pr/retcode.11, compare) due to conflicts with #25494 and #25645
  85. DrahtBot removed the label Needs rebase on Jul 19, 2022
  86. MarcoFalke commented at 5:48 am on July 20, 2022: member

    ACK 1e761a0169ebdbd3b5784af39fc2248b4546eeea 🕚

    Signature:

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA512
     2
     3ACK 1e761a0169ebdbd3b5784af39fc2248b4546eeea 🕚
     4-----BEGIN PGP SIGNATURE-----
     5
     6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
     7pUj60wv+IY0G/RNQGAu7vVe19qrbdpSiDWKDuTcsbjIn4nLmwav/SkKO9CbdbUe3
     8n4oVsfVGmhksUF/DrTbEd0qrQMw4SH6rUemfrRiQAW5RyZuj9H6uzw7/Kg5xdI5l
     94qzP4xf3WLgCJ4Aqk41O3Y1lOyqE0zTt9YVznWutNGGJZh3dYD34kyGGCSd78BbD
    10RCaa7ap+sJCF5HQF+aJXqslvBAKvJ0+sXzpbMmOnX2AAUNkYsuGeWOn+5OnKlGgA
    11awx5snXIwNDKGrkfUoUeqeP7nVMLjSAqt+HNZYlS6hV7NPL8raxvJhQAVteACOje
    12LTFft7Zrni4IzM5ozXVQwpgVAVrCJ/L3pRm90XXvSTWELo07OWj7Dxni/F1twD93
    13wY9767zZEfON2Wb/SP33a9DlRbA/o8iVFswfv/Cqzjtl3T+RV9RWgi0ZF3UMpx+q
    14xwmLnunLT7hI5MvPKGtyVPZTybK8rn72G1uamb0wLXDh8hCZI2qbZssgfTiJtgm6
    15PMzwpr5X
    16=jnK3
    17-----END PGP SIGNATURE-----
    
  87. MarcoFalke merged this on Jul 20, 2022
  88. MarcoFalke closed this on Jul 20, 2022

  89. sidhujag referenced this in commit 51ff6f820b on Jul 20, 2022
  90. ryanofsky referenced this in commit 779966d0c1 on Jul 21, 2022
  91. ryanofsky referenced this in commit f32c57681c on Jul 21, 2022
  92. ryanofsky referenced this in commit 7de05b35d4 on Jul 21, 2022
  93. ryanofsky referenced this in commit dce1d50d2a on Jul 21, 2022
  94. ryanofsky referenced this in commit ef269ce087 on Jul 22, 2022
  95. ryanofsky referenced this in commit 3faf5dc77c on Jul 22, 2022
  96. ryanofsky referenced this in commit 48f543a578 on Jul 25, 2022
  97. ryanofsky referenced this in commit 74fd5f621d on Jul 26, 2022
  98. stickies-v referenced this in commit 917b82d5ae on Aug 2, 2022
  99. Rspigler referenced this in commit 0effd0114d on Aug 21, 2022
  100. aguycalled referenced this in commit 30f4f832c0 on Aug 25, 2022
  101. mxaddict referenced this in commit d13efa1944 on Aug 29, 2022
  102. janus referenced this in commit f082991e8b on Jan 20, 2023
  103. bitcoin locked this on Jul 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-12-19 06:12 UTC

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