2016-12-20 14:26:45 +01:00
// Copyright (c) 2014-2017 The Dash Core developers
2016-02-02 16:28:56 +01:00
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
2014-12-09 02:17:57 +01:00
# include "activemasternode.h"
2015-04-17 17:10:38 +02:00
# include "masternode.h"
2016-01-24 20:05:31 +01:00
# include "masternode-sync.h"
# include "masternodeman.h"
2016-08-05 21:49:45 +02:00
# include "protocol.h"
extern CWallet * pwalletMain ;
// Keep track of the active Masternode
CActiveMasternode activeMasternode ;
2014-12-09 02:17:57 +01:00
2016-08-05 21:49:45 +02:00
void CActiveMasternode : : ManageState ( )
{
2016-10-17 20:54:28 +02:00
LogPrint ( " masternode " , " CActiveMasternode::ManageState -- Start \n " ) ;
if ( ! fMasterNode ) {
LogPrint ( " masternode " , " CActiveMasternode::ManageState -- Not a masternode, returning \n " ) ;
return ;
}
2014-12-09 02:17:57 +01:00
2016-02-02 16:28:56 +01:00
if ( Params ( ) . NetworkIDString ( ) ! = CBaseChainParams : : REGTEST & & ! masternodeSync . IsBlockchainSynced ( ) ) {
2016-08-05 21:49:45 +02:00
nState = ACTIVE_MASTERNODE_SYNC_IN_PROCESS ;
2016-10-26 23:21:39 +02:00
LogPrintf ( " CActiveMasternode::ManageState -- %s: %s \n " , GetStateString ( ) , GetStatus ( ) ) ;
2014-12-09 02:17:57 +01:00
return ;
}
2016-10-17 20:54:28 +02:00
if ( nState = = ACTIVE_MASTERNODE_SYNC_IN_PROCESS ) {
nState = ACTIVE_MASTERNODE_INITIAL ;
2014-12-09 02:17:57 +01:00
}
2016-10-26 23:21:39 +02:00
LogPrint ( " masternode " , " CActiveMasternode::ManageState -- status = %s, type = %s, pinger enabled = %d \n " , GetStatus ( ) , GetTypeString ( ) , fPingerEnabled ) ;
2014-12-09 02:17:57 +01:00
2016-10-17 20:54:28 +02:00
if ( eType = = MASTERNODE_UNKNOWN ) {
ManageStateInitial ( ) ;
}
2015-07-14 07:25:07 +02:00
2016-10-17 20:54:28 +02:00
if ( eType = = MASTERNODE_REMOTE ) {
ManageStateRemote ( ) ;
2016-10-26 23:21:39 +02:00
} else if ( eType = = MASTERNODE_LOCAL ) {
2017-01-01 11:18:21 +01:00
// Try Remote Start first so the started local masternode can be restarted without recreate masternode broadcast.
ManageStateRemote ( ) ;
if ( nState ! = ACTIVE_MASTERNODE_STARTED )
ManageStateLocal ( ) ;
2014-12-09 02:17:57 +01:00
}
2016-10-26 23:21:39 +02:00
SendMasternodePing ( ) ;
}
std : : string CActiveMasternode : : GetStateString ( ) const
{
switch ( nState ) {
case ACTIVE_MASTERNODE_INITIAL : return " INITIAL " ;
case ACTIVE_MASTERNODE_SYNC_IN_PROCESS : return " SYNC_IN_PROCESS " ;
case ACTIVE_MASTERNODE_INPUT_TOO_NEW : return " INPUT_TOO_NEW " ;
case ACTIVE_MASTERNODE_NOT_CAPABLE : return " NOT_CAPABLE " ;
case ACTIVE_MASTERNODE_STARTED : return " STARTED " ;
default : return " UNKNOWN " ;
2015-07-14 07:25:07 +02:00
}
}
2016-10-26 23:21:39 +02:00
std : : string CActiveMasternode : : GetStatus ( ) const
2016-08-05 21:49:45 +02:00
{
switch ( nState ) {
2016-10-22 18:52:14 +02:00
case ACTIVE_MASTERNODE_INITIAL : return " Node just started, not yet activated " ;
2016-08-05 21:49:45 +02:00
case ACTIVE_MASTERNODE_SYNC_IN_PROCESS : return " Sync in progress. Must wait until sync is complete to start Masternode " ;
2016-10-22 18:52:14 +02:00
case ACTIVE_MASTERNODE_INPUT_TOO_NEW : return strprintf ( " Masternode input must have at least %d confirmations " , Params ( ) . GetConsensus ( ) . nMasternodeMinimumConfirmations ) ;
case ACTIVE_MASTERNODE_NOT_CAPABLE : return " Not capable masternode: " + strNotCapableReason ;
case ACTIVE_MASTERNODE_STARTED : return " Masternode successfully started " ;
2016-10-26 23:21:39 +02:00
default : return " Unknown " ;
2014-12-06 20:41:53 +01:00
}
}
2014-12-09 02:17:57 +01:00
2016-10-26 23:21:39 +02:00
std : : string CActiveMasternode : : GetTypeString ( ) const
2016-10-17 20:54:28 +02:00
{
std : : string strType ;
switch ( eType ) {
case MASTERNODE_UNKNOWN :
strType = " UNKNOWN " ;
break ;
case MASTERNODE_REMOTE :
strType = " REMOTE " ;
break ;
case MASTERNODE_LOCAL :
strType = " LOCAL " ;
break ;
default :
strType = " UNKNOWN " ;
break ;
}
return strType ;
}
2016-10-26 23:21:39 +02:00
bool CActiveMasternode : : SendMasternodePing ( )
2016-08-05 21:49:45 +02:00
{
2016-10-26 23:21:39 +02:00
if ( ! fPingerEnabled ) {
2016-11-29 01:01:03 +01:00
LogPrint ( " masternode " , " CActiveMasternode::SendMasternodePing -- %s: masternode ping service is disabled, skipping... \n " , GetStateString ( ) ) ;
2015-03-22 00:58:18 +01:00
return false ;
}
2014-12-09 02:17:57 +01:00
2016-10-26 23:21:39 +02:00
if ( ! mnodeman . Has ( vin ) ) {
strNotCapableReason = " Masternode not in masternode list " ;
nState = ACTIVE_MASTERNODE_NOT_CAPABLE ;
LogPrintf ( " CActiveMasternode::SendMasternodePing -- %s: %s \n " , GetStateString ( ) , strNotCapableReason ) ;
2014-12-09 02:17:57 +01:00
return false ;
}
2016-10-26 23:21:39 +02:00
CMasternodePing mnp ( vin ) ;
2017-07-04 19:31:57 +02:00
mnp . nSentinelVersion = nSentinelVersion ;
mnp . fSentinelIsCurrent =
( abs ( GetAdjustedTime ( ) - nSentinelPingTime ) < MASTERNODE_WATCHDOG_MAX_SECONDS ) ;
2016-10-26 23:21:39 +02:00
if ( ! mnp . Sign ( keyMasternode , pubKeyMasternode ) ) {
LogPrintf ( " CActiveMasternode::SendMasternodePing -- ERROR: Couldn't sign Masternode Ping \n " ) ;
2014-12-09 02:17:57 +01:00
return false ;
}
2016-10-17 20:54:28 +02:00
// Update lastPing for our masternode in Masternode list
if ( mnodeman . IsMasternodePingedWithin ( vin , MASTERNODE_MIN_MNP_SECONDS , mnp . sigTime ) ) {
2016-10-26 23:21:39 +02:00
LogPrintf ( " CActiveMasternode::SendMasternodePing -- Too early to send Masternode Ping \n " ) ;
2016-10-17 20:54:28 +02:00
return false ;
}
mnodeman . SetMasternodeLastPing ( vin , mnp ) ;
LogPrintf ( " CActiveMasternode::SendMasternodePing -- Relaying ping, collateral=%s \n " , vin . ToString ( ) ) ;
mnp . Relay ( ) ;
return true ;
2014-12-06 20:41:53 +01:00
}
2017-07-04 19:31:57 +02:00
bool CActiveMasternode : : UpdateSentinelPing ( int version )
{
nSentinelVersion = version ;
nSentinelPingTime = GetAdjustedTime ( ) ;
return true ;
}
2016-10-17 20:54:28 +02:00
void CActiveMasternode : : ManageStateInitial ( )
{
2016-10-26 23:21:39 +02:00
LogPrint ( " masternode " , " CActiveMasternode::ManageStateInitial -- status = %s, type = %s, pinger enabled = %d \n " , GetStatus ( ) , GetTypeString ( ) , fPingerEnabled ) ;
2016-12-15 17:27:24 +01:00
2016-10-17 20:54:28 +02:00
// Check that our local network configuration is correct
2016-12-15 17:27:24 +01:00
if ( ! fListen ) {
// listen option is probably overwritten by smth else, no good
nState = ACTIVE_MASTERNODE_NOT_CAPABLE ;
strNotCapableReason = " Masternode must accept connections from outside. Make sure listen configuration option is not overwritten by some another parameter. " ;
LogPrintf ( " CActiveMasternode::ManageStateInitial -- %s: %s \n " , GetStateString ( ) , strNotCapableReason ) ;
return ;
}
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
// First try to find whatever local address is specified by externalip option
bool fFoundLocal = GetLocal ( service ) & & CMasternode : : IsValidNetAddr ( service ) ;
if ( ! fFoundLocal ) {
bool empty = true ;
// If we have some peers, let's try to find our local address from one of them
2017-08-17 20:37:22 +02:00
g_connman - > ForEachNodeContinueIf ( CConnman : : AllNodes , [ & fFoundLocal , & empty , this ] ( CNode * pnode ) {
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
empty = false ;
2017-08-17 20:37:22 +02:00
if ( pnode - > addr . IsIPv4 ( ) )
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
fFoundLocal = GetLocal ( service , & pnode - > addr ) & & CMasternode : : IsValidNetAddr ( service ) ;
return ! fFoundLocal ;
} ) ;
// nothing and no live connections, can't do anything for now
if ( empty ) {
nState = ACTIVE_MASTERNODE_NOT_CAPABLE ;
strNotCapableReason = " Can't detect valid external address. Will retry when there are some connections available. " ;
LogPrintf ( " CActiveMasternode::ManageStateInitial -- %s: %s \n " , GetStateString ( ) , strNotCapableReason ) ;
return ;
2016-12-15 17:27:24 +01:00
}
}
if ( ! fFoundLocal ) {
2016-10-26 23:21:39 +02:00
nState = ACTIVE_MASTERNODE_NOT_CAPABLE ;
2016-12-15 17:27:24 +01:00
strNotCapableReason = " Can't detect valid external address. Please consider using the externalip configuration option if problem persists. Make sure to use IPv4 address only. " ;
2016-10-26 23:21:39 +02:00
LogPrintf ( " CActiveMasternode::ManageStateInitial -- %s: %s \n " , GetStateString ( ) , strNotCapableReason ) ;
2016-10-17 20:54:28 +02:00
return ;
}
int mainnetDefaultPort = Params ( CBaseChainParams : : MAIN ) . GetDefaultPort ( ) ;
if ( Params ( ) . NetworkIDString ( ) = = CBaseChainParams : : MAIN ) {
if ( service . GetPort ( ) ! = mainnetDefaultPort ) {
2016-10-26 23:21:39 +02:00
nState = ACTIVE_MASTERNODE_NOT_CAPABLE ;
2016-10-17 20:54:28 +02:00
strNotCapableReason = strprintf ( " Invalid port: %u - only %d is supported on mainnet. " , service . GetPort ( ) , mainnetDefaultPort ) ;
2016-10-26 23:21:39 +02:00
LogPrintf ( " CActiveMasternode::ManageStateInitial -- %s: %s \n " , GetStateString ( ) , strNotCapableReason ) ;
2016-10-17 20:54:28 +02:00
return ;
}
} else if ( service . GetPort ( ) = = mainnetDefaultPort ) {
2016-10-26 23:21:39 +02:00
nState = ACTIVE_MASTERNODE_NOT_CAPABLE ;
2016-10-17 20:54:28 +02:00
strNotCapableReason = strprintf ( " Invalid port: %u - %d is only supported on mainnet. " , service . GetPort ( ) , mainnetDefaultPort ) ;
2016-10-26 23:21:39 +02:00
LogPrintf ( " CActiveMasternode::ManageStateInitial -- %s: %s \n " , GetStateString ( ) , strNotCapableReason ) ;
2016-10-17 20:54:28 +02:00
return ;
}
2016-12-15 17:27:24 +01:00
LogPrintf ( " CActiveMasternode::ManageStateInitial -- Checking inbound connection to '%s' \n " , service . ToString ( ) ) ;
2016-10-17 20:54:28 +02:00
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
// TODO: Pass CConnman instance somehow and don't use global variable.
if ( ! g_connman - > ConnectNode ( CAddress ( service , NODE_NETWORK ) , NULL , true ) ) {
2016-10-26 23:21:39 +02:00
nState = ACTIVE_MASTERNODE_NOT_CAPABLE ;
2016-10-17 20:54:28 +02:00
strNotCapableReason = " Could not connect to " + service . ToString ( ) ;
2016-10-26 23:21:39 +02:00
LogPrintf ( " CActiveMasternode::ManageStateInitial -- %s: %s \n " , GetStateString ( ) , strNotCapableReason ) ;
2016-10-17 20:54:28 +02:00
return ;
}
// Default to REMOTE
eType = MASTERNODE_REMOTE ;
// Check if wallet funds are available
if ( ! pwalletMain ) {
2016-10-26 23:21:39 +02:00
LogPrintf ( " CActiveMasternode::ManageStateInitial -- %s: Wallet not available \n " , GetStateString ( ) ) ;
2016-10-17 20:54:28 +02:00
return ;
}
if ( pwalletMain - > IsLocked ( ) ) {
2016-10-26 23:21:39 +02:00
LogPrintf ( " CActiveMasternode::ManageStateInitial -- %s: Wallet is locked \n " , GetStateString ( ) ) ;
2016-10-17 20:54:28 +02:00
return ;
}
if ( pwalletMain - > GetBalance ( ) < 1000 * COIN ) {
2016-11-30 02:33:47 +01:00
LogPrintf ( " CActiveMasternode::ManageStateInitial -- %s: Wallet balance is < 1000 DASH \n " , GetStateString ( ) ) ;
2016-10-17 20:54:28 +02:00
return ;
}
// Choose coins to use
CPubKey pubKeyCollateral ;
CKey keyCollateral ;
// If collateral is found switch to LOCAL mode
if ( pwalletMain - > GetMasternodeVinAndKeys ( vin , pubKeyCollateral , keyCollateral ) ) {
eType = MASTERNODE_LOCAL ;
}
2016-10-26 23:21:39 +02:00
LogPrint ( " masternode " , " CActiveMasternode::ManageStateInitial -- End status = %s, type = %s, pinger enabled = %d \n " , GetStatus ( ) , GetTypeString ( ) , fPingerEnabled ) ;
2016-10-17 20:54:28 +02:00
}
void CActiveMasternode : : ManageStateRemote ( )
{
2016-10-25 16:37:33 +02:00
LogPrint ( " masternode " , " CActiveMasternode::ManageStateRemote -- Start status = %s, type = %s, pinger enabled = %d, pubKeyMasternode.GetID() = %s \n " ,
2017-06-06 01:47:23 +02:00
GetStatus ( ) , GetTypeString ( ) , fPingerEnabled , pubKeyMasternode . GetID ( ) . ToString ( ) ) ;
2016-10-25 16:37:33 +02:00
2017-07-01 21:00:40 +02:00
mnodeman . CheckMasternode ( pubKeyMasternode , true ) ;
2016-10-17 20:54:28 +02:00
masternode_info_t infoMn = mnodeman . GetMasternodeInfo ( pubKeyMasternode ) ;
if ( infoMn . fInfoValid ) {
if ( infoMn . nProtocolVersion ! = PROTOCOL_VERSION ) {
nState = ACTIVE_MASTERNODE_NOT_CAPABLE ;
strNotCapableReason = " Invalid protocol version " ;
2016-10-26 23:21:39 +02:00
LogPrintf ( " CActiveMasternode::ManageStateRemote -- %s: %s \n " , GetStateString ( ) , strNotCapableReason ) ;
return ;
}
if ( service ! = infoMn . addr ) {
nState = ACTIVE_MASTERNODE_NOT_CAPABLE ;
2017-02-19 22:02:33 +01:00
strNotCapableReason = " Broadcasted IP doesn't match our external address. Make sure you issued a new broadcast if IP of this masternode changed recently. " ;
2016-10-26 23:21:39 +02:00
LogPrintf ( " CActiveMasternode::ManageStateRemote -- %s: %s \n " , GetStateString ( ) , strNotCapableReason ) ;
2016-10-17 20:54:28 +02:00
return ;
}
2016-12-24 03:49:13 +01:00
if ( ! CMasternode : : IsValidStateForAutoStart ( infoMn . nActiveState ) ) {
2016-10-17 20:54:28 +02:00
nState = ACTIVE_MASTERNODE_NOT_CAPABLE ;
2016-10-26 23:21:39 +02:00
strNotCapableReason = strprintf ( " Masternode in %s state " , CMasternode : : StateToString ( infoMn . nActiveState ) ) ;
LogPrintf ( " CActiveMasternode::ManageStateRemote -- %s: %s \n " , GetStateString ( ) , strNotCapableReason ) ;
2016-12-24 03:49:13 +01:00
return ;
}
if ( nState ! = ACTIVE_MASTERNODE_STARTED ) {
LogPrintf ( " CActiveMasternode::ManageStateRemote -- STARTED! \n " ) ;
vin = infoMn . vin ;
service = infoMn . addr ;
fPingerEnabled = true ;
nState = ACTIVE_MASTERNODE_STARTED ;
2016-10-17 20:54:28 +02:00
}
}
else {
nState = ACTIVE_MASTERNODE_NOT_CAPABLE ;
2016-10-26 23:21:39 +02:00
strNotCapableReason = " Masternode not in masternode list " ;
LogPrintf ( " CActiveMasternode::ManageStateRemote -- %s: %s \n " , GetStateString ( ) , strNotCapableReason ) ;
2016-10-17 20:54:28 +02:00
}
}
void CActiveMasternode : : ManageStateLocal ( )
{
2016-10-26 23:21:39 +02:00
LogPrint ( " masternode " , " CActiveMasternode::ManageStateLocal -- status = %s, type = %s, pinger enabled = %d \n " , GetStatus ( ) , GetTypeString ( ) , fPingerEnabled ) ;
2016-10-17 20:54:28 +02:00
if ( nState = = ACTIVE_MASTERNODE_STARTED ) {
return ;
}
// Choose coins to use
CPubKey pubKeyCollateral ;
CKey keyCollateral ;
if ( pwalletMain - > GetMasternodeVinAndKeys ( vin , pubKeyCollateral , keyCollateral ) ) {
2017-08-25 14:56:48 +02:00
int nPrevoutAge = GetUTXOConfirmations ( vin . prevout ) ;
if ( nPrevoutAge < Params ( ) . GetConsensus ( ) . nMasternodeMinimumConfirmations ) {
2016-10-17 20:54:28 +02:00
nState = ACTIVE_MASTERNODE_INPUT_TOO_NEW ;
2017-08-25 14:56:48 +02:00
strNotCapableReason = strprintf ( _ ( " %s - %d confirmations " ) , GetStatus ( ) , nPrevoutAge ) ;
2016-10-26 23:21:39 +02:00
LogPrintf ( " CActiveMasternode::ManageStateLocal -- %s: %s \n " , GetStateString ( ) , strNotCapableReason ) ;
2016-10-17 20:54:28 +02:00
return ;
}
{
LOCK ( pwalletMain - > cs_wallet ) ;
pwalletMain - > LockCoin ( vin . prevout ) ;
}
CMasternodeBroadcast mnb ;
std : : string strError ;
if ( ! CMasternodeBroadcast : : Create ( vin , service , keyCollateral , pubKeyCollateral , keyMasternode , pubKeyMasternode , strError , mnb ) ) {
2016-10-26 23:21:39 +02:00
nState = ACTIVE_MASTERNODE_NOT_CAPABLE ;
strNotCapableReason = " Error creating mastenode broadcast: " + strError ;
LogPrintf ( " CActiveMasternode::ManageStateLocal -- %s: %s \n " , GetStateString ( ) , strNotCapableReason ) ;
2016-10-17 20:54:28 +02:00
return ;
}
2016-12-24 03:49:13 +01:00
fPingerEnabled = true ;
nState = ACTIVE_MASTERNODE_STARTED ;
2016-10-17 20:54:28 +02:00
//update to masternode list
LogPrintf ( " CActiveMasternode::ManageStateLocal -- Update Masternode List \n " ) ;
mnodeman . UpdateMasternodeList ( mnb ) ;
2016-11-13 18:52:34 +01:00
mnodeman . NotifyMasternodeUpdates ( ) ;
2016-10-17 20:54:28 +02:00
//send to all peers
LogPrintf ( " CActiveMasternode::ManageStateLocal -- Relay broadcast, vin=%s \n " , vin . ToString ( ) ) ;
mnb . Relay ( ) ;
}
}