24 static bool GetLocalAddress(
CService& addrRet)
32 if (
LookupHost(
"8.8.8.8", addrDummyPeer,
false)) {
35 if (!fFound &&
Params().IsRegTestNet()) {
42 g_connman->ForEachNodeContinueIf([&fFound, &addrRet](
CNode* pnode) {
61 default:
return "Unknown";
68 LogPrintf(
"Initializing deterministic masternode...\n");
69 if (strMNOperatorPrivKey.empty()) {
70 return errorOut(
"ERROR: Masternode operator priv key cannot be empty.");
75 return errorOut(
_(
"Invalid mnoperatorprivatekey. Please see the documentation."));
85 return errorOut(
"Active masternode not ready");
92 return errorOut(
"Active masternode operator key changed or revoked");
109 strError =
"Evo upgrade is not active yet.";
110 LogPrintf(
"%s -- ERROR: %s\n", __func__,
strError);
120 strError =
"Masternode must accept connections from outside. Make sure listen configuration option is not overwritten by some another parameter.";
121 LogPrintf(
"%s ERROR: %s\n", __func__,
strError);
127 strError =
"Can't detect valid external address. Please consider using the externalip configuration option if problem persists. Make sure to use IPv4 address only.";
128 LogPrintf(
"%s ERROR: %s\n", __func__,
strError);
140 if (dmn->IsPoSeBanned()) {
145 LogPrintf(
"%s: proTxHash=%s, proTx=%s\n", __func__, dmn->proTxHash.ToString(), dmn->ToString());
149 strError =
strprintf(
"Local address %s does not match the address from ProTx (%s)",
151 LogPrintf(
"%s ERROR: %s\n", __func__,
strError);
157 LogPrintf(
"%s: Checking inbound connection to '%s'\n", __func__, strService);
161 strError =
"DMN connectivity check failed, could not create socket to DMN running at " + strService;
162 LogPrintf(
"%s -- ERROR: %s\n", __func__,
strError);
170 strError =
"DMN connectivity check failed, could not connect to DMN running at " + strService;
171 LogPrintf(
"%s ERROR: %s\n", __func__,
strError);
178 LogPrintf(
"Deterministic Masternode initialized\n");
191 if (fInitialDownload)
199 if (newDmn ==
nullptr) {
206 if (oldDmn ==
nullptr) {
208 LogPrintf(
"%s: WARNING: unable to find active mn %s in prev block list %s\n",
213 if (newDmn->pdmnState->pubKeyOperator != oldDmn->pdmnState->pubKeyOperator) {
219 if (newDmn->pdmnState->addr != oldDmn->pdmnState->addr) {
243 return errorOut(
"ERROR: Masternode already initialized.");
247 LogPrintf(
"Initializing masternode, addr %s..\n", _strMasterNodeAddr.c_str());
249 if (_strMasterNodePrivKey.empty()) {
250 return errorOut(
"ERROR: Masternode priv key cannot be empty.");
253 if (_strMasterNodeAddr.empty()) {
254 return errorOut(
"ERROR: Empty masternodeaddr");
266 if (nPort == 0) nPort = nDefaultPort;
268 return errorOut(
strprintf(
_(
"Invalid -masternodeaddr port %d, only %d is supported on %s-net."),
269 nPort, nDefaultPort,
Params().NetworkIDString()));
273 return errorOut(
strprintf(
_(
"Invalid -masternodeaddr address: %s"), _strMasterNodeAddr));
279 return errorOut(
strprintf(
_(
"Invalid -masternodeaddr port %d, isn't the same as the peer port %d"),
286 return errorOut(
_(
"Invalid masternodeprivkey. Please see the documentation."));
320 LogPrintf(
"%s: Disabling active legacy Masternode %s as the collateral is now registered with a DMN\n",
339 LogPrintf(
"%s: ERROR Trying to start a masternode running an old protocol version, "
340 "the controller and masternode wallets need to be running the latest release version.\n", __func__);
353 LogPrintf(
"%s - Checking inbound connection for masternode to '%s'\n", __func__ ,
service.
ToString());
360 "Masternode address:port connection availability test failed, could not open a connection to the public masternode address (" +
375 std::string errorMessage;
377 LogPrintf(
"CActiveMasternode::ManageStatus() - Error on Ping: %s\n", errorMessage);
391 return "Node just started, not yet activated";
393 return "Sync in progress. Must wait until sync is complete to start Masternode";
397 return "Masternode successfully started";
405 if (
vin == nullopt) {
406 errorMessage =
"Active Masternode not initialized";
411 errorMessage =
"Masternode is not in a running status";
416 errorMessage =
"Error upon masternode key.\n";
420 LogPrintf(
"CActiveMasternode::SendMasternodePing() - Relay Masternode Ping vin = %s\n",
vin->ToString());
425 errorMessage =
"Couldn't sign Masternode Ping";
431 if (pmn !=
nullptr) {
433 errorMessage =
"Too early to send Masternode Ping";
455 errorMessage =
"Masternode List doesn't include our Masternode, shutting down Masternode pinging service! " +
vin->ToString();
473 LogPrintf(
"CActiveMasternode::EnableHotColdMasterNode() - Enabled! You may shut down the cold daemon.\n");
481 throw std::runtime_error(
"Error trying to get masternode keys");
490 return error(
"%s: Active Masternode not initialized", __func__);
495 return error(
"%s: %s", __func__, res.getError());
497 vin =
CTxIn(dmn->collateralOutpoint);
510 return error(
"%s: Active Masternode not initialized", __func__);
OperationResult initMasternode(const std::string &_strMasterNodePrivKey, const std::string &_strMasterNodeAddr, bool isFromInit)
CActiveDeterministicMasternodeManager * activeMasternodeManager
bool GetActiveDMNKeys(CBLSSecretKey &key, CTxIn &vin)
bool GetActiveMasternodeKeys(CTxIn &vin, Optional< CKey > &key, CBLSSecretKey &blsKey)
#define ACTIVE_MASTERNODE_NOT_CAPABLE
#define ACTIVE_MASTERNODE_SYNC_IN_PROCESS
#define ACTIVE_MASTERNODE_STARTED
#define ACTIVE_MASTERNODE_INITIAL
const CChainParams & Params()
Return the currently selected parameters.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override
Notifies listeners when the block chain tip advances.
static bool IsValidNetAddr(const CService &addrIn)
std::string GetStatus() const
@ MASTERNODE_WAITING_FOR_PROTX
@ MASTERNODE_OPERATOR_KEY_CHANGED
@ MASTERNODE_PROTX_IP_CHANGED
void Reset(masternode_state_t _state, const CBlockIndex *pindexTip)
OperationResult SetOperatorKey(const std::string &strMNOperatorPrivKey)
void Init(const CBlockIndex *pindexTip)
CActiveMasternodeInfo info
OperationResult GetOperatorKey(CBLSSecretKey &key, CDeterministicMNCPtr &dmn) const
bool EnableHotColdMasterNode(CTxIn &vin, CService &addr)
Enable cold wallet mode (run a Masternode with no funds)
void ManageStatus()
Manage status of main Masternode.
std::string GetStatusMessage() const
void GetKeys(CKey &privKeyMasternode, CPubKey &pubKeyMasternode) const
std::string notCapableReason
bool SendMasternodePing(std::string &errorMessage)
Ping Masternode.
A CService with information about it as peer.
CBLSPublicKey GetPublicKey() const
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
uint256 GetBlockHash() const
int nHeight
height of the entry in the chain. The genesis block has height 0
CChainParams defines various tweakable parameters of a given instance of the PIVX system.
int GetDefaultPort() const
bool IsRegTestNet() const
CDeterministicMNCPtr GetMNByOperatorKey(const CBLSPublicKey &pubKey)
An encapsulated private key.
bool IsValid() const
Check whether this private key is valid.
void SetLastPing(const CMasternodePing &_lastPing)
bool IsPingedWithin(int seconds, int64_t now=-1) const
std::map< uint256, CMasternodeBroadcast > mapSeenMasternodeBroadcast
uint256 GetBlockHashToPing() const
std::map< uint256, CMasternodePing > mapSeenMasternodePing
CMasternode * Find(const COutPoint &collateralOut)
Find an entry.
static bool GetKeysFromSecret(const std::string &strSecret, CKey &keyRet, CPubKey &pubkeyRet)
Set the private/public key values, returns true if successful.
bool IsTor() const
Check whether this object represents a TOR address.
Information about a peer.
std::string ToString() const
An encapsulated public key.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
A combination of a network address (CNetAddr) and a (TCP) port.
std::string ToStringIPPort() const
std::string ToString() const
bool Sign(const CKey &key, const CKeyID &keyID)
CSignedMessage Class Functions inherited by network signed-messages.
An input of a transaction.
bool IsBlockchainSynced() const
std::string ToString() const
std::unique_ptr< CDeterministicMNManager > deterministicMNManager
std::shared_ptr< const CDeterministicMN > CDeterministicMNCPtr
std::unique_ptr< CConnman > g_connman
#define LogPrint(category,...)
int MasternodePingSeconds()
CMasternodeMan mnodeman
Masternode manager.
CActiveMasternode activeMasternode
Keep track of the active Masternode.
Optional< CBLSSecretKey > DecodeSecret(const CChainParams ¶ms, const std::string &keyStr)
bool GetLocal(CService &addr, const CNetAddr *paddrPeer)
bool IsReachable(enum Network net)
RecursiveMutex cs_main
Global state.
void SplitHostPort(std::string in, int &portOut, std::string &hostOut)
bool Lookup(const std::string &name, std::vector< CService > &vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions)
CService LookupNumeric(const std::string &name, int portDefault)
bool LookupHost(const std::string &name, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions, bool fAllowLookup)
bool ConnectSocketDirectly(const CService &addrConnect, const SOCKET &hSocket, int nTimeout, bool manual_connection)
bool CloseSocket(SOCKET &hSocket)
Close socket and set hSocket to INVALID_SOCKET.
SOCKET CreateSocket(const CService &addrConnect)
OperationResult errorOut(const std::string &errorStr)
boost::optional< T > Optional
Substitute for C++17 std::optional.
CBLSSecretKey keyOperator
CBLSPublicKey pubKeyOperator
std::atomic< bool > fMasterNode
bool error(const char *fmt, const Args &... args)
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a Optional result.
TierTwoSyncState g_tiertwo_sync_state
int64_t GetAdjustedTime()