15 #define MASTERNODE_MIN_MNP_SECONDS_REGTEST 90
16 #define MASTERNODE_MIN_MNB_SECONDS_REGTEST 25
17 #define MASTERNODE_PING_SECONDS_REGTEST 25
18 #define MASTERNODE_EXPIRATION_SECONDS_REGTEST 12 * 60
19 #define MASTERNODE_REMOVAL_SECONDS_REGTEST 13 * 60
21 #define MASTERNODE_MIN_MNP_SECONDS (10 * 60)
22 #define MASTERNODE_MIN_MNB_SECONDS (5 * 60)
23 #define MASTERNODE_PING_SECONDS (5 * 60)
24 #define MASTERNODE_EXPIRATION_SECONDS (120 * 60)
25 #define MASTERNODE_REMOVAL_SECONDS (130 * 60)
26 #define MASTERNODE_CHECK_SECONDS 5
96 vin =
CTxIn(dmn->collateralOutpoint);
97 addr = dmn->pdmnState->addr;
172 return (hash3 > hash2 ? hash3 - hash2 : hash2 - hash3);
222 const std::string& strKeyMasternode,
223 const std::string& strTxHash,
224 const std::string& strOutputIndex,
225 std::string& strErrorRet,
230 CPubKey pubKeyCollateralAddressNew;
231 CKey keyCollateralAddressNew;
233 CKey keyMasternodeNew;
237 strErrorRet =
"Sync in progress. Must wait until sync is complete to start Masternode";
242 std::string strError;
243 if (strTxHash.empty() || strOutputIndex.empty()) {
244 strError =
"Invalid masternode collateral hash or output index";
245 return error(
"%s: %s", __func__, strError);
249 int collateralOutputIndex;
251 collateralOutputIndex = std::stoi(strOutputIndex.c_str());
252 }
catch (
const std::exception& e) {
253 strError =
"Invalid masternode output index";
254 return error(
"%s: %s on strOutputIndex", __func__, e.what());
258 strErrorRet =
strprintf(
"Invalid masternode key %s", strKeyMasternode);
265 if (
vpwallets.empty() || !
vpwallets[0]->GetMasternodeVinAndKeys(pubKeyCollateralAddressNew,
266 keyCollateralAddressNew,
270 strErrorRet = strError;
271 LogPrint(
BCLog::MASTERNODE,
"CMasternodeBroadcast::Create -- %s\n",
strprintf(
"Could not allocate txin %s:%s for masternode %s", strTxHash, strOutputIndex, strService));
279 if (nPort == 0) nPort = nDefaultPort;
283 if (!
CheckDefaultPort(_service, strErrorRet,
"CMasternodeBroadcast::Create"))
286 CTxIn txin(collateralOut.
hash, collateralOut.
n);
287 return Create(txin, _service, keyCollateralAddressNew, pubKeyCollateralAddressNew, keyMasternodeNew, pubKeyMasternodeNew, strErrorRet, mnbRet);
292 const CKey& keyCollateralAddressNew,
293 const CPubKey& pubKeyCollateralAddressNew,
294 const CKey& keyMasternodeNew,
295 const CPubKey& pubKeyMasternodeNew,
296 std::string& strErrorRet,
302 LogPrint(
BCLog::MASTERNODE,
"CMasternodeBroadcast::Create -- pubKeyCollateralAddressNew = %s, pubKeyMasternodeNew.GetID() = %s\n",
309 if (!mnp.
Sign(keyMasternodeNew, pubKeyMasternodeNew.
GetID())) {
316 mnbRet =
CMasternodeBroadcast(service, txin, pubKeyCollateralAddressNew, pubKeyMasternodeNew, PROTOCOL_VERSION, mnp);
325 if (!mnbRet.
Sign(keyCollateralAddressNew, pubKeyCollateralAddressNew)) {
337 std::string strError =
"";
342 return error(
"%s : SignMessage() (nMessVersion=%d) failed", __func__,
nMessVersion);
346 return error(
"%s : VerifyMessage() (nMessVersion=%d) failed, error: %s\n",
355 std::string strError =
"";
356 std::string strMessage = (
363 return error(
"%s : VerifyMessage (nMessVersion=%d) failed: %s", __func__,
nMessVersion, strError);
372 if (service.
GetPort() != nDefaultPort && !
Params().IsRegTestNet()) {
373 strErrorRet =
strprintf(
"Invalid port %u for masternode %s, only %d is supported on %s-net.",
375 LogPrintf(
"%s - %s\n", strContext, strErrorRet);
406 if (pubkeyScript.
size() != 25) {
415 if (pubkeyScript2.
size() != 25) {
426 std::string strError =
"";
431 return error(
"%s : Got bad Masternode address signature", __func__);
448 if (pmn ==
nullptr)
return true;
454 return error(
"%s : Bad sigTime %d for Masternode %20s %105s (existing broadcast is at %d)",
499 blockHash(nBlockHash),
549 const bool isMasternodeFound = (pmn !=
nullptr);
552 if(fCheckSigTimeOnly) {
553 if (isMasternodeFound && !isSignatureValid) {
573 if (!isSignatureValid) {
616 int refHeight = std::max(dmn->pdmnState->nRegisteredHeight, dmn->pdmnState->nPoSeRevivedHeight);
arith_uint256 UintToArith256(const uint256 &a)
const CChainParams & Params()
Return the currently selected parameters.
static const std::string MAIN
Chain name strings.
The block chain is a tree shaped structure starting with the genesis block at the root,...
uint256 GetBlockHash() const
int64_t GetBlockTime() const
int GetDefaultPort() const
bool IsRegTestNet() const
A writer stream (for serialization) that computes a 256-bit hash.
An encapsulated private key.
static bool CheckDefaultPort(CService service, std::string &strErrorRet, const std::string &strContext)
static bool Create(const CTxIn &vin, 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.
bool CheckAndUpdate(int &nDoS)
bool CheckSignature() const
bool Sign(const CKey &key, const CPubKey &pubKey)
uint256 GetSignatureHash() const override
int nLastScanningErrorBlockHeight
arith_uint256 CalculateScore(const uint256 &hash) const
bool IsAvailableState() const
void SetLastPing(const CMasternodePing &_lastPing)
bool IsBroadcastedWithin(int seconds)
std::string GetStrMessage() const override
bool UpdateFromNewBroadcast(CMasternodeBroadcast &mnb)
bool IsValidNetAddr() const
bool IsPingedWithin(int seconds, int64_t now=-1) const
CMasternode::state GetActiveState() const
CPubKey pubKeyCollateralAddress
std::map< uint256, CMasternodeBroadcast > mapSeenMasternodeBroadcast
uint256 GetBlockHashToPing() const
bool IsWithinDepth(const uint256 &nHash, int depth) const
std::map< uint256, CMasternodePing > mapSeenMasternodePing
CMasternode * Find(const COutPoint &collateralOut)
Find an entry.
bool CheckAndUpdate(int &nDos, bool fRequireAvailable=true, bool fCheckSigTimeOnly=false)
std::string GetStrMessage() const override
static bool SignMessage(const std::string &strMessage, std::vector< unsigned char > &vchSigRet, const CKey &key)
Sign the message, returns true if successful.
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 successful.
static bool GetKeysFromSecret(const std::string &strSecret, CKey &keyRet, CPubKey &pubkeyRet)
Set the private/public key values, returns true if successful.
std::string ToStringIP() const
bool IsAddrV1Compatible() const
Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
An outpoint - a combination of a transaction hash and an index n into its vout.
An encapsulated public key.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Serialized script, used inside transaction inputs and outputs.
A combination of a network address (CNetAddr) and a (TCP) port.
std::string ToString() const
Base Class for all signed messages on the network.
bool Sign(const CKey &key, const CKeyID &keyID)
CSignedMessage Class Functions inherited by network signed-messages.
bool CheckSignature(const CKeyID &keyID) const
std::vector< unsigned char > vchSig
An input of a transaction.
std::string ToString() const
bool IsBlockchainSynced() const
void AddedMasternodeList(const uint256 &hash)
256-bit unsigned big integer.
std::string ToString() const
std::string GetHex() const
std::shared_ptr< const CDeterministicMN > CDeterministicMNCPtr
std::unique_ptr< CConnman > g_connman
#define LogPrint(category,...)
int MasternodeMinPingSeconds()
#define MASTERNODE_EXPIRATION_SECONDS_REGTEST
int MasternodeBroadcastSeconds()
int64_t GetMaxTimeWindow()
#define MASTERNODE_REMOVAL_SECONDS
int MasternodeExpirationSeconds()
int MasternodeRemovalSeconds()
#define MASTERNODE_PING_SECONDS
#define MASTERNODE_MIN_MNB_SECONDS
#define MASTERNODE_PING_SECONDS_REGTEST
#define MASTERNODE_MIN_MNB_SECONDS_REGTEST
#define MASTERNODE_REMOVAL_SECONDS_REGTEST
#define MASTERNODE_MIN_MNP_SECONDS_REGTEST
#define MASTERNODE_MIN_MNP_SECONDS
#define MASTERNODE_EXPIRATION_SECONDS
int MasternodePingSeconds()
MasternodeRef MakeMasternodeRefForDMN(const CDeterministicMNCPtr &dmn)
std::shared_ptr< CMasternode > MasternodeRef
CMasternodeMan mnodeman
Masternode manager.
std::string EncodeDestination(const CWDestination &address, const CChainParams::Base58Type addrType)
bool IsReachable(enum Network net)
RecursiveMutex cs_main
Global state.
void SplitHostPort(std::string in, int &portOut, std::string &hostOut)
CService LookupNumeric(const std::string &name, int portDefault)
@ MSG_MASTERNODE_ANNOUNCE
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a PIVX scriptPubKey for the given CTxDestination.
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
bool error(const char *fmt, const Args &... args)
TierTwoSyncState g_tiertwo_sync_state
int64_t GetAdjustedTime()
uint256 uint256S(const char *str)
int ActiveProtocol()
See whether the protocol update is enforced for connected nodes.
std::atomic< bool > fImporting
std::atomic< bool > fReindex
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
std::vector< CWalletRef > vpwallets