mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
drop pCurrentBlockIndex and use cached block height instead (nCachedBlockHeight) (#1579)
This commit is contained in:
parent
23582aea45
commit
fe81d641da
@ -23,8 +23,7 @@ const int CGovernanceManager::MAX_TIME_FUTURE_DEVIATION = 60*60;
|
||||
const int CGovernanceManager::RELIABLE_PROPAGATION_TIME = 60;
|
||||
|
||||
CGovernanceManager::CGovernanceManager()
|
||||
: pCurrentBlockIndex(NULL),
|
||||
nTimeLastDiff(0),
|
||||
: nTimeLastDiff(0),
|
||||
nCachedBlockHeight(0),
|
||||
mapObjects(),
|
||||
mapErasedGovernanceObjects(),
|
||||
@ -149,10 +148,6 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
|
||||
{
|
||||
// MAKE SURE WE HAVE A VALID REFERENCE TO THE TIP BEFORE CONTINUING
|
||||
|
||||
if(!pCurrentBlockIndex) {
|
||||
LogPrintf("MNGOVERNANCEOBJECT -- pCurrentBlockIndex is NULL\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!masternodeSync.IsMasternodeListSynced()) {
|
||||
LogPrint("gobject", "MNGOVERNANCEOBJECT -- masternode list not synced\n");
|
||||
@ -472,14 +467,8 @@ void CGovernanceManager::UpdateCachesAndClean()
|
||||
it->second.fDirtyCache = true;
|
||||
}
|
||||
|
||||
// DOUBLE CHECK THAT WE HAVE A VALID POINTER TO TIP
|
||||
|
||||
if(!pCurrentBlockIndex) return;
|
||||
|
||||
CRateChecksGuard guard(false, *this);
|
||||
|
||||
LogPrint("gobject", "CGovernanceManager::UpdateCachesAndClean -- After pCurrentBlockIndex (not NULL)\n");
|
||||
|
||||
// UPDATE CACHE FOR EACH OBJECT THAT IS FLAGGED DIRTYCACHE=TRUE
|
||||
|
||||
object_m_it it = mapObjects.begin();
|
||||
@ -681,15 +670,7 @@ struct sortProposalsByVotes {
|
||||
|
||||
void CGovernanceManager::DoMaintenance()
|
||||
{
|
||||
// NOTHING TO DO IN LITEMODE
|
||||
if(fLiteMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
// IF WE'RE NOT SYNCED, EXIT
|
||||
if(!masternodeSync.IsSynced()) return;
|
||||
|
||||
if(!pCurrentBlockIndex) return;
|
||||
if(fLiteMode || !masternodeSync.IsSynced()) return;
|
||||
|
||||
// CHECK OBJECTS WE'VE ASKED FOR, REMOVE OLD ENTRIES
|
||||
|
||||
@ -1400,12 +1381,8 @@ void CGovernanceManager::UpdatedBlockTip(const CBlockIndex *pindex)
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
LOCK(cs);
|
||||
pCurrentBlockIndex = pindex;
|
||||
nCachedBlockHeight = pCurrentBlockIndex->nHeight;
|
||||
LogPrint("gobject", "CGovernanceManager::UpdatedBlockTip pCurrentBlockIndex->nHeight: %d\n", pCurrentBlockIndex->nHeight);
|
||||
}
|
||||
nCachedBlockHeight = pindex->nHeight;
|
||||
LogPrint("gobject", "CGovernanceManager::UpdatedBlockTip -- nCachedBlockHeight: %d\n", nCachedBlockHeight);
|
||||
|
||||
CheckPostponedObjects();
|
||||
}
|
||||
|
@ -226,10 +226,9 @@ private:
|
||||
static const int MAX_TIME_FUTURE_DEVIATION;
|
||||
static const int RELIABLE_PROPAGATION_TIME;
|
||||
|
||||
// Keep track of current block index
|
||||
const CBlockIndex *pCurrentBlockIndex;
|
||||
|
||||
int64_t nTimeLastDiff;
|
||||
|
||||
// keep track of current block height
|
||||
int nCachedBlockHeight;
|
||||
|
||||
// keep track of the scanning errors
|
||||
|
@ -1972,7 +1972,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
|
||||
// ********************************************************* Step 11c: update block tip in Dash modules
|
||||
|
||||
// force UpdatedBlockTip to initialize pCurrentBlockIndex for DS, MN payments and budgets
|
||||
// force UpdatedBlockTip to initialize nCachedBlockHeight for DS, MN payments and budgets
|
||||
// but don't call it directly to prevent triggering of other listeners like zmq etc.
|
||||
// GetMainSignals().UpdatedBlockTip(chainActive.Tip());
|
||||
mnodeman.UpdatedBlockTip(chainActive.Tip());
|
||||
|
@ -605,7 +605,7 @@ int64_t CInstantSend::GetAverageMasternodeOrphanVoteTime()
|
||||
|
||||
void CInstantSend::CheckAndRemove()
|
||||
{
|
||||
if(!pCurrentBlockIndex) return;
|
||||
if(!masternodeSync.IsMasternodeListSynced()) return;
|
||||
|
||||
LOCK(cs_instantsend);
|
||||
|
||||
@ -615,7 +615,7 @@ void CInstantSend::CheckAndRemove()
|
||||
while(itLockCandidate != mapTxLockCandidates.end()) {
|
||||
CTxLockCandidate &txLockCandidate = itLockCandidate->second;
|
||||
uint256 txHash = txLockCandidate.GetHash();
|
||||
if(txLockCandidate.IsExpired(pCurrentBlockIndex->nHeight)) {
|
||||
if(txLockCandidate.IsExpired(nCachedBlockHeight)) {
|
||||
LogPrintf("CInstantSend::CheckAndRemove -- Removing expired Transaction Lock Candidate: txid=%s\n", txHash.ToString());
|
||||
std::map<COutPoint, COutPointLock>::iterator itOutpointLock = txLockCandidate.mapOutPointLocks.begin();
|
||||
while(itOutpointLock != txLockCandidate.mapOutPointLocks.end()) {
|
||||
@ -634,7 +634,7 @@ void CInstantSend::CheckAndRemove()
|
||||
// remove expired votes
|
||||
std::map<uint256, CTxLockVote>::iterator itVote = mapTxLockVotes.begin();
|
||||
while(itVote != mapTxLockVotes.end()) {
|
||||
if(itVote->second.IsExpired(pCurrentBlockIndex->nHeight)) {
|
||||
if(itVote->second.IsExpired(nCachedBlockHeight)) {
|
||||
LogPrint("instantsend", "CInstantSend::CheckAndRemove -- Removing expired vote: txid=%s masternode=%s\n",
|
||||
itVote->second.GetTxHash().ToString(), itVote->second.GetMasternodeOutpoint().ToStringShort());
|
||||
mapTxLockVotes.erase(itVote++);
|
||||
@ -803,7 +803,7 @@ void CInstantSend::Relay(const uint256& txHash)
|
||||
|
||||
void CInstantSend::UpdatedBlockTip(const CBlockIndex *pindex)
|
||||
{
|
||||
pCurrentBlockIndex = pindex;
|
||||
nCachedBlockHeight = pindex->nHeight;
|
||||
}
|
||||
|
||||
void CInstantSend::SyncTransaction(const CTransaction& tx, const CBlock* pblock)
|
||||
|
@ -39,8 +39,8 @@ class CInstantSend
|
||||
private:
|
||||
static const int ORPHAN_VOTE_SECONDS = 60;
|
||||
|
||||
// Keep track of current block index
|
||||
const CBlockIndex *pCurrentBlockIndex;
|
||||
// Keep track of current block height
|
||||
int nCachedBlockHeight;
|
||||
|
||||
// maps for AlreadyHave
|
||||
std::map<uint256, CTxLockRequest> mapLockRequestAccepted; // tx hash - tx
|
||||
|
@ -338,8 +338,6 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand,
|
||||
|
||||
if(pfrom->nVersion < GetMinMasternodePaymentsProto()) return;
|
||||
|
||||
if(!pCurrentBlockIndex) return;
|
||||
|
||||
uint256 nHash = vote.GetHash();
|
||||
|
||||
pfrom->setAskFor.erase(nHash);
|
||||
@ -347,7 +345,7 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand,
|
||||
{
|
||||
LOCK(cs_mapMasternodePaymentVotes);
|
||||
if(mapMasternodePaymentVotes.count(nHash)) {
|
||||
LogPrint("mnpayments", "MASTERNODEPAYMENTVOTE -- hash=%s, nHeight=%d seen\n", nHash.ToString(), pCurrentBlockIndex->nHeight);
|
||||
LogPrint("mnpayments", "MASTERNODEPAYMENTVOTE -- hash=%s, nHeight=%d seen\n", nHash.ToString(), nCachedBlockHeight);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -358,14 +356,14 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand,
|
||||
mapMasternodePaymentVotes[nHash].MarkAsNotVerified();
|
||||
}
|
||||
|
||||
int nFirstBlock = pCurrentBlockIndex->nHeight - GetStorageLimit();
|
||||
if(vote.nBlockHeight < nFirstBlock || vote.nBlockHeight > pCurrentBlockIndex->nHeight+20) {
|
||||
LogPrint("mnpayments", "MASTERNODEPAYMENTVOTE -- vote out of range: nFirstBlock=%d, nBlockHeight=%d, nHeight=%d\n", nFirstBlock, vote.nBlockHeight, pCurrentBlockIndex->nHeight);
|
||||
int nFirstBlock = nCachedBlockHeight - GetStorageLimit();
|
||||
if(vote.nBlockHeight < nFirstBlock || vote.nBlockHeight > nCachedBlockHeight+20) {
|
||||
LogPrint("mnpayments", "MASTERNODEPAYMENTVOTE -- vote out of range: nFirstBlock=%d, nBlockHeight=%d, nHeight=%d\n", nFirstBlock, vote.nBlockHeight, nCachedBlockHeight);
|
||||
return;
|
||||
}
|
||||
|
||||
std::string strError = "";
|
||||
if(!vote.IsValid(pfrom, pCurrentBlockIndex->nHeight, strError)) {
|
||||
if(!vote.IsValid(pfrom, nCachedBlockHeight, strError)) {
|
||||
LogPrint("mnpayments", "MASTERNODEPAYMENTVOTE -- invalid message, error: %s\n", strError);
|
||||
return;
|
||||
}
|
||||
@ -384,7 +382,7 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand,
|
||||
}
|
||||
|
||||
int nDos = 0;
|
||||
if(!vote.CheckSignature(mnInfo.pubKeyMasternode, pCurrentBlockIndex->nHeight, nDos)) {
|
||||
if(!vote.CheckSignature(mnInfo.pubKeyMasternode, nCachedBlockHeight, nDos)) {
|
||||
if(nDos) {
|
||||
LogPrintf("MASTERNODEPAYMENTVOTE -- ERROR: invalid signature\n");
|
||||
Misbehaving(pfrom->GetId(), nDos);
|
||||
@ -406,7 +404,7 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand,
|
||||
CBitcoinAddress address2(address1);
|
||||
|
||||
LogPrint("mnpayments", "MASTERNODEPAYMENTVOTE -- vote: address=%s, nBlockHeight=%d, nHeight=%d, prevout=%s, hash=%s new\n",
|
||||
address2.ToString(), vote.nBlockHeight, pCurrentBlockIndex->nHeight, vote.vinMasternode.prevout.ToStringShort(), nHash.ToString());
|
||||
address2.ToString(), vote.nBlockHeight, nCachedBlockHeight, vote.vinMasternode.prevout.ToStringShort(), nHash.ToString());
|
||||
|
||||
if(AddPaymentVote(vote)){
|
||||
vote.Relay();
|
||||
@ -450,13 +448,13 @@ bool CMasternodePayments::IsScheduled(CMasternode& mn, int nNotBlockHeight)
|
||||
{
|
||||
LOCK(cs_mapMasternodeBlocks);
|
||||
|
||||
if(!pCurrentBlockIndex) return false;
|
||||
if(!masternodeSync.IsMasternodeListSynced()) return false;
|
||||
|
||||
CScript mnpayee;
|
||||
mnpayee = GetScriptForDestination(mn.pubKeyCollateralAddress.GetID());
|
||||
|
||||
CScript payee;
|
||||
for(int64_t h = pCurrentBlockIndex->nHeight; h <= pCurrentBlockIndex->nHeight + 8; h++){
|
||||
for(int64_t h = nCachedBlockHeight; h <= nCachedBlockHeight + 8; h++){
|
||||
if(h == nNotBlockHeight) continue;
|
||||
if(mapMasternodeBlocks.count(h) && mapMasternodeBlocks[h].GetBestPayee(payee) && mnpayee == payee) {
|
||||
return true;
|
||||
@ -633,7 +631,7 @@ bool CMasternodePayments::IsTransactionValid(const CTransaction& txNew, int nBlo
|
||||
|
||||
void CMasternodePayments::CheckAndRemove()
|
||||
{
|
||||
if(!pCurrentBlockIndex) return;
|
||||
if(!masternodeSync.IsBlockchainSynced()) return;
|
||||
|
||||
LOCK2(cs_mapMasternodeBlocks, cs_mapMasternodePaymentVotes);
|
||||
|
||||
@ -643,7 +641,7 @@ void CMasternodePayments::CheckAndRemove()
|
||||
while(it != mapMasternodePaymentVotes.end()) {
|
||||
CMasternodePaymentVote vote = (*it).second;
|
||||
|
||||
if(pCurrentBlockIndex->nHeight - vote.nBlockHeight > nLimit) {
|
||||
if(nCachedBlockHeight - vote.nBlockHeight > nLimit) {
|
||||
LogPrint("mnpayments", "CMasternodePayments::CheckAndRemove -- Removing old Masternode payment: nBlockHeight=%d\n", vote.nBlockHeight);
|
||||
mapMasternodePaymentVotes.erase(it++);
|
||||
mapMasternodeBlocks.erase(vote.nBlockHeight);
|
||||
@ -824,11 +822,11 @@ void CMasternodePayments::Sync(CNode* pnode)
|
||||
{
|
||||
LOCK(cs_mapMasternodeBlocks);
|
||||
|
||||
if(!pCurrentBlockIndex) return;
|
||||
if(!masternodeSync.IsWinnersListSynced()) return;
|
||||
|
||||
int nInvCount = 0;
|
||||
|
||||
for(int h = pCurrentBlockIndex->nHeight; h < pCurrentBlockIndex->nHeight + 20; h++) {
|
||||
for(int h = nCachedBlockHeight; h < nCachedBlockHeight + 20; h++) {
|
||||
if(mapMasternodeBlocks.count(h)) {
|
||||
BOOST_FOREACH(CMasternodePayee& payee, mapMasternodeBlocks[h].vecPayees) {
|
||||
std::vector<uint256> vecVoteHashes = payee.GetVoteHashes();
|
||||
@ -848,16 +846,16 @@ void CMasternodePayments::Sync(CNode* pnode)
|
||||
// Request low data/unknown payment blocks in batches directly from some node instead of/after preliminary Sync.
|
||||
void CMasternodePayments::RequestLowDataPaymentBlocks(CNode* pnode)
|
||||
{
|
||||
if(!pCurrentBlockIndex) return;
|
||||
if(!masternodeSync.IsMasternodeListSynced()) return;
|
||||
|
||||
LOCK2(cs_main, cs_mapMasternodeBlocks);
|
||||
|
||||
std::vector<CInv> vToFetch;
|
||||
int nLimit = GetStorageLimit();
|
||||
|
||||
const CBlockIndex *pindex = pCurrentBlockIndex;
|
||||
const CBlockIndex *pindex = chainActive.Tip();
|
||||
|
||||
while(pCurrentBlockIndex->nHeight - pindex->nHeight < nLimit) {
|
||||
while(nCachedBlockHeight - pindex->nHeight < nLimit) {
|
||||
if(!mapMasternodeBlocks.count(pindex->nHeight)) {
|
||||
// We have no idea about this block height, let's ask
|
||||
vToFetch.push_back(CInv(MSG_MASTERNODE_PAYMENT_BLOCK, pindex->GetBlockHash()));
|
||||
@ -949,8 +947,10 @@ int CMasternodePayments::GetStorageLimit()
|
||||
|
||||
void CMasternodePayments::UpdatedBlockTip(const CBlockIndex *pindex)
|
||||
{
|
||||
pCurrentBlockIndex = pindex;
|
||||
LogPrint("mnpayments", "CMasternodePayments::UpdatedBlockTip -- pCurrentBlockIndex->nHeight=%d\n", pCurrentBlockIndex->nHeight);
|
||||
if(!pindex) return;
|
||||
|
||||
ProcessBlock(pindex->nHeight + 10);
|
||||
nCachedBlockHeight = pindex->nHeight;
|
||||
LogPrint("mnpayments", "CMasternodePayments::UpdatedBlockTip -- nCachedBlockHeight=%d\n", nCachedBlockHeight);
|
||||
|
||||
ProcessBlock(nCachedBlockHeight + 10);
|
||||
}
|
||||
|
@ -172,8 +172,8 @@ private:
|
||||
// ... but at least nMinBlocksToStore (payments blocks)
|
||||
const int nMinBlocksToStore;
|
||||
|
||||
// Keep track of current block index
|
||||
const CBlockIndex *pCurrentBlockIndex;
|
||||
// Keep track of current block height
|
||||
int nCachedBlockHeight;
|
||||
|
||||
public:
|
||||
std::map<uint256, CMasternodePaymentVote> mapMasternodePaymentVotes;
|
||||
|
@ -145,7 +145,6 @@ void CMasternodeSync::ProcessTick()
|
||||
{
|
||||
static int nTick = 0;
|
||||
if(nTick++ % MASTERNODE_SYNC_TICK_SECONDS != 0) return;
|
||||
if(!pCurrentBlockIndex) return;
|
||||
|
||||
// reset the sync process if the last call to this function was more than 60 minutes ago (client was in sleep mode)
|
||||
static int64_t nTimeLastProcess = GetTime();
|
||||
@ -389,8 +388,7 @@ void CMasternodeSync::SendGovernanceSyncRequest(CNode* pnode)
|
||||
|
||||
void CMasternodeSync::UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload)
|
||||
{
|
||||
pCurrentBlockIndex = pindexNew;
|
||||
if(fDebug) LogPrintf("CMasternodeSync::UpdatedBlockTip -- pCurrentBlockIndex->nHeight: %d fInitialDownload=%d\n", pCurrentBlockIndex->nHeight, fInitialDownload);
|
||||
if(fDebug) LogPrintf("CMasternodeSync::UpdatedBlockTip -- pindexNew->nHeight: %d fInitialDownload=%d\n", pindexNew->nHeight, fInitialDownload);
|
||||
// nothing to do here if we failed to sync previousely,
|
||||
// just wait till status reset after a cooldown (see ProcessTick)
|
||||
if(IsFailed()) return;
|
||||
|
@ -46,9 +46,6 @@ private:
|
||||
// ... or failed
|
||||
int64_t nTimeLastFailure;
|
||||
|
||||
// Keep track of current block index
|
||||
const CBlockIndex *pCurrentBlockIndex;
|
||||
|
||||
void Fail();
|
||||
void ClearFulfilledRequests();
|
||||
|
||||
|
@ -210,8 +210,7 @@ void CMasternodeMan::CheckAndRemove()
|
||||
it = vMasternodes.erase(it);
|
||||
fMasternodesRemoved = true;
|
||||
} else {
|
||||
bool fAsk = pCurrentBlockIndex &&
|
||||
(nAskForMnbRecovery > 0) &&
|
||||
bool fAsk = (nAskForMnbRecovery > 0) &&
|
||||
masternodeSync.IsSynced() &&
|
||||
it->IsNewStartRequired() &&
|
||||
!IsMnbRecoveryRequested(hash);
|
||||
@ -220,7 +219,7 @@ void CMasternodeMan::CheckAndRemove()
|
||||
std::set<CNetAddr> setRequested;
|
||||
// calulate only once and only when it's needed
|
||||
if(vecMasternodeRanks.empty()) {
|
||||
int nRandomBlockHeight = GetRandInt(pCurrentBlockIndex->nHeight);
|
||||
int nRandomBlockHeight = GetRandInt(nCachedBlockHeight);
|
||||
vecMasternodeRanks = GetMasternodeRanks(nRandomBlockHeight);
|
||||
}
|
||||
bool fAskedForMnbRecovery = false;
|
||||
@ -321,7 +320,7 @@ void CMasternodeMan::CheckAndRemove()
|
||||
|
||||
std::map<CNetAddr, CMasternodeVerification>::iterator it3 = mWeAskedForVerification.begin();
|
||||
while(it3 != mWeAskedForVerification.end()){
|
||||
if(it3->second.nBlockHeight < pCurrentBlockIndex->nHeight - MAX_POSE_BLOCKS) {
|
||||
if(it3->second.nBlockHeight < nCachedBlockHeight - MAX_POSE_BLOCKS) {
|
||||
mWeAskedForVerification.erase(it3++);
|
||||
} else {
|
||||
++it3;
|
||||
@ -344,7 +343,7 @@ void CMasternodeMan::CheckAndRemove()
|
||||
// remove expired mapSeenMasternodeVerification
|
||||
std::map<uint256, CMasternodeVerification>::iterator itv2 = mapSeenMasternodeVerification.begin();
|
||||
while(itv2 != mapSeenMasternodeVerification.end()){
|
||||
if((*itv2).second.nBlockHeight < pCurrentBlockIndex->nHeight - MAX_POSE_BLOCKS){
|
||||
if((*itv2).second.nBlockHeight < nCachedBlockHeight - MAX_POSE_BLOCKS){
|
||||
LogPrint("masternode", "CMasternodeMan::CheckAndRemove -- Removing expired Masternode verification: hash=%s\n", (*itv2).first.ToString());
|
||||
mapSeenMasternodeVerification.erase(itv2++);
|
||||
} else {
|
||||
@ -541,15 +540,17 @@ bool CMasternodeMan::Has(const CTxIn& vin)
|
||||
//
|
||||
CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment(bool fFilterSigTime, int& nCount)
|
||||
{
|
||||
if(!pCurrentBlockIndex) {
|
||||
nCount = 0;
|
||||
return NULL;
|
||||
}
|
||||
return GetNextMasternodeInQueueForPayment(pCurrentBlockIndex->nHeight, fFilterSigTime, nCount);
|
||||
return GetNextMasternodeInQueueForPayment(nCachedBlockHeight, fFilterSigTime, nCount);
|
||||
}
|
||||
|
||||
CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, int& nCount)
|
||||
{
|
||||
if (!masternodeSync.IsWinnersListSynced()) {
|
||||
// without winner list we can't reliably find the next winner anyway
|
||||
nCount = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Need LOCK2 here to ensure consistent locking order because the GetBlockHash call below locks cs_main
|
||||
LOCK2(cs_main,cs);
|
||||
|
||||
@ -961,7 +962,7 @@ void CMasternodeMan::DoFullVerificationStep()
|
||||
if(activeMasternode.vin == CTxIn()) return;
|
||||
if(!masternodeSync.IsSynced()) return;
|
||||
|
||||
std::vector<std::pair<int, CMasternode> > vecMasternodeRanks = GetMasternodeRanks(pCurrentBlockIndex->nHeight - 1, MIN_POSE_PROTO_VERSION);
|
||||
std::vector<std::pair<int, CMasternode> > vecMasternodeRanks = GetMasternodeRanks(nCachedBlockHeight - 1, MIN_POSE_PROTO_VERSION);
|
||||
|
||||
// Need LOCK2 here to ensure consistent locking order because the SendVerifyRequest call below locks cs_main
|
||||
// through GetHeight() signal in ConnectNode
|
||||
@ -1106,7 +1107,7 @@ bool CMasternodeMan::SendVerifyRequest(const CAddress& addr, const std::vector<C
|
||||
|
||||
netfulfilledman.AddFulfilledRequest(addr, strprintf("%s", NetMsgType::MNVERIFY)+"-request");
|
||||
// use random nonce, store it and require node to reply with correct one later
|
||||
CMasternodeVerification mnv(addr, GetRandInt(999999), pCurrentBlockIndex->nHeight - 1);
|
||||
CMasternodeVerification mnv(addr, GetRandInt(999999), nCachedBlockHeight - 1);
|
||||
mWeAskedForVerification[addr] = mnv;
|
||||
LogPrintf("CMasternodeMan::SendVerifyRequest -- verifying node using nonce %d addr=%s\n", mnv.nonce, addr.ToString());
|
||||
g_connman->PushMessage(pnode, NetMsgType::MNVERIFY, mnv);
|
||||
@ -1274,9 +1275,9 @@ void CMasternodeMan::ProcessVerifyBroadcast(CNode* pnode, const CMasternodeVerif
|
||||
mapSeenMasternodeVerification[mnv.GetHash()] = mnv;
|
||||
|
||||
// we don't care about history
|
||||
if(mnv.nBlockHeight < pCurrentBlockIndex->nHeight - MAX_POSE_BLOCKS) {
|
||||
if(mnv.nBlockHeight < nCachedBlockHeight - MAX_POSE_BLOCKS) {
|
||||
LogPrint("masternode", "CMasternodeMan::ProcessVerifyBroadcast -- Outdated: current block %d, verification block %d, peer=%d\n",
|
||||
pCurrentBlockIndex->nHeight, mnv.nBlockHeight, pnode->id);
|
||||
nCachedBlockHeight, mnv.nBlockHeight, pnode->id);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1495,12 +1496,11 @@ bool CMasternodeMan::CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBr
|
||||
return true;
|
||||
}
|
||||
|
||||
void CMasternodeMan::UpdateLastPaid()
|
||||
void CMasternodeMan::UpdateLastPaid(const CBlockIndex* pindex)
|
||||
{
|
||||
LOCK(cs);
|
||||
|
||||
if(fLiteMode || !pCurrentBlockIndex) return;
|
||||
if(!masternodeSync.IsWinnersListSynced() || vMasternodes.empty()) return;
|
||||
if(fLiteMode || !masternodeSync.IsWinnersListSynced() || vMasternodes.empty()) return;
|
||||
|
||||
static bool IsFirstRun = true;
|
||||
// Do full scan on first run or if we are not a masternode
|
||||
@ -1508,10 +1508,10 @@ void CMasternodeMan::UpdateLastPaid()
|
||||
int nMaxBlocksToScanBack = (IsFirstRun || !fMasterNode) ? mnpayments.GetStorageLimit() : LAST_PAID_SCAN_BLOCKS;
|
||||
|
||||
// LogPrint("mnpayments", "CMasternodeMan::UpdateLastPaid -- nHeight=%d, nMaxBlocksToScanBack=%d, IsFirstRun=%s\n",
|
||||
// pCurrentBlockIndex->nHeight, nMaxBlocksToScanBack, IsFirstRun ? "true" : "false");
|
||||
// nCachedBlockHeight, nMaxBlocksToScanBack, IsFirstRun ? "true" : "false");
|
||||
|
||||
BOOST_FOREACH(CMasternode& mn, vMasternodes) {
|
||||
mn.UpdateLastPaid(pCurrentBlockIndex, nMaxBlocksToScanBack);
|
||||
mn.UpdateLastPaid(pindex, nMaxBlocksToScanBack);
|
||||
}
|
||||
|
||||
IsFirstRun = false;
|
||||
@ -1666,14 +1666,14 @@ void CMasternodeMan::SetMasternodeLastPing(const CTxIn& vin, const CMasternodePi
|
||||
|
||||
void CMasternodeMan::UpdatedBlockTip(const CBlockIndex *pindex)
|
||||
{
|
||||
pCurrentBlockIndex = pindex;
|
||||
LogPrint("masternode", "CMasternodeMan::UpdatedBlockTip -- pCurrentBlockIndex->nHeight=%d\n", pCurrentBlockIndex->nHeight);
|
||||
nCachedBlockHeight = pindex->nHeight;
|
||||
LogPrint("masternode", "CMasternodeMan::UpdatedBlockTip -- nCachedBlockHeight=%d\n", nCachedBlockHeight);
|
||||
|
||||
CheckSameAddr();
|
||||
|
||||
if(fMasterNode) {
|
||||
// normal wallet does not need to update this every block, doing update on rpc call should be enough
|
||||
UpdateLastPaid();
|
||||
UpdateLastPaid(pindex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,8 +114,8 @@ private:
|
||||
// critical section to protect the inner data structures
|
||||
mutable CCriticalSection cs;
|
||||
|
||||
// Keep track of current block index
|
||||
const CBlockIndex *pCurrentBlockIndex;
|
||||
// Keep track of current block height
|
||||
int nCachedBlockHeight;
|
||||
|
||||
// map to hold all MNs
|
||||
std::vector<CMasternode> vMasternodes;
|
||||
@ -321,7 +321,7 @@ public:
|
||||
bool CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBroadcast mnb, int& nDos);
|
||||
bool IsMnbRecoveryRequested(const uint256& hash) { return mMnbRecoveryRequests.count(hash); }
|
||||
|
||||
void UpdateLastPaid();
|
||||
void UpdateLastPaid(const CBlockIndex* pindex);
|
||||
bool UpdateLastDsq(const CTxIn& vin);
|
||||
|
||||
void CheckAndRebuildMasternodeIndex();
|
||||
|
@ -242,7 +242,7 @@ std::string CPrivateSendClient::GetStatus()
|
||||
nStatusMessageProgress += 10;
|
||||
std::string strSuffix = "";
|
||||
|
||||
if((pCurrentBlockIndex && pCurrentBlockIndex->nHeight - nCachedLastSuccessBlock < nMinBlockSpacing) || !masternodeSync.IsBlockchainSynced())
|
||||
if((nCachedBlockHeight - nCachedLastSuccessBlock < nMinBlockSpacing) || !masternodeSync.IsBlockchainSynced())
|
||||
return strAutoDenomResult;
|
||||
|
||||
switch(nState) {
|
||||
@ -578,7 +578,7 @@ void CPrivateSendClient::CompletedTransaction(PoolMessage nMessageID)
|
||||
|
||||
if(nMessageID == MSG_SUCCESS) {
|
||||
LogPrintf("CompletedTransaction -- success\n");
|
||||
nCachedLastSuccessBlock = pCurrentBlockIndex->nHeight;
|
||||
nCachedLastSuccessBlock = nCachedBlockHeight;
|
||||
} else {
|
||||
LogPrintf("CompletedTransaction -- error\n");
|
||||
}
|
||||
@ -658,7 +658,8 @@ bool CPrivateSendClient::CheckAutomaticBackup()
|
||||
//
|
||||
bool CPrivateSendClient::DoAutomaticDenominating(CConnman& connman, bool fDryRun)
|
||||
{
|
||||
if(!fEnablePrivateSend || fMasterNode || !pCurrentBlockIndex) return false;
|
||||
if(fMasterNode) return false; // no client-side mixing on masternodes
|
||||
if(!fEnablePrivateSend) return false;
|
||||
if(!pwalletMain || pwalletMain->IsLocked(true)) return false;
|
||||
if(nState != POOL_STATE_IDLE) return false;
|
||||
|
||||
@ -686,7 +687,7 @@ bool CPrivateSendClient::DoAutomaticDenominating(CConnman& connman, bool fDryRun
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!fPrivateSendMultiSession && pCurrentBlockIndex->nHeight - nCachedLastSuccessBlock < nMinBlockSpacing) {
|
||||
if(!fPrivateSendMultiSession && nCachedBlockHeight - nCachedLastSuccessBlock < nMinBlockSpacing) {
|
||||
LogPrintf("CPrivateSendClient::DoAutomaticDenominating -- Last successful PrivateSend action was too recent\n");
|
||||
strAutoDenomResult = _("Last successful PrivateSend action was too recent.");
|
||||
return false;
|
||||
@ -1214,7 +1215,7 @@ bool CPrivateSendClient::MakeCollateralAmounts(const CompactTallyItem& tallyItem
|
||||
return false;
|
||||
}
|
||||
|
||||
nCachedLastSuccessBlock = pCurrentBlockIndex->nHeight;
|
||||
nCachedLastSuccessBlock = nCachedBlockHeight;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1362,7 +1363,7 @@ bool CPrivateSendClient::CreateDenominated(const CompactTallyItem& tallyItem, bo
|
||||
}
|
||||
|
||||
// use the same nCachedLastSuccessBlock as for DS mixing to prevent race
|
||||
nCachedLastSuccessBlock = pCurrentBlockIndex->nHeight;
|
||||
nCachedLastSuccessBlock = nCachedBlockHeight;
|
||||
LogPrintf("CPrivateSendClient::CreateDenominated -- txid=%s\n", wtx.GetHash().GetHex());
|
||||
|
||||
return true;
|
||||
@ -1387,8 +1388,8 @@ void CPrivateSendClient::SetState(PoolState nStateNew)
|
||||
|
||||
void CPrivateSendClient::UpdatedBlockTip(const CBlockIndex *pindex)
|
||||
{
|
||||
pCurrentBlockIndex = pindex;
|
||||
LogPrint("privatesend", "CPrivateSendClient::UpdatedBlockTip -- pCurrentBlockIndex->nHeight: %d\n", pCurrentBlockIndex->nHeight);
|
||||
nCachedBlockHeight = pindex->nHeight;
|
||||
LogPrint("privatesend", "CPrivateSendClient::UpdatedBlockTip -- nCachedBlockHeight: %d\n", nCachedBlockHeight);
|
||||
|
||||
if(!fLiteMode && masternodeSync.IsMasternodeListSynced()) {
|
||||
NewBlock();
|
||||
|
@ -43,7 +43,9 @@ private:
|
||||
|
||||
int nCachedLastSuccessBlock;
|
||||
int nMinBlockSpacing; //required blocks between mixes
|
||||
const CBlockIndex *pCurrentBlockIndex; // Keep track of current block index
|
||||
|
||||
// Keep track of current block height
|
||||
int nCachedBlockHeight;
|
||||
|
||||
int nEntriesCount;
|
||||
bool fLastEntryAccepted;
|
||||
|
@ -188,11 +188,13 @@ UniValue masternode(const UniValue& params, bool fHelp)
|
||||
int nCount;
|
||||
int nHeight;
|
||||
CMasternode* winner = NULL;
|
||||
CBlockIndex* pindex = NULL;
|
||||
{
|
||||
LOCK(cs_main);
|
||||
nHeight = chainActive.Height() + (strCommand == "current" ? 1 : 10);
|
||||
pindex = chainActive.Tip();
|
||||
}
|
||||
mnodeman.UpdateLastPaid();
|
||||
nHeight = pindex->nHeight + (strCommand == "current" ? 1 : 10);
|
||||
mnodeman.UpdateLastPaid(pindex);
|
||||
winner = mnodeman.GetNextMasternodeInQueueForPayment(nHeight, true, nCount);
|
||||
if(!winner) return "unknown";
|
||||
|
||||
@ -487,7 +489,12 @@ UniValue masternodelist(const UniValue& params, bool fHelp)
|
||||
}
|
||||
|
||||
if (strMode == "full" || strMode == "lastpaidtime" || strMode == "lastpaidblock") {
|
||||
mnodeman.UpdateLastPaid();
|
||||
CBlockIndex* pindex = NULL;
|
||||
{
|
||||
LOCK(cs_main);
|
||||
pindex = chainActive.Tip();
|
||||
}
|
||||
mnodeman.UpdateLastPaid(pindex);
|
||||
}
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
|
@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
LOCK(cs_main);
|
||||
fCheckpointsEnabled = false;
|
||||
|
||||
// force UpdatedBlockTip to initialize pCurrentBlockIndex
|
||||
// force UpdatedBlockTip to initialize nCachedBlockHeight
|
||||
mnpayments.UpdatedBlockTip(chainActive.Tip());
|
||||
|
||||
// Simple block creation, nothing special yet:
|
||||
|
Loading…
Reference in New Issue
Block a user