Skip to content

Commit

Permalink
allow to start without komodo.conf for KMD (#87)
Browse files Browse the repository at this point in the history
* introduce DEFAULT_TXINDEX (true)

as a part of constrain constant values to a single location in code

* fix error messages displayed on startup by the daemon

* allow to start without komodo.conf for KMD

No komodo.conf file is OK
  • Loading branch information
DeckerSU authored Nov 20, 2024
1 parent d837369 commit d0cb57c
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ While the Komodo assetchains provide advanced privacy features, the main KMD coi

KomodoOcean is available on three OS platforms: `Windows`, `Linux`, and `macOS`.

Use the default `static` branch and the following scripts to build, depending on your target platform and architecture:
Use the default `static` branch and the following scripts in `./zcutil` to build, depending on your target platform and architecture:

- **Linux**:
- `build.sh`: Native build for Linux.
Expand Down
42 changes: 10 additions & 32 deletions src/bitcoind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "util.h"
#include "httpserver.h"
#include "httprpc.h"

#include "komodo.h"
#include "komodo_defs.h"
#include "komodo_gateway.h"
Expand Down Expand Up @@ -68,14 +67,12 @@ void WaitForShutdown(boost::thread_group* threadGroup)
{
int32_t i,height; CBlockIndex *pindex; bool fShutdown = ShutdownRequested();
static const uint256 zeroid; //!< null uint256 constant

// Tell the main threads to shutdown.
if (komodo_currentheight()>KOMODO_EARLYTXID_HEIGHT && KOMODO_EARLYTXID!=zeroid && ((height=tx_height(KOMODO_EARLYTXID))==0 || height>KOMODO_EARLYTXID_HEIGHT))
{
LogPrintf("error: earlytx must be before block height %d or tx does not exist\n",KOMODO_EARLYTXID_HEIGHT);
fprintf(stderr,"error: earlytx must be before block height %d or tx does not exist\n",KOMODO_EARLYTXID_HEIGHT);
StartShutdown();
}

while (!fShutdown)
{
/* TODO: move to ThreadUpdateKomodoInternals */
Expand Down Expand Up @@ -117,7 +114,6 @@ void WaitForShutdown(boost::thread_group* threadGroup)
//
// Start
//

bool AppInit(int argc, char* argv[])
{
boost::thread_group threadGroup;
Expand Down Expand Up @@ -156,44 +152,26 @@ bool AppInit(int argc, char* argv[])
{
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
if (!SelectParamsFromCommandLine()) {
LogPrintf("Error: Invalid combination of -regtest and -testnet.\n");
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
return false;
}
void komodo_args(char *argv0);
komodo_args(argv[0]);
void chainparams_commandline();
chainparams_commandline();

LogPrintf("call komodo_args.(%s) NOTARY_PUBKEY.(%s)\n",argv[0],NOTARY_PUBKEY.c_str());
LogPrintf("initialized %s at %u\n",chainName.symbol().c_str(),(uint32_t)time(NULL));
fprintf(stderr, "call komodo_args.(%s) NOTARY_PUBKEY.(%s)\n",argv[0],NOTARY_PUBKEY.c_str());
fprintf(stdout, "initialized %s at %u\n",chainName.symbol().c_str(),(uint32_t)time(NULL));
if (!boost::filesystem::is_directory(GetDataDir(false)))
{
LogPrintf("Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
return false;
}
try
{
ReadConfigFile(mapArgs, mapMultiArgs);
} catch (const missing_zcash_conf& e) {
LogPrintf(
(_("Before starting komodod, you need to create a configuration file:\n"
"%s\n"
"It can be completely empty! That indicates you are happy with the default\n"
"configuration of komodod. But requiring a configuration file to start ensures\n"
"that komodod won't accidentally compromise your privacy if there was a default\n"
"option you needed to change.\n"
"\n"
"You can look at the example configuration file for suggestions of default\n"
"options that you may want to change. It should be in one of these locations,\n"
"depending on how you installed Komodo:\n") +
_("- Source code: %s\n"
"- .deb package: %s\n")).c_str(),
GetConfigFile().string().c_str(),
"contrib/debian/examples/komodo.conf",
"/usr/share/doc/komodo/examples/komodo.conf");
return false;
} catch (const std::exception& e) {
LogPrintf("Error reading configuration file: %s\n", e.what());
fprintf(stderr,"Error reading configuration file: %s\n", e.what());
return false;
}

Expand All @@ -205,21 +183,21 @@ bool AppInit(int argc, char* argv[])

if (fCommandLine)
{
LogPrintf( "Error: There is no RPC client functionality in komodod. Use the komodo-cli utility instead.\n");
fprintf(stderr, "Error: There is no RPC client functionality in komodod. Use the komodo-cli utility instead.\n");
exit(EXIT_FAILURE);
}

#ifndef _WIN32
fDaemon = GetBoolArg("-daemon", false);
if (fDaemon)
{
LogPrintf("Komodo %s server starting\n",chainName.symbol().c_str());
fprintf(stdout, "Komodo %s server starting\n",chainName.symbol().c_str());

// Daemonize
pid_t pid = fork();
if (pid < 0)
{
LogPrintf( "Error: fork() returned %d errno %d\n", pid, errno);
fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
return false;
}
if (pid > 0) // Parent process, pid is child process id
Expand All @@ -230,7 +208,7 @@ bool AppInit(int argc, char* argv[])

pid_t sid = setsid();
if (sid < 0)
LogPrintf( "Error: setsid() returned %d errno %d\n", sid, errno);
fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
}
#endif
SoftSetBoolArg("-server", true);
Expand Down
8 changes: 4 additions & 4 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ std::string HelpMessage(HelpMessageMode mode)
#if !defined(WIN32)
strUsage += HelpMessageOpt("-sysperms", _("Create new files with system default permissions, instead of umask 077 (only effective with disabled wallet functionality)"));
#endif
strUsage += HelpMessageOpt("-txindex", strprintf(_("Maintain a full transaction index, used by the getrawtransaction rpc call (default: %u)"), 0));
strUsage += HelpMessageOpt("-txindex", strprintf(_("Maintain a full transaction index, used by the getrawtransaction rpc call (default: %u)"), DEFAULT_TXINDEX));
strUsage += HelpMessageOpt("-addressindex", strprintf(_("Maintain a full address index, used to query for the balance, txids and unspent outputs for addresses (default: %u)"), DEFAULT_ADDRESSINDEX));
strUsage += HelpMessageOpt("-timestampindex", strprintf(_("Maintain a timestamp index for block hashes, used to query blocks hashes by a range of timestamps (default: %u)"), DEFAULT_TIMESTAMPINDEX));
strUsage += HelpMessageOpt("-spentindex", strprintf(_("Maintain a full spent index, used to query the spending txid and input index for an outpoint (default: %u)"), DEFAULT_SPENTINDEX));
Expand Down Expand Up @@ -1046,7 +1046,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
// if using block pruning, then disable txindex
// also disable the wallet (for now, until SPV support is implemented in wallet)
if (GetArg("-prune", 0)) {
if (GetBoolArg("-txindex", true))
if (GetBoolArg("-txindex", DEFAULT_TXINDEX))
return InitError(_("Prune mode is incompatible with -txindex."));
#ifdef ENABLE_WALLET
if (!GetBoolArg("-disablewallet", false)) {
Expand Down Expand Up @@ -1578,7 +1578,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
// enable 3/4 of the cache if addressindex and/or spentindex is enabled
nBlockTreeDBCache = nTotalCache * 3 / 4;
} else {
if (nBlockTreeDBCache > (1 << 21) && !GetBoolArg("-txindex", false)) {
if (nBlockTreeDBCache > (1 << 21) && !GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
nBlockTreeDBCache = (1 << 21); // block tree db cache shouldn't be larger than 2 MiB
}
}
Expand Down Expand Up @@ -1671,7 +1671,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
}
KOMODO_LOADINGBLOCKS = false;
// Check for changed -txindex state
if (fTxIndex != GetBoolArg("-txindex", true)) {
if (fTxIndex != GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
strLoadError = _("You need to rebuild the database using -reindex to change -txindex");
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6660,7 +6660,7 @@ bool InitBlockIndex() {
if ( pblocktree != nullptr )
{
// Use the provided setting for -txindex in the new database
fTxIndex = GetBoolArg("-txindex", true);
fTxIndex = GetBoolArg("-txindex", DEFAULT_TXINDEX);
pblocktree->WriteFlag("txindex", fTxIndex);
// Use the provided setting for -addressindex in the new database
fAddressIndex = GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX);
Expand Down
1 change: 1 addition & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
static const unsigned int DEFAULT_LIMITFREERELAY = 15;
static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;

static const bool DEFAULT_TXINDEX = true;
//static const bool DEFAULT_ADDRESSINDEX = false;
//static const bool DEFAULT_SPENTINDEX = false;
#define DEFAULT_ADDRESSINDEX (GetArg("-ac_cc",0) != 0 || GetArg("-ac_ccactivate",0) != 0)
Expand Down
1 change: 0 additions & 1 deletion src/qt/komodoapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,6 @@ int main(int argc, char *argv[])
}

try {
// ReadConfigFile(GetArg("-conf", KOMODO_CONF_FILENAME));
ReadConfigFile(mapArgs, mapMultiArgs);
} catch (const std::exception& e) {
QMessageBox::critical(0, QObject::tr(PACKAGE_NAME),
Expand Down
2 changes: 1 addition & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ void ReadConfigFile(map<string, string>& mapSettingsRet,
{
boost::filesystem::ifstream streamConfig(GetConfigFile());
if (!streamConfig.good())
throw missing_zcash_conf();
return; // No komodo.conf file is OK

set<string> setOptions;
setOptions.insert("*");
Expand Down
4 changes: 0 additions & 4 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,6 @@ boost::filesystem::path GetConfigFile();
boost::filesystem::path GetPidFile();
void CreatePidFile(const boost::filesystem::path &path, pid_t pid);
#endif
class missing_zcash_conf : public std::runtime_error {
public:
missing_zcash_conf() : std::runtime_error("Missing komodo.conf") { }
};
void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet, std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet);
#ifdef _WIN32
boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
Expand Down

0 comments on commit d0cb57c

Please sign in to comment.