Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Use util::Result class for wallet loading #25722

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 27, 2022

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

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/25722.

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #bitcoin-core/gui/807 (refactor: interfaces, make 'createTransaction' less error-prone by furszy)
  • #31519 (refactor: Use std::span over Span by maflcko)
  • #31483 (kernel: Move kernel-related cache constants to kernel cache by TheCharlatan)
  • #31451 (wallet: migration, avoid loading legacy wallet after failure when BDB isn't compiled by furszy)
  • #31423 (wallet: migration, don't create spendable wallet from a watch-only legacy wallet by furszy)
  • #31250 (wallet: Disable creating and loading legacy wallets by achow101)
  • #31241 (wallet: remove BDB dependency from wallet migration benchmark by furszy)
  • #31061 (refactor: Check translatable format strings at compile-time by maflcko)
  • #30965 (kernel: Move block tree db open to block manager by TheCharlatan)
  • #30343 (wallet, logging: Replace WalletLogPrintf() with LogInfo() by ryanofsky)
  • #30221 (wallet: Ensure best block matches wallet scan state by achow101)
  • #29694 (fuzz: wallet: add target for spkm migration by brunoerg)
  • #29641 (scripted-diff: Use LogInfo over LogPrintf [WIP, NOMERGE, DRAFT] by maflcko)
  • #29278 (Wallet: Add maxfeerate wallet startup option by ismaelsadeeq)
  • #28710 (Remove the legacy wallet and BDB dependency by achow101)
  • #28333 (wallet: Construct ScriptPubKeyMans with all data rather than loaded progressively by achow101)
  • #27865 (wallet: Track no-longer-spendable TXOs separately by achow101)
  • #19461 (multiprocess: Add bitcoin-gui -ipcconnect option by ryanofsky)
  • #19460 (multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky)
  • #10102 (Multiprocess bitcoin by ryanofsky)

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.

@ryanofsky ryanofsky marked this pull request as ready for review August 15, 2022 18:18
@ryanofsky
Copy link
Contributor Author

ryanofsky commented Aug 15, 2022

Rebased a09c21c -> e7457d0 (pr/bresult-load.2 -> pr/bresult-load.3, compare) due to conflict with #25616
Rebased e7457d0 -> 874003f (pr/bresult-load.3 -> pr/bresult-load.4, compare) due to conflict with #25504
Rebased 874003f -> d020d0c (pr/bresult-load.4 -> pr/bresult-load.5, compare) on top of newer base PR #25665 tag r/bresult2.18 for derived-to-base conversion bugfix
Rebased d020d0c -> f942d92 (pr/bresult-load.5 -> pr/bresult-load.6, compare) due to silent conflict with #19602
Rebased f942d92 -> 4e53392 (pr/bresult-load.6 -> pr/bresult-load.7, compare) on top of newer version of #25665 (pr/bresult2.21)
Rebased 4e53392 -> f3d1658 (pr/bresult-load.7 -> pr/bresult-load.8, compare) due to conflict with #26021
Rebased f3d1658 -> f718aec (pr/bresult-load.8 -> pr/bresult-load.9, compare) due to conflict with #26005
Rebased f718aec -> 7bd578a (pr/bresult-load.9 -> pr/bresult-load.10, compare) due to conflicts with #25667, #26198, and #26282
Rebased 7bd578a -> 2c675f0 (pr/bresult-load.10 -> pr/bresult-load.11, compare) due to conflicts with #26238, #26462, #26594, #26618, #26758
Rebased 2c675f0 -> 2e12b25 (pr/bresult-load.11 -> pr/bresult-load.12, compare) on top of pr/bresult2.28
Rebased 2e12b25 -> 5c1be53 (pr/bresult-load.12 -> pr/bresult-load.13, compare) due to conflicts with #26595 and #26032
Rebased 5c1be53 -> 9c28172 (pr/bresult-load.13 -> pr/bresult-load.14, compare) due to conflicts with #25666 and #24845
Rebased 9c28172 -> 2a9db07 (pr/bresult-load.14 -> pr/bresult-load.15, compare) due to conflict with #27279

ryanofsky and others added 20 commits December 6, 2024 07:38
Suggested by Martin Leitner-Ankerl <[email protected]>
bitcoin#25722 (comment)

Co-authored-by: Martin Leitner-Ankerl <[email protected]>
The util::ResultPtr class is a wrapper for util::Result providing syntax sugar
to make it less awkward to use with returned pointers. Instead of needing to be
deferenced twice with **result or (*result)->member, it only needs to be
dereferenced once with *result or result->member. Also when it is used in a
boolean context, instead of evaluating to true when there is no error and the
pointer is null, it evaluates to false so it is straightforward to determine
whether the result points to something.

This PR is only partial a solution to bitcoin#26004 because while it makes it easier
to check for null pointer values, it does not make it impossible to return a
null pointer value inside a successful result. It would be possible to enforce
that successful results always contain non-null pointers by using a not_null
type (bitcoin#24423) in combination with
ResultPtr, though.
-BEGIN VERIFY SCRIPT-
git grep -l DatabaseStatus src | xargs sed -i s/DatabaseStatus/DatabaseError/g
sed -i '/^    SUCCESS,$/d' src/wallet/db.h
-END VERIFY SCRIPT-
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Dec 6, 2024
Add util::Result support for returning warning messages and multiple errors,
not just a single error string. This provides a way for functions to report
errors and warnings in a standard way, and simplifies interfaces.

The functionality is unit tested here, and put to use in followup PR
bitcoin#25722
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Dec 6, 2024
Suggested by Martin Leitner-Ankerl <[email protected]>
bitcoin#25722 (comment)

Co-authored-by: Martin Leitner-Ankerl <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants