Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13711129
D17736.id52887.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
D17736.id52887.diff
View Options
diff --git a/src/bitcoin-chainstate.cpp b/src/bitcoin-chainstate.cpp
--- a/src/bitcoin-chainstate.cpp
+++ b/src/bitcoin-chainstate.cpp
@@ -72,7 +72,7 @@
// We can't use a goto here, but we can use an assert since none of the
// things instantiated so far requires running the epilogue to be torn down
// properly
- assert(!kernel::SanityChecks(kernel_context).has_value());
+ assert(kernel::SanityChecks(kernel_context));
// Necessary for CheckInputScripts (eventually called by ProcessNewBlock),
// which will try the script cache first and fall back to actually
diff --git a/src/init.cpp b/src/init.cpp
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -2082,23 +2082,9 @@
bool AppInitSanityChecks(const kernel::Context &kernel) {
// Step 4: sanity checks
- auto maybe_error = kernel::SanityChecks(kernel);
-
- if (maybe_error.has_value()) {
- switch (maybe_error.value()) {
- case kernel::SanityCheckError::ERROR_ECC:
- InitError(Untranslated("Elliptic curve cryptography sanity "
- "check failure. Aborting."));
- break;
- case kernel::SanityCheckError::ERROR_RANDOM:
- InitError(Untranslated(
- "OS cryptographic RNG sanity check failure. Aborting."));
- break;
- case kernel::SanityCheckError::ERROR_CHRONO:
- InitError(Untranslated("Clock epoch mismatch. Aborting."));
- break;
- } // no default case, so the compiler can warn about missing cases
-
+ auto result{kernel::SanityChecks(kernel)};
+ if (!result) {
+ InitError(util::ErrorString(result));
return InitError(strprintf(
_("Initialization sanity check failed. %s is shutting down."),
PACKAGE_NAME));
diff --git a/src/kernel/checks.h b/src/kernel/checks.h
--- a/src/kernel/checks.h
+++ b/src/kernel/checks.h
@@ -5,22 +5,16 @@
#ifndef BITCOIN_KERNEL_CHECKS_H
#define BITCOIN_KERNEL_CHECKS_H
-#include <optional>
+#include <util/result.h>
namespace kernel {
struct Context;
-enum class SanityCheckError {
- ERROR_ECC,
- ERROR_RANDOM,
- ERROR_CHRONO,
-};
-
/**
* Ensure a usable environment with all necessary library support.
*/
-std::optional<SanityCheckError> SanityChecks(const Context &);
+util::Result<void> SanityChecks(const Context &);
} // namespace kernel
diff --git a/src/kernel/checks.cpp b/src/kernel/checks.cpp
--- a/src/kernel/checks.cpp
+++ b/src/kernel/checks.cpp
@@ -7,23 +7,26 @@
#include <key.h>
#include <random.h>
#include <util/time.h>
+#include <util/translation.h>
namespace kernel {
-std::optional<SanityCheckError> SanityChecks(const Context &) {
+util::Result<void> SanityChecks(const Context &) {
if (!ECC_InitSanityCheck()) {
- return SanityCheckError::ERROR_ECC;
+ return util::Error{Untranslated(
+ "Elliptic curve cryptography sanity check failure. Aborting.")};
}
if (!Random_SanityCheck()) {
- return SanityCheckError::ERROR_RANDOM;
+ return util::Error{Untranslated(
+ "OS cryptographic RNG sanity check failure. Aborting.")};
}
if (!ChronoSanityCheck()) {
- return SanityCheckError::ERROR_CHRONO;
+ return util::Error{Untranslated("Clock epoch mismatch. Aborting.")};
}
- return std::nullopt;
+ return {};
}
} // namespace kernel
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 26, 10:35 (3 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5572374
Default Alt Text
D17736.id52887.diff (3 KB)
Attached To
D17736: refactor: Reduce number of SanityChecks return values and return util::Result
Event Timeline
Log In to Comment