Make wallet DB properly detect and report failure to scan wallet directory. Seems to have been broken since moving from Boost to std::filesystem.
Found while reviewing: #31410#pullrequestreview-2604068753
Make wallet DB properly detect and report failure to scan wallet directory. Seems to have been broken since moving from Boost to std::filesystem.
Found while reviewing: #31410#pullrequestreview-2604068753
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32736.
See the guideline for information on the review process.
Type | Reviewers |
---|---|
Stale ACK | maflcko |
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
Reviewers, this pull request conflicts with the following ones:
wallet_multiwallet.py
by hebasto)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.
https://cirrus-ci.com/task/6556243914915840?logs=ci#L4845:
0[09:50:58.842] AssertionError: [node 0] Expected messages "['Error scanning directory entries under']" does not partially match log:
77@@ -78,6 +78,15 @@ def wallet_file(name):
78 self.stop_nodes()
79 assert_equal(os.path.isfile(wallet_dir(self.default_wallet_name, self.wallet_data_filename)), True)
80
81+ self.log.info("Verify warning is emitted when failing to scan the wallets directory")
82+ os.chmod(data_dir('wallets'), 0)
32@@ -33,6 +33,7 @@ std::vector<std::pair<fs::path, std::string>> ListDatabases(const fs::path& wall
33 } else {
34 LogPrintf("%s: %s %s\n", __func__, ec.message(), fs::PathToString(it->path()));
35 }
36+ ec.clear();
is this code ever hit? At least corecheck shows it as dead code and according to the docs any error should always lead to the end iterator, which already breaks the loop, no?
https://en.cppreference.com/w/cpp/filesystem/recursive_directory_iterator.html says: “If the recursive_directory_iterator reports an error […], it becomes equal to the default-constructed iterator, also known as the end iterator.”
assert(!ec)
. Seems to be leftovers from Boost filesystem. Updated PR title/description.
74+ // Loop could have exited with an error due to one of:
75+ // * wallet_dir itself not being scannable.
76+ // * increment() failure. (Observed on Windows native builds when
77+ // removing the ACL read permissions of a wallet directory after the
78+ // process started).
79+ LogWarning("Error scanning directory entries under %s, loop probably aborted: %s", fs::PathToString(wallet_dir), ec.message());
85+ self.log.warning('Skipping test involving chmod as it requires a non-root user.')
86+ else:
87+ os.chmod(data_dir('wallets'), 0)
88+ self.start_node(0)
89+ with self.nodes[0].assert_debug_log(expected_msgs=['Error scanning directory entries under']):
90+ _ = self.nodes[0].listwalletdir()
why discard the result. It should be expected to be empty, no?
nit: If you want to take an extra step, it could make sense to pass up the warnings into the result dict as "warnings": ["...",]
, instead of relying on the debug log
chmod
, then added assertion of return values in both cases. Punting on “warnings” for now.
The code looks correct, matches the upstream docs, and passes the tests. I left some nits.
review ACK 6ed17c7dca35ec820dc1c0500ef32a132c641fa5 🤜
Signature:
0untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
1RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
2trusted comment: review ACK 6ed17c7dca35ec820dc1c0500ef32a132c641fa5 🤜
38C1jo8YtfwmG7YDw/SkVQcm33apByQ744hTZUTZRr1uCttPMiBfHDSd3YQ0UxkMDHOvAMpU1SIwUm5b4tAV8AQ==
Seems to have been broken since conversion from Boost in #20744. The std::filesystem iteration aborts upon failure while Boost might have allowed skipping over faulty entries.
hodlinator
DrahtBot
fanquake
maflcko
Labels
Wallet