@@ -314,7 +314,13 @@ CMasternodeBroadcast::CMasternodeBroadcast(const CMasternode& mn) :
314314 CMasternode(mn)
315315{ }
316316
317- bool CMasternodeBroadcast::Create (std::string strService, std::string strKeyMasternode, std::string strTxHash, std::string strOutputIndex, std::string& strErrorRet, CMasternodeBroadcast& mnbRet, bool fOffline )
317+ bool CMasternodeBroadcast::Create (const std::string& strService,
318+ const std::string& strKeyMasternode,
319+ const std::string& strTxHash,
320+ const std::string& strOutputIndex,
321+ std::string& strErrorRet,
322+ CMasternodeBroadcast& mnbRet,
323+ bool fOffline )
318324{
319325 CTxIn txin;
320326 CPubKey pubKeyCollateralAddressNew;
@@ -356,7 +362,14 @@ bool CMasternodeBroadcast::Create(std::string strService, std::string strKeyMast
356362 return Create (txin, _service, keyCollateralAddressNew, pubKeyCollateralAddressNew, keyMasternodeNew, pubKeyMasternodeNew, strErrorRet, mnbRet);
357363}
358364
359- bool CMasternodeBroadcast::Create (CTxIn txin, CService service, CKey keyCollateralAddressNew, CPubKey pubKeyCollateralAddressNew, CKey keyMasternodeNew, CPubKey pubKeyMasternodeNew, std::string& strErrorRet, CMasternodeBroadcast& mnbRet)
365+ bool CMasternodeBroadcast::Create (const CTxIn& txin,
366+ const CService& service,
367+ const CKey& keyCollateralAddressNew,
368+ const CPubKey& pubKeyCollateralAddressNew,
369+ const CKey& keyMasternodeNew,
370+ const CPubKey& pubKeyMasternodeNew,
371+ std::string& strErrorRet,
372+ CMasternodeBroadcast& mnbRet)
360373{
361374 // wait for reindex and/or import to finish
362375 if (fImporting || fReindex ) return false ;
@@ -365,7 +378,9 @@ bool CMasternodeBroadcast::Create(CTxIn txin, CService service, CKey keyCollater
365378 EncodeDestination (pubKeyCollateralAddressNew.GetID ()),
366379 pubKeyMasternodeNew.GetID ().ToString ());
367380
368- CMasternodePing mnp (txin);
381+ // Get block hash to ping (TODO: move outside of this function)
382+ const uint256& nBlockHashToPing = mnodeman.GetBlockHashToPing ();
383+ CMasternodePing mnp (txin, nBlockHashToPing);
369384 if (!mnp.Sign (keyMasternodeNew, pubKeyMasternodeNew)) {
370385 strErrorRet = strprintf (" Failed to sign ping, masternode=%s" , txin.prevout .hash .ToString ());
371386 LogPrint (BCLog::MASTERNODE," CMasternodeBroadcast::Create -- %s\n " , strErrorRet);
@@ -640,19 +655,12 @@ CMasternodePing::CMasternodePing() :
640655 sigTime(GetAdjustedTime())
641656{ }
642657
643- CMasternodePing::CMasternodePing (CTxIn& newVin) :
658+ CMasternodePing::CMasternodePing (const CTxIn& newVin, const uint256& nBlockHash ) :
644659 CSignedMessage(),
645660 vin(newVin),
661+ blockHash(nBlockHash),
646662 sigTime(GetAdjustedTime())
647- {
648- int nHeight;
649- {
650- LOCK (cs_main);
651- nHeight = chainActive.Height ();
652- if (nHeight > 12 )
653- blockHash = chainActive[nHeight - 12 ]->GetBlockHash ();
654- }
655- }
663+ { }
656664
657665uint256 CMasternodePing::GetHash () const
658666{
0 commit comments