20 #include "validation.h"
23 #include <boost/thread.hpp>
30 strUsage +=
HelpMessageOpt(
"-masternode=<n>",
strprintf(
"Enable the client to act as a masternode (0-1, default: %u)", DEFAULT_MASTERNODE));
32 strUsage +=
HelpMessageOpt(
"-mnconflock=<n>",
strprintf(
"Lock masternodes from masternode configuration file (default: %u)", DEFAULT_MNCONFLOCK));
33 strUsage +=
HelpMessageOpt(
"-masternodeprivkey=<n>",
"Set the masternode private key");
34 strUsage +=
HelpMessageOpt(
"-masternodeaddr=<n>",
strprintf(
"Set external address:port to get to this masternode (example: %s). Only for Legacy Masternodes",
"128.127.106.235:51472"));
35 strUsage +=
HelpMessageOpt(
"-budgetvotemode=<mode>",
"Change automatic finalized budget voting behavior. mode=auto: Vote for only exact finalized budget match to my generated budget. (string, default: auto)");
36 strUsage +=
HelpMessageOpt(
"-mnoperatorprivatekey=<bech32>",
"Set the masternode operator private key. Only valid with -masternode=1. When set, the masternode acts as a deterministic masternode.");
38 strUsage +=
HelpMessageOpt(
"-pushversion",
strprintf(
"Modifies the mnauth serialization if the version is lower than %d."
39 "testnet/regtest only; ", MNAUTH_NODE_VER_VERSION));
40 strUsage +=
HelpMessageOpt(
"-disabledkg",
"Disable the DKG sessions process threads for the entire lifecycle. testnet/regtest only.");
67 int64_t nEvoDbCache = 1024 * 1024 * 64;
92 unsigned int inserted = 0;
93 while (pindex && inserted < CACHED_BLOCK_HASHES) {
95 pindex = pindex->
pprev;
112 LogPrintf(
"Missing masternode cache file - mncache.dat, will try to recreate\n");
114 LogPrintf(
"Error reading mncache.dat - cached data discarded\n");
123 const bool fDryRun = (chain_active_height <= 0);
128 LogPrintf(
"Missing budget cache - budget.dat, will try to recreate\n");
130 LogPrintf(
"Error reading budget.dat - cached data discarded\n");
145 LogPrintf(
"Missing masternode payment cache - mnpayments.dat, will try to recreate\n");
147 LogPrintf(
"Error reading mnpayments.dat - cached data discarded\n");
155 return UIError(
strprintf(
_(
"Error reading masternode configuration file: %s"), strErr));
163 if (load_cache_files) {
165 return UIError(
strprintf(
_(
"Failed to load masternode metadata cache from: %s"), metadb.
GetDbPath().string()));
169 if (!metadb.
Dump(mmetamanTmp)) {
170 return UIError(
strprintf(
_(
"Failed to clear masternode metadata cache at: %s"), metadb.
GetDbPath().string()));
179 if (load_cache_files) {
181 LogPrintf(
"Failed to load network requests cache from %s\n", netRequestsDb.
GetDbPath().string());
185 if (!netRequestsDb.
Dump(netfulfilledmanTmp)) {
186 LogPrintf(
"Failed to clear network requests cache at %s\n", netRequestsDb.
GetDbPath().string());
219 return UIError(
strprintf(
_(
"Enabling Masternode support requires turning on transaction indexing."
220 "Please add %s to your configuration and start with %s"),
"txindex=1",
"-reindex"));
226 return UIError(
_(
"Cannot be a masternode and only connect to specific nodes"));
229 if (
gArgs.
GetArg(
"-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS) < DEFAULT_MAX_PEER_CONNECTIONS) {
230 return UIError(
strprintf(
_(
"Masternode must be able to handle at least %d connections, set %s=%d"),
231 DEFAULT_MAX_PEER_CONNECTIONS,
"-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS));
234 const std::string& mnoperatorkeyStr =
gArgs.
GetArg(
"-mnoperatorprivatekey",
"");
235 const bool fDeterministic = !mnoperatorkeyStr.empty();
236 LogPrintf(
"IS %s MASTERNODE\n", (fDeterministic ?
"DETERMINISTIC " :
""));
238 if (fDeterministic) {
242 _(
"Cannot start deterministic masternode before enforcement. Remove %s to start as legacy masternode"),
243 "-mnoperatorprivatekey");
244 LogPrintf(
"-- ERROR: %s\n", strError);
245 return UIError(strError);
250 if (!res) {
return UIError(res.getError()); }
261 _(
"Legacy masternode system disabled. Use %s to start as deterministic masternode"),
262 "-mnoperatorprivatekey");
263 LogPrintf(
"-- ERROR: %s\n", strError);
264 return UIError(strError);
268 if (!res) {
return UIError(res.getError()); }
277 LogPrintf(
"Locking Masternodes collateral utxo:\n");
280 mnTxHash.
SetHex(mne.getTxHash());
281 COutPoint outpoint =
COutPoint(mnTxHash, (
unsigned int) std::stoul(mne.getOutputIndex()));
283 LogPrintf(
"Locked collateral, MN: %s, tx hash: %s, output index: %s\n",
284 mne.getAlias(), mne.getTxHash(), mne.getOutputIndex());
290 LogPrintf(
"Locking masternode collaterals...\n");
294 pwallet->LockOutpointIfMineWithMutex(
nullptr, dmn->collateralOutpoint);
311 throw std::runtime_error(
"DKG system can be disabled only on testnet/regtest");
313 LogPrintf(
"DKG system disabled.\n");
OperationResult initMasternode(const std::string &_strMasterNodePrivKey, const std::string &_strMasterNodeAddr, bool isFromInit)
CActiveDeterministicMasternodeManager * activeMasternodeManager
void DumpBudgets(CBudgetManager &budgetman)
CBudgetManager g_budgetman
const CChainParams & Params()
Return the currently selected parameters.
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
masternode_state_t GetState() const
std::string GetStatus() const
OperationResult SetOperatorKey(const std::string &strMNOperatorPrivKey)
void Init(const CBlockIndex *pindexTip)
static const std::string MAIN
Chain name strings.
The block chain is a tree shaped structure starting with the genesis block at the root,...
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Save Budget Manager (budget.dat)
ReadResult Read(CBudgetManager &objToLoad, bool fDryRun=false)
std::string strBudgetMode
void SetBestHeight(int height)
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or nullptr if none.
boost::signals2::signal< void(const std::string &message)> InitMessage
Progress message during initialization.
fs::path GetDbPath() const
bool read(std::string &strErr)
std::vector< CMasternodeEntry > getEntries()
Access to the MN database (mncache.dat)
ReadResult Read(CMasternodeMan &mnodemanToLoad)
void CacheBlockHash(const CBlockIndex *pindex)
void SetBestHeight(int height)
Save Masternode Payment Data (mnpayments.dat)
ReadResult Read(CMasternodePayments &objToLoad)
An outpoint - a combination of a transaction hash and an index n into its vout.
void scheduleEvery(Function f, int64_t deltaMilliSeconds)
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
void InitializeCurrentBlockTip()
void SetHex(const char *psz)
std::unique_ptr< CDeterministicMNManager > deterministicMNManager
std::shared_ptr< const CDeterministicMN > CDeterministicMNCPtr
std::unique_ptr< CEvoDB > evoDb
CClientUIInterface uiInterface
CMasternodePayments masternodePayments
Object for who's going to get paid on which blocks.
void DumpMasternodePayments()
CMasternodeConfig masternodeConfig
CMasternodeMan mnodeman
Masternode manager.
void ThreadCheckMasternodes()
void InterruptLLMQSystem()
void InitLLMQSystem(CEvoDB &evoDb, CScheduler *scheduler, bool unitTests)
RecursiveMutex cs_main
Global state.
CNetFulfilledRequestManager g_netfulfilledman(DEFAULT_ITEMS_FILTER_SIZE)
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
const char *const PIVX_MASTERNODE_CONF_FILENAME
std::atomic< bool > fMasterNode
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a Optional result.
bool InitActiveMN()
Initialize the active Masternode manager.
void InterruptTierTwo()
Interrupt tier two threads.
void ResetTierTwoInterfaces()
Resets the interfaces objects.
std::string GetTierTwoHelpString(bool showDebug)
void SetBudgetFinMode(const std::string &mode)
void InitTierTwoChainTip()
Initialize chain tip.
void RegisterTierTwoValidationInterface()
Register all tier two objects.
void InitTierTwoInterfaces()
Init the interfaces objects.
void InitTierTwoPreChainLoad(bool fReindex)
Inits the tier two global objects.
void StopTierTwoThreads()
Stops tier two workers.
bool LoadTierTwo(int chain_active_height, bool load_cache_files)
Loads from disk all the tier two related objects.
void StartTierTwoThreadsAndScheduleJobs(boost::thread_group &threadGroup, CScheduler &scheduler)
Starts tier two threads and jobs.
void DeleteTierTwo()
Cleans manager and worker objects pointers.
void DumpTierTwo()
Dump tier two managers to disk.
void InitTierTwoPostCoinsCacheLoad(CScheduler *scheduler)
Inits the tier two global objects that require access to the coins tip cache.
std::atomic< bool > fReindex
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
void UnregisterValidationInterface(CValidationInterface *pwalletIn)
Unregister a wallet from core.
void RegisterValidationInterface(CValidationInterface *pwalletIn)
Register a wallet to receive updates from core.
std::vector< CWalletRef > vpwallets
boost::thread_group threadGroup
EvoNotificationInterface * pEvoNotificationInterface