Repository: bitcoin/bitcoin
File: src/init.cpp (C++)

Code before:
        return InitError(strprintf(_("Elliptic curve cryptography sanity check failure. %s is shutting down."), CLIENT_NAME));
    }

    // Probe the directory locks to give an early error message, if possible
    // We cannot hold the directory locks here, as the forking for daemon() hasn't yet happened,
    // and a fork will cause weird behavior to them.
    return LockDirectories(true);
}

bool AppInitLockDirectories()
{
    // After daemonization get the directory locks again and hold on to them until exit
    // This creates a slight window for a race condition to happen, however this condition is harmless: it
    // will at most make us exit without printing a message to console.
    if (!LockDirectories(false)) {
        // Detailed error printed inside LockDirectory
        return false;
    }
    return true;
}

bool AppInitInterfaces(NodeContext& node)
{
    node.chain = node.init->makeChain();
    node.mining = node.init->makeMining();
    return true;
}

bool CheckHostPortOptions(const ArgsManager& args) {
    for (const std::string port_option : {
        "-port",
        "-rpcport",
    }) {
        if (const auto port{args.GetArg(port_option)}) {
            const auto n{ToIntegral<uint16_t>(*port)};
            if (!n || *n == 0) {
                return InitError(InvalidPortErrMsg(port_option, *port));
            }
        }
    }

    for ([[maybe_unused]] const auto& [param_name, unix, suffix_allowed] : std::vector<std::tuple<std::string, bool, bool>>{
        // arg name          UNIX socket support  =suffix allowed
        {"-i2psam",          false,               false},
        {"-onion",           true,                false},
        {"-proxy",           true,                true},
        {"-bind",            false,               true},
        {"-rpcbind",         false,               false},
        {"-torcontrol",      false,               false},
        {"-whitebind",       false,               false},
        {"-zmqpubhashblock", true,                false},

Review comment (bug):
In "ipc mining: Prevent ``Assertion `m_node.chainman' failed`` errors on early startup" bbc8f1e0a7e5739f15b2e646a4ace338083309a3

why should the internal mining interface not be tied to chainstate loading?

Code after:
        return InitError(strprintf(_("Elliptic curve cryptography sanity check failure. %s is shutting down."), CLIENT_NAME));
    }

    // Probe the directory locks to give an early error message, if possible
    // We cannot hold the directory locks here, as the forking for daemon() hasn't yet happened,
    // and a fork will cause weird behavior to them.
    return LockDirectories(true);
}

bool AppInitLockDirectories()
{
    // After daemonization get the directory locks again and hold on to them until exit
    // This creates a slight window for a race condition to happen, however this condition is harmless: it
    // will at most make us exit without printing a message to console.
    if (!LockDirectories(false)) {
        // Detailed error printed inside LockDirectory
        return false;
    }
    return true;
}

bool AppInitInterfaces(NodeContext& node)
{
    node.chain = interfaces::MakeChain(node);
    // Specify wait_loaded=false so internal mining interface can be initialized
    // on early startup and does not need to be tied to chainstate loading.
    node.mining = interfaces::MakeMining(node, /*wait_loaded=*/false);
    return true;
}

bool CheckHostPortOptions(const ArgsManager& args) {
    for (const std::string port_option : {
        "-port",
        "-rpcport",
    }) {
        if (const auto port{args.GetArg(port_option)}) {
            const auto n{ToIntegral<uint16_t>(*port)};
            if (!n || *n == 0) {
                return InitError(InvalidPortErrMsg(port_option, *port));
            }
        }
    }

    for ([[maybe_unused]] const auto& [param_name, unix, suffix_allowed] : std::vector<std::tuple<std::string, bool, bool>>{
        // arg name          UNIX socket support  =suffix allowed
        {"-i2psam",          false,               false},
        {"-onion",           true,                false},
        {"-proxy",           true,                true},
        {"-bind",            false,               true},
        {"-rpcbind",         false,               false},
        {"-torcontrol",      false,               false},