From 0534632d2ba9c4b4e56c8fe03bab6b737fdfaa37 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Mon, 12 Sep 2016 21:06:59 +0300 Subject: [PATCH] add cs_main lock to GetCollateralAge --- src/masternode.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/masternode.cpp b/src/masternode.cpp index c4b6699a0d..bc497ba995 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -205,18 +205,23 @@ void CMasternode::Check(bool forceCheck) int CMasternode::GetCollateralAge() { - if (chainActive.Height() < 0) return -1; + int nHeight; + { + TRY_LOCK(cs_main, lockMain); + if(!lockMain || !chainActive.Tip()) return -1; + nHeight = chainActive.Height(); + } if (nCacheCollateralBlock == 0) { int nInputAge = GetInputAge(vin); if(nInputAge > 0) { - nCacheCollateralBlock = chainActive.Height() - nInputAge; + nCacheCollateralBlock = nHeight - nInputAge; } else { return nInputAge; } } - return chainActive.Height() - nCacheCollateralBlock; + return nHeight - nCacheCollateralBlock; } void CMasternode::UpdateLastPaid(const CBlockIndex *pindex, int nMaxBlocksToScanBack)