Skip to content

Commit 387c4cf

Browse files
committed
Move common sanity check code to init/common
1 parent a67b548 commit 387c4cf

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

src/init.cpp

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -672,30 +672,6 @@ static void StartupNotify(const ArgsManager& args)
672672
}
673673
#endif
674674

675-
/** Sanity checks
676-
* Ensure that Bitcoin is running in a usable environment with all
677-
* necessary library support.
678-
*/
679-
static bool InitSanityCheck()
680-
{
681-
if (!ECC_InitSanityCheck()) {
682-
return InitError(Untranslated("Elliptic curve cryptography sanity check failure. Aborting."));
683-
}
684-
685-
if (!glibcxx_sanity_test())
686-
return false;
687-
688-
if (!Random_SanityCheck()) {
689-
return InitError(Untranslated("OS cryptographic RNG sanity check failure. Aborting."));
690-
}
691-
692-
if (!ChronoSanityCheck()) {
693-
return InitError(Untranslated("Clock epoch mismatch. Aborting."));
694-
}
695-
696-
return true;
697-
}
698-
699675
static bool AppInitServers(NodeContext& node)
700676
{
701677
const ArgsManager& args = *Assert(node.args);
@@ -1147,9 +1123,9 @@ bool AppInitSanityChecks()
11471123

11481124
init::SetGlobals();
11491125

1150-
// Sanity check
1151-
if (!InitSanityCheck())
1126+
if (!init::SanityChecks()) {
11521127
return InitError(strprintf(_("Initialization sanity check failed. %s is shutting down."), PACKAGE_NAME));
1128+
}
11531129

11541130
// Probe the data directory lock to give an early error message, if possible
11551131
// We cannot hold the data directory lock here, as the forking for daemon() hasn't yet happened,

src/init/common.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include <compat/sanity.h>
56
#include <crypto/sha256.h>
67
#include <key.h>
78
#include <logging.h>
9+
#include <node/ui_interface.h>
810
#include <pubkey.h>
911
#include <random.h>
12+
#include <util/time.h>
13+
#include <util/translation.h>
1014

1115
#include <memory>
1216

@@ -27,4 +31,24 @@ void UnsetGlobals()
2731
globalVerifyHandle.reset();
2832
ECC_Stop();
2933
}
34+
35+
bool SanityChecks()
36+
{
37+
if (!ECC_InitSanityCheck()) {
38+
return InitError(Untranslated("Elliptic curve cryptography sanity check failure. Aborting."));
39+
}
40+
41+
if (!glibcxx_sanity_test())
42+
return false;
43+
44+
if (!Random_SanityCheck()) {
45+
return InitError(Untranslated("OS cryptographic RNG sanity check failure. Aborting."));
46+
}
47+
48+
if (!ChronoSanityCheck()) {
49+
return InitError(Untranslated("Clock epoch mismatch. Aborting."));
50+
}
51+
52+
return true;
53+
}
3054
} // namespace init

src/init/common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
namespace init {
1212
void SetGlobals();
1313
void UnsetGlobals();
14+
/**
15+
* Ensure a usable environment with all
16+
* necessary library support.
17+
*/
18+
bool SanityChecks();
1419
} // namespace init
1520

1621
#endif // BITCOIN_INIT_COMMON_H

0 commit comments

Comments
 (0)