init: Some small chainstate load improvements #31046

pull TheCharlatan wants to merge 6 commits into bitcoin:master from TheCharlatan:chainstate_init_followup changing 3 files +27 −21
  1. TheCharlatan commented at 10:49 am on October 7, 2024: contributor

    These are mostly followups from #30968, making the code, log lines, error messages, and comments more consistent.

    The last commit is an attempt at improving the error reporting when loading the chainstate. It aims to more cleanly distinguish between errors arising from a specific database, and errors where the culprit may be less clear.

  2. init: Remove unneeded argument for mempool_opts checks baea842ff1
  3. init: Improve comment describing chainstate load retry behaviour 720ce880a3
  4. init: Remove misleading log line when user chooses not to retry
    It is bad, because it is both printed for non-GUI users and does not
    convey additional information.
    
    Co-authored-by: Martin Zumsande <mzumsande@gmail.com>
    635e9f85d7
  5. init: Remove incorrect comment about shutdown condition
    Shutdown is indeed called, and it being overkill does not make sense
    either.
    cd093049dd
  6. DrahtBot commented at 10:49 am on October 7, 2024: contributor

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

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #31061 (refactor: Check translatable format strings at compile-time by maflcko)
    • #30965 (kernel: Move block tree db open to block manager by TheCharlatan)

    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.

  7. DrahtBot added the label CI failed on Oct 7, 2024
  8. TheCharlatan force-pushed on Oct 7, 2024
  9. DrahtBot removed the label CI failed on Oct 7, 2024
  10. in src/node/chainstate.cpp:51 in 1bec418e77 outdated
    52+            .path = chainman.m_options.datadir / "blocks" / "index",
    53+            .cache_bytes = static_cast<size_t>(cache_sizes.block_tree_db),
    54+            .memory_only = options.block_tree_db_in_memory,
    55+            .wipe_data = options.wipe_block_tree_db,
    56+            .options = chainman.m_options.block_tree_db});
    57+    } catch (dbwrapper_error&) {
    


    stickies-v commented at 11:08 am on October 8, 2024:

    Note: instantiating a CDBWrapper can throw other errors such as a fs::filesystem_error from here, but I suppose that is not something the user can recover from with a reindex so not catching that here seems correct.

    I think it logging the dbwrapper_error would be useful though?

     0diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp
     1index 76094105fa..b9c3981910 100644
     2--- a/src/node/chainstate.cpp
     3+++ b/src/node/chainstate.cpp
     4@@ -48,8 +48,10 @@ static ChainstateLoadResult CompleteChainstateInitialization(
     5             .memory_only = options.block_tree_db_in_memory,
     6             .wipe_data = options.wipe_block_tree_db,
     7             .options = chainman.m_options.block_tree_db});
     8-    } catch (dbwrapper_error&) {
     9-        return {ChainstateLoadStatus::FAILURE, _("Error opening block database")};
    10+    } catch (dbwrapper_error& err) {
    11+        auto msg{_("Error opening block database")};
    12+        LogError("%s: %s\n", msg.original, err.what());
    13+        return {ChainstateLoadStatus::FAILURE, msg};
    14     }
    15 
    16     if (options.wipe_block_tree_db) {
    17@@ -116,8 +118,10 @@ static ChainstateLoadResult CompleteChainstateInitialization(
    18                 /*cache_size_bytes=*/chainman.m_total_coinsdb_cache * init_cache_fraction,
    19                 /*in_memory=*/options.coins_db_in_memory,
    20                 /*should_wipe=*/options.wipe_chainstate_db);
    21-        } catch (dbwrapper_error&) {
    22-            return {ChainstateLoadStatus::FAILURE, _("Error opening coins database")};
    23+        } catch (dbwrapper_error& err) {
    24+            auto msg{_("Error opening coins database")};
    25+            LogError("%s: %s\n", msg.original, err.what());
    26+            return {ChainstateLoadStatus::FAILURE, msg};
    27         }
    28 
    29         if (options.coins_error_cb) {
    
  11. stickies-v commented at 11:42 am on October 8, 2024: contributor
    Approach ACK 1bec418e77482a4c53c8f1e7c89a151fdeae0f8e
  12. mzumsande commented at 5:09 pm on October 8, 2024: contributor
    one more small thing that I noticed reviewing #30968 (it wasn’t really on-topic there, but fits with the last commit here): I don’t think that we should return ChainstateLoadStatus::FAILURE in https://github.com/bitcoin/bitcoin/blob/5837e3463fe188a65d67f96e84cbcca674d61d9e/src/node/chainstate.cpp#L239 (snapshot validation failure). This is not a problem where a general reindex would typically help, and is handled inside of validation (InvalidateCoinsDBOnDisk) anyway, so something like node::ChainstateLoadStatus::FAILURE_FATAL might be bettter.
  13. init: Improve chainstate init db error messages
    They should name the correct source of an error, or be generic if no
    clear source can be ascertained.
    8f1246e833
  14. init: Return fatal failure on snapshot validation failure
    A general reindex won't typically help in this case, and there is
    already some action being taken with the call to
    `InvalidateCoinsDBOnDisk`.
    31cc5006c3
  15. TheCharlatan force-pushed on Oct 8, 2024
  16. TheCharlatan commented at 8:50 pm on October 8, 2024: contributor

    Thank you for the reviews @mzumsande and @stickies-v,

    Updated 1bec418e77482a4c53c8f1e7c89a151fdeae0f8e -> a7a02b09fafe9d03e5db1fb9d9600f6a13aaa852 (chainstate_init_followup_0 -> chainstate_init_followup_1, compare)

  17. mzumsande commented at 6:12 pm on October 9, 2024: contributor
    Code Review / lightly tested ACK 31cc5006c3de4dd6a1f7a238684163956604df45
  18. DrahtBot requested review from stickies-v on Oct 9, 2024
  19. BrandonOdiwuor commented at 7:49 pm on October 17, 2024: contributor

    Code Review ACK 31cc5006c3de4dd6a1f7a238684163956604df45.

    Nice work on the chainstate loading improvements, especially the enhanced handling of database-specific errors.

  20. in src/node/chainstate.cpp:246 in 31cc5006c3
    245@@ -236,7 +246,7 @@ ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSize
    246             return {init_status, init_error};
    


    stickies-v commented at 12:37 pm on October 18, 2024:

    unrelated nit / probably scope creep but it is a “small chainstate load improvement” so leaving here anyway, can be simplified:

     0diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp
     1index fa8d7a386f..4837135dee 100644
     2--- a/src/node/chainstate.cpp
     3+++ b/src/node/chainstate.cpp
     4@@ -240,11 +240,7 @@ ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSize
     5         // A reload of the block index is required to recompute setBlockIndexCandidates
     6         // for the fully validated chainstate.
     7         chainman.ActiveChainstate().ClearBlockIndexCandidates();
     8-
     9-        auto [init_status, init_error] = CompleteChainstateInitialization(chainman, cache_sizes, options);
    10-        if (init_status != ChainstateLoadStatus::SUCCESS) {
    11-            return {init_status, init_error};
    12-        }
    13+        return CompleteChainstateInitialization(chainman, cache_sizes, options);
    14     } else {
    15         return {ChainstateLoadStatus::FAILURE_FATAL, _(
    16            "UTXO snapshot failed to validate. "
    

    stickies-v commented at 3:00 pm on October 18, 2024:
    Hmm, then again, that breaks the pattern here of only (explicitly) returning early for failure, so could also leave as-is.

    TheCharlatan commented at 5:28 pm on October 19, 2024:
    I think your suggestion is a bit better. I’ll push it if something else comes up. Looks to me like that code iterated over the chainstates in a previous un-pushed version, that would explain why only the errors are surfaced here. There is also ryanofsky’s assumeutxo state cleanup PR that could catch this later if we don’t get it here
  21. stickies-v approved
  22. stickies-v commented at 2:54 pm on October 18, 2024: contributor
    ACK 31cc5006c3de4dd6a1f7a238684163956604df45
  23. laanwj added the label UTXO Db and Indexes on Oct 20, 2024
  24. achow101 commented at 9:42 pm on October 23, 2024: member
    ACK 31cc5006c3de4dd6a1f7a238684163956604df45
  25. achow101 merged this on Oct 23, 2024
  26. achow101 closed this on Oct 23, 2024


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