File tree Expand file tree Collapse file tree 4 files changed +31
-12
lines changed Expand file tree Collapse file tree 4 files changed +31
-12
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ int main(int argc, char* argv[])
5656 // We can't use a goto here, but we can use an assert since none of the
5757 // things instantiated so far requires running the epilogue to be torn down
5858 // properly
59- assert (kernel::SanityChecks (kernel_context));
59+ assert (! kernel::SanityChecks (kernel_context). has_value ( ));
6060
6161 // Necessary for CheckInputScripts (eventually called by ProcessNewBlock),
6262 // which will try the script cache first and fall back to actually
Original file line number Diff line number Diff line change @@ -1094,7 +1094,21 @@ static bool LockDataDirectory(bool probeOnly)
10941094bool AppInitSanityChecks (const kernel::Context& kernel)
10951095{
10961096 // ********************************************************* Step 4: sanity checks
1097- if (!kernel::SanityChecks (kernel)) {
1097+ auto maybe_error = kernel::SanityChecks (kernel);
1098+
1099+ if (maybe_error.has_value ()) {
1100+ switch (maybe_error.value ()) {
1101+ case kernel::SanityCheckError::ERROR_ECC:
1102+ InitError (Untranslated (" Elliptic curve cryptography sanity check failure. Aborting." ));
1103+ break ;
1104+ case kernel::SanityCheckError::ERROR_RANDOM:
1105+ InitError (Untranslated (" OS cryptographic RNG sanity check failure. Aborting." ));
1106+ break ;
1107+ case kernel::SanityCheckError::ERROR_CHRONO:
1108+ InitError (Untranslated (" Clock epoch mismatch. Aborting." ));
1109+ break ;
1110+ } // no default case, so the compiler can warn about missing cases
1111+
10981112 return InitError (strprintf (_ (" Initialization sanity check failed. %s is shutting down." ), PACKAGE_NAME));
10991113 }
11001114
Original file line number Diff line number Diff line change 55#include < kernel/checks.h>
66
77#include < key.h>
8- #include < node/ui_interface.h>
98#include < random.h>
109#include < util/time.h>
11- #include < util/translation.h>
12-
13- #include < memory>
1410
1511namespace kernel {
1612
17- bool SanityChecks (const Context&) {
13+ std::optional<SanityCheckError> SanityChecks (const Context&)
14+ {
1815 if (!ECC_InitSanityCheck ()) {
19- return InitError ( Untranslated ( " Elliptic curve cryptography sanity check failure. Aborting. " )) ;
16+ return SanityCheckError::ERROR_ECC ;
2017 }
2118
2219 if (!Random_SanityCheck ()) {
23- return InitError ( Untranslated ( " OS cryptographic RNG sanity check failure. Aborting. " )) ;
20+ return SanityCheckError::ERROR_RANDOM ;
2421 }
2522
2623 if (!ChronoSanityCheck ()) {
27- return InitError ( Untranslated ( " Clock epoch mismatch. Aborting. " )) ;
24+ return SanityCheckError::ERROR_CHRONO ;
2825 }
2926
30- return true ;
27+ return std:: nullopt ;
3128}
3229
3330}
Original file line number Diff line number Diff line change 55#ifndef BITCOIN_KERNEL_CHECKS_H
66#define BITCOIN_KERNEL_CHECKS_H
77
8+ #include < optional>
9+
810namespace kernel {
911
1012struct Context ;
1113
14+ enum class SanityCheckError {
15+ ERROR_ECC,
16+ ERROR_RANDOM,
17+ ERROR_CHRONO,
18+ };
19+
1220/* *
1321 * Ensure a usable environment with all necessary library support.
1422 */
15- bool SanityChecks (const Context&);
23+ std::optional<SanityCheckError> SanityChecks (const Context&);
1624
1725}
1826
You can’t perform that action at this time.
0 commit comments