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[])
56
56
// We can't use a goto here, but we can use an assert since none of the
57
57
// things instantiated so far requires running the epilogue to be torn down
58
58
// properly
59
- assert (kernel::SanityChecks (kernel_context));
59
+ assert (! kernel::SanityChecks (kernel_context). has_value ( ));
60
60
61
61
// Necessary for CheckInputScripts (eventually called by ProcessNewBlock),
62
62
// 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)
1094
1094
bool AppInitSanityChecks (const kernel::Context& kernel)
1095
1095
{
1096
1096
// ********************************************************* 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
+
1098
1112
return InitError (strprintf (_ (" Initialization sanity check failed. %s is shutting down." ), PACKAGE_NAME));
1099
1113
}
1100
1114
Original file line number Diff line number Diff line change 5
5
#include < kernel/checks.h>
6
6
7
7
#include < key.h>
8
- #include < node/ui_interface.h>
9
8
#include < random.h>
10
9
#include < util/time.h>
11
- #include < util/translation.h>
12
-
13
- #include < memory>
14
10
15
11
namespace kernel {
16
12
17
- bool SanityChecks (const Context&) {
13
+ std::optional<SanityCheckError> SanityChecks (const Context&)
14
+ {
18
15
if (!ECC_InitSanityCheck ()) {
19
- return InitError ( Untranslated ( " Elliptic curve cryptography sanity check failure. Aborting. " )) ;
16
+ return SanityCheckError::ERROR_ECC ;
20
17
}
21
18
22
19
if (!Random_SanityCheck ()) {
23
- return InitError ( Untranslated ( " OS cryptographic RNG sanity check failure. Aborting. " )) ;
20
+ return SanityCheckError::ERROR_RANDOM ;
24
21
}
25
22
26
23
if (!ChronoSanityCheck ()) {
27
- return InitError ( Untranslated ( " Clock epoch mismatch. Aborting. " )) ;
24
+ return SanityCheckError::ERROR_CHRONO ;
28
25
}
29
26
30
- return true ;
27
+ return std::nullopt ;
31
28
}
32
29
33
30
}
Original file line number Diff line number Diff line change 5
5
#ifndef BITCOIN_KERNEL_CHECKS_H
6
6
#define BITCOIN_KERNEL_CHECKS_H
7
7
8
+ #include < optional>
9
+
8
10
namespace kernel {
9
11
10
12
struct Context ;
11
13
14
+ enum class SanityCheckError {
15
+ ERROR_ECC,
16
+ ERROR_RANDOM,
17
+ ERROR_CHRONO,
18
+ };
19
+
12
20
/* *
13
21
* Ensure a usable environment with all necessary library support.
14
22
*/
15
- bool SanityChecks (const Context&);
23
+ std::optional<SanityCheckError> SanityChecks (const Context&);
16
24
17
25
}
18
26
You can’t perform that action at this time.
0 commit comments