15 #include <boost/lexical_cast.hpp> 31 lastPing(other.lastPing),
33 nCollateralMinConfBlockHash(other.nCollateralMinConfBlockHash),
34 nBlockLastPaid(other.nBlockLastPaid),
35 nPoSeBanScore(other.nPoSeBanScore),
36 nPoSeBanHeight(other.nPoSeBanHeight),
37 fAllowMixingTx(other.fAllowMixingTx),
38 fUnitTest(other.fUnitTest)
45 lastPing(mnb.lastPing),
113 return (hash3 > hash2 ? hash3 - hash2 : hash2 - hash3);
131 if(coins.
vout[outpoint.
n].nValue != 1000 *
COIN) {
156 if(!lockMain)
return;
202 if(fWaitForPing && !fOurMasternode) {
211 if(!fWaitForPing || fOurMasternode) {
224 LogPrint(
"masternode",
"CMasternode::Check -- outpoint=%s, nTimeLastWatchdogVote=%d, GetAdjustedTime()=%d, fWatchdogExpired=%d\n",
227 if(fWatchdogExpired) {
267 if(
out.nValue == 1000*
COIN &&
out.scriptPubKey == payee)
return true;
290 info.fInfoValid =
true;
305 default:
return "UNKNOWN";
331 for (
int i = 0; BlockReading && BlockReading->
nHeight >
nBlockLastPaid && i < nMaxBlocksToScanBack; i++) {
341 BOOST_FOREACH(
CTxOut txout, block.
vtx[0].vout)
350 if (BlockReading->
pprev == NULL) { assert(BlockReading);
break; }
351 BlockReading = BlockReading->
pprev;
362 CPubKey pubKeyCollateralAddressNew;
363 CKey keyCollateralAddressNew;
365 CKey keyMasternodeNew;
367 auto Log = [&strErrorRet](std::string sErr)->
bool 370 LogPrintf(
"CMasternodeBroadcast::Create -- %s\n", strErrorRet);
376 return Log(
"Sync in progress. Must wait until sync is complete to start Masternode");
379 return Log(
strprintf(
"Invalid masternode key %s", strKeyMasternode));
382 return Log(
strprintf(
"Could not allocate outpoint %s:%s for masternode %s", strTxHash, strOutputIndex, strService));
385 if (!
Lookup(strService.c_str(), service, 0,
false))
386 return Log(
strprintf(
"Invalid address %s for masternode.", strService));
389 if (service.
GetPort() != mainnetDefaultPort)
390 return Log(
strprintf(
"Invalid port %u for masternode %s, only %d is supported on mainnet.", service.
GetPort(), strService, mainnetDefaultPort));
391 }
else if (service.
GetPort() == mainnetDefaultPort)
392 return Log(
strprintf(
"Invalid port %u for masternode %s, %d is the only supported on mainnet.", service.
GetPort(), strService, mainnetDefaultPort));
394 return Create(outpoint, service, keyCollateralAddressNew, pubKeyCollateralAddressNew, keyMasternodeNew, pubKeyMasternodeNew, strErrorRet, mnbRet);
402 LogPrint(
"masternode",
"CMasternodeBroadcast::Create -- pubKeyCollateralAddressNew = %s, pubKeyMasternodeNew.GetID() = %s\n",
406 auto Log = [&strErrorRet,&mnbRet](std::string sErr)->
bool 409 LogPrintf(
"CMasternodeBroadcast::Create -- %s\n", strErrorRet);
415 if (!mnp.
Sign(keyMasternodeNew, pubKeyMasternodeNew))
424 if (!mnbRet.
Sign(keyCollateralAddressNew))
436 LogPrintf(
"CMasternodeBroadcast::SimpleCheck -- Invalid addr, rejected: masternode=%s addr=%s\n",
462 if(pubkeyScript.
size() != 25) {
463 LogPrintf(
"CMasternodeBroadcast::SimpleCheck -- pubKeyCollateralAddress has the wrong size\n");
471 if(pubkeyScript2.
size() != 25) {
472 LogPrintf(
"CMasternodeBroadcast::SimpleCheck -- pubKeyMasternode has the wrong size\n");
478 LogPrintf(
"CMasternodeBroadcast::SimpleCheck -- Ignore Not Empty ScriptSig %s\n",
vin.
ToString());
485 if(
addr.
GetPort() != mainnetDefaultPort)
return false;
486 }
else if(
addr.
GetPort() == mainnetDefaultPort)
return false;
504 LogPrintf(
"CMasternodeBroadcast::Update -- Bad sigTime %d (existing broadcast is at %d) for Masternode %s %s\n",
519 LogPrintf(
"CMasternodeBroadcast::Update -- Got mismatched pubKeyCollateralAddress and vin\n");
532 LogPrintf(
"CMasternodeBroadcast::Update -- Got UPDATED Masternode entry: addr=%s\n",
addr.
ToString());
560 LogPrint(
"masternode",
"CMasternodeBroadcast::CheckOutpoint -- Failed to aquire lock, addr=%s",
addr.
ToString());
578 LogPrintf(
"CMasternodeBroadcast::CheckOutpoint -- Masternode UTXO must have at least %d confirmations, masternode=%s\n",
588 LogPrint(
"masternode",
"CMasternodeBroadcast::CheckOutpoint -- Masternode UTXO verified\n");
593 LogPrintf(
"CMasternodeMan::CheckOutpoint -- Got mismatched pubKeyCollateralAddress and vin\n");
610 LogPrintf(
"CMasternodeBroadcast::CheckOutpoint -- Bad sigTime %d (%d conf block is at %d) for Masternode %s %s\n",
622 std::string strError;
623 std::string strMessage;
632 LogPrintf(
"CMasternodeBroadcast::Sign -- SignMessage() failed\n");
637 LogPrintf(
"CMasternodeBroadcast::Sign -- VerifyMessage() failed, error: %s\n", strError);
646 std::string strMessage;
647 std::string strError =
"";
657 LogPrintf(
"CMasternodeBroadcast::CheckSignature -- Got bad Masternode announce signature, error: %s\n", strError);
683 std::string strError;
684 std::string strMasterNodeSignMessage;
691 LogPrintf(
"CMasternodePing::Sign -- SignMessage() failed\n");
696 LogPrintf(
"CMasternodePing::Sign -- VerifyMessage() failed, error: %s\n", strError);
707 std::string strError =
"";
757 if(!fFromNewBroadcast) {
764 LogPrint(
"masternode",
"CMasternodePing::CheckAndUpdate -- masternode is completely expired, new start is required, masternode=%s\n",
vin.
prevout.
ToStringShort());
862 std::vector<uint256> vecDirty;
866 vecDirty.push_back(it->first);
870 for(
size_t i = 0; i < vecDirty.size(); ++i) {
bool CheckOutpoint(int &nDos)
CMasternodeSync masternodeSync
bool Update(CMasternode *pmn, int &nDos, CConnman &connman)
CAmount GetMasternodePayment(int nHeight, CAmount blockValue)
std::string NetworkIDString() const
void UpdateWatchdogVoteTime(uint64_t nVoteTime=0)
CActiveMasternode activeMasternode
#define TRY_LOCK(cs, name)
void Relay(CConnman &connman)
bool UpdateFromNewBroadcast(CMasternodeBroadcast &mnb, CConnman &connman)
bool GetUTXOCoins(const COutPoint &outpoint, CCoins &coins)
bool SimpleCheck(int &nDos)
const Consensus::Params & GetConsensus() const
static const CAmount COIN
int64_t nTimeLastWatchdogVote
void AddDirtyGovernanceObjectHash(const uint256 &nHash)
std::vector< unsigned char > vchSig
bool CheckAndUpdate(CMasternode *pmn, bool fFromNewBroadcast, int &nDos, CConnman &connman)
void FlagGovernanceItemsAsDirty()
std::map< uint256, CMasternodePing > mapSeenMasternodePing
void RelayInv(CInv &inv, const int minProtoVersion=MIN_PEER_PROTO_VERSION)
std::map< uint256, std::pair< int64_t, CMasternodeBroadcast > > mapSeenMasternodeBroadcast
std::string ToString(bool fUseGetnameinfo=true) const
bool Sign(const CKey &keyCollateralAddress)
static const int MASTERNODE_NEW_START_REQUIRED_SECONDS
CCriticalSection cs_mapMasternodeBlocks
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
std::vector< unsigned char > vchSig
arith_uint256 UintToArith256(const uint256 &a)
int GetDefaultPort() const
std::vector< CTransaction > vtx
string EncodeBase64(const unsigned char *pch, size_t len)
unsigned short GetPort() const
static const int MASTERNODE_WATCHDOG_MAX_SECONDS
bool IsBroadcastedWithin(int nSeconds)
static CollateralStatus CheckCollateral(const COutPoint &outpoint)
std::map< uint256, int > mapGovernanceObjectsVotedOn
std::string GetStateString() const
#define AssertLockHeld(cs)
bool IsInputAssociatedWithPubkey()
Is the input associated with collateral public key? (and there is 1000 DASH - checking if valid maste...
static bool GetKeysFromSecret(const std::string strSecret, CKey &keyRet, CPubKey &pubkeyRet)
Set the private/public key values, returns true if successful.
std::atomic< bool > fDIP0001WasLockedIn
std::vector< CTxOut > vout
unspent transaction outputs; spent outputs are .IsNull(); spent outputs at the end of the array are d...
static const int MASTERNODE_MIN_MNB_SECONDS
std::string GetStatus() const
int nMasternodeMinimumConfirmations
bool Sign(const CKey &keyMasternode, const CPubKey &pubKeyMasternode)
static const int MASTERNODE_CHECK_SECONDS
arith_uint256 CalculateScore(const uint256 &blockHash)
CMasternodePayments mnpayments
CMasternodePing()=default
static int LogPrint(const char *category, const char *format)
std::string ToString() const
static bool Create(const COutPoint &outpoint, const CService &service, const CKey &keyCollateralAddressNew, const CPubKey &pubKeyCollateralAddressNew, const CKey &keyMasternodeNew, const CPubKey &pubKeyMasternodeNew, std::string &strErrorRet, CMasternodeBroadcast &mnbRet)
Create Masternode broadcast, needs to be relayed manually after that.
void RemoveGovernanceObject(uint256 nGovernanceObjectHash)
void UpdateLastPaid(const CBlockIndex *pindex, int nMaxBlocksToScanBack)
void Check(bool fForce=false)
static bool VerifyMessage(const CPubKey pubkey, const std::vector< unsigned char > &vchSig, const std::string strMessage, std::string &strErrorRet)
Verify the message signature, returns true if succcessful.
std::string ToString() const
CScript GetScriptForDestination(const CTxDestination &dest)
bool CheckSignature(CPubKey &pubKeyMasternode, int &nDos)
int size()
Return the number of (unique) Masternodes.
static const int MASTERNODE_MIN_MNP_SECONDS
bool IsNewStartRequired()
void ManageState(CConnman &connman)
Manage state of active Masternode.
void AddGovernanceVote(uint256 nGovernanceObjectHash)
CPubKey pubKeyCollateralAddress
static const int MASTERNODE_EXPIRATION_SECONDS
bool IsReachable(enum Network net)
uint256 ArithToUint256(const arith_uint256 &a)
static const int MASTERNODE_POSE_BAN_MAX_SCORE
const CChainParams & Params()
bool CheckSignature(int &nDos)
static const int PROTOCOL_VERSION
static std::string StateToString(int nStateIn)
int64_t GetAdjustedTime()
bool IsBlockchainSynced()
bool Lookup(const char *pszName, std::vector< CService > &vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions)
bool SimpleCheck(int &nDos)
CBlockIndex * Tip() const
masternode_info_t GetInfo()
bool GetMasternodeOutpointAndKeys(COutPoint &outpointRet, CPubKey &pubKeyRet, CKey &keyRet, std::string strTxHash="", std::string strOutputIndex="")
Get 1000DASH output and keys which can be used for the Masternode.
static const std::string MAIN
static bool SignMessage(const std::string strMessage, std::vector< unsigned char > &vchSigRet, const CKey key)
Sign the message, returns true if successful.
int64_t GetBlockTime() const
CBlockIndex * pprev
pointer to the index of the predecessor of this block
int64_t GetTime()
For unit testing.
bool GetTransaction(const uint256 &hash, CTransaction &txOut, const Consensus::Params &consensusParams, uint256 &hashBlock, bool fAllowSlow)
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos, const Consensus::Params &consensusParams)
void BumpAssetLastTime(std::string strFuncName)
int GetMinMasternodePaymentsProto()
void Relay(CConnman &connman)
int nHeight
height of the entry in the chain. The genesis block has height 0
std::string ToStringShort() const
void DecreasePoSeBanScore()
bool IsMasternodeListSynced()
uint256 nCollateralMinConfBlockHash
std::map< int, CMasternodeBlockPayees > mapMasternodeBlocks
int nHeight
at which height this transaction was included in the active block chain
bool IsPingedWithin(int nSeconds, int64_t nTimeToCheckAt=-1)
static const std::string REGTEST